Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve local exposure, the server opens the token, and the client call fails #7334

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.protocol.injvm;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Constants;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Result;
Expand Down Expand Up @@ -60,6 +61,12 @@ public Result doInvoke(Invocation invocation) throws Throwable {
throw new RpcException("Service [" + key + "] not found.");
}
RpcContext.getContext().setRemoteAddress(LOCALHOST_VALUE, 0);
// Solve local exposure, the server opens the token, and the client call fails.
URL serverURL = exporter.getInvoker().getUrl();
boolean serverHasToken = serverURL.hasParameter(Constants.TOKEN_KEY);
if (serverHasToken) {
invocation.setAttachment(Constants.TOKEN_KEY, serverURL.getParameter(Constants.TOKEN_KEY));
}
return exporter.getInvoker().invoke(invocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public void testLocalProtocol() throws Exception {

}

@Test
public void testLocalProtocolWithToken() throws Exception {
DemoService service = new DemoServiceImpl();
Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService?token=abc").addParameter(INTERFACE_KEY, DemoService.class.getName()));
assertTrue(invoker.isAvailable());
Exporter<?> exporter = protocol.export(invoker);
AlbumenJ marked this conversation as resolved.
Show resolved Hide resolved
exporters.add(exporter);
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName())));
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
}

@Test
public void testIsInjvmRefer() throws Exception {
DemoService service = new DemoServiceImpl();
Expand Down