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

remove serviceclassHolder and also fix the issue #2637 #2607

Merged
merged 5 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -635,6 +635,8 @@ public class Constants {

public static final String MULTICAST = "multicast";

public static final String SERVICE_IMPL_CLASS = "service.classimpl";

/*
* private Constants(){ }
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -217,7 +218,7 @@ public static Properties loadProperties(String fileName, boolean allowMultiFile)
*/
public static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional) {
Properties properties = new Properties();
if (fileName.startsWith("/")) {
if (checkFileNameExist(fileName)) {
try {
FileInputStream input = new FileInputStream(fileName);
try {
Expand Down Expand Up @@ -291,6 +292,16 @@ public static Properties loadProperties(String fileName, boolean allowMultiFile,
return properties;
}

/**
* check if the fileName can be found in filesystem
* @param fileName
* @return
*/
private static boolean checkFileNameExist(String fileName) {
File file = new File(fileName);
return file != null && file.exists() ? true : false;
}

public static int getPid() {
if (PID < 0) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.ServiceClassHolder;
import com.alibaba.dubbo.rpc.StaticContext;
import com.alibaba.dubbo.rpc.cluster.ConfiguratorFactory;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.rpc.support.ProtocolUtils;
Expand Down Expand Up @@ -532,7 +532,7 @@ private void exportLocal(URL url) {
.setProtocol(Constants.LOCAL_PROTOCOL)
.setHost(LOCALHOST)
.setPort(0);
ServiceClassHolder.getInstance().pushServiceClass(getServiceClass(ref));
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(url.getServiceKey(), getServiceClass(ref));
Exporter<?> exporter = protocol.export(
proxyFactory.getInvoker(ref, (Class) interfaceClass, local));
exporters.add(exporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void checkApplication1() throws Exception {
interfaceConfig.checkApplication();
ApplicationConfig appConfig = interfaceConfig.getApplication();
TestCase.assertEquals("demo", appConfig.getName());
TestCase.assertEquals("100", System.getProperty(Constants.SHUTDOWN_WAIT_KEY));
TestCase.assertEquals("100", ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY));

System.clearProperty(Constants.SHUTDOWN_WAIT_KEY);
ConfigUtils.setProperties(null);
Expand Down Expand Up @@ -386,6 +386,7 @@ private void writeDubboProperties(String key, String value) {
Properties properties = new Properties();
properties.put(key, value);
properties.store(os, "");
os.flush();
os.close();
} catch (IOException e) {
if (os != null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import com.alibaba.dubbo.remoting.http.servlet.BootstrapListener;
import com.alibaba.dubbo.remoting.http.servlet.ServletManager;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.ServiceClassHolder;
import com.alibaba.dubbo.rpc.StaticContext;
import com.alibaba.dubbo.rpc.protocol.AbstractProxyProtocol;

import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -83,7 +82,7 @@ public int getDefaultPort() {
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
String addr = getAddr(url);
Class implClass = ServiceClassHolder.getInstance().popServiceClass();
Class implClass = (Class) StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).get(url.getServiceKey());
RestServer server = servers.get(addr);
if (server == null) {
server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.ServiceClassHolder;
import com.alibaba.dubbo.rpc.*;
Jeff-Lv marked this conversation as resolved.
Show resolved Hide resolved
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Test;
Expand All @@ -48,7 +41,7 @@ public void tearDown() {

@Test
public void testExport() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);


RpcContext.getContext().setAttachment("timeout", "200");
Expand All @@ -64,7 +57,7 @@ public void testExport() {

@Test
public void testNettyServer() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);

URL nettyUrl = exportUrl.addParameter(Constants.SERVER_KEY, "netty");
Exporter<IDemoService> exporter = protocol.export(proxy.getInvoker(new DemoService(), IDemoService.class, nettyUrl));
Expand All @@ -79,7 +72,7 @@ public void testNettyServer() {

@Test(expected = RpcException.class)
public void testServletWithoutWebConfig() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);

URL servletUrl = exportUrl.addParameter(Constants.SERVER_KEY, "servlet");

Expand All @@ -88,7 +81,7 @@ public void testServletWithoutWebConfig() {

@Test(expected = RpcException.class)
public void testErrorHandler() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);

URL nettyUrl = exportUrl.addParameter(Constants.SERVER_KEY, "netty");
Exporter<IDemoService> exporter = protocol.export(proxy.getInvoker(new DemoService(), IDemoService.class, nettyUrl));
Expand All @@ -100,7 +93,7 @@ public void testErrorHandler() {

@Test
public void testInvoke() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);


Exporter<IDemoService> exporter = protocol.export(proxy.getInvoker(new DemoService(), IDemoService.class, exportUrl));
Expand All @@ -113,7 +106,7 @@ public void testInvoke() {

@Test
public void testFilter() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);

URL nettyUrl = exportUrl.addParameter(Constants.SERVER_KEY, "netty")
.addParameter(Constants.EXTENSION_KEY, "com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter");
Expand All @@ -130,7 +123,7 @@ public void testFilter() {

@Test(expected = RuntimeException.class)
public void testRegFail() {
ServiceClassHolder.getInstance().pushServiceClass(DemoService.class);
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(exportUrl.getServiceKey(), DemoService.class);

URL nettyUrl = exportUrl.addParameter(Constants.EXTENSION_KEY, "com.not.existing.Filter");
protocol.export(proxy.getInvoker(new DemoService(), IDemoService.class, nettyUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alibaba.dubbo.rpc.protol.rest;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.*;
Jeff-Lv marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -32,10 +33,11 @@ public class RestProtocolTest {

@Test
public void testRestProtocol() {
ServiceClassHolder.getInstance().pushServiceClass(RestServiceImpl.class);
URL url = URL.valueOf("rest://127.0.0.1:5342/rest/say1?version=1.0.0");
StaticContext.getContext(Constants.SERVICE_IMPL_CLASS).put(url.getServiceKey(), RestServiceImpl.class);
RestServiceImpl server = new RestServiceImpl();
Assert.assertFalse(server.isCalled());
URL url = URL.valueOf("rest://127.0.0.1:5342/rest/say1?version=1.0.0");

Exporter<RestService> exporter = protocol.export(proxyFactory.getInvoker(server, RestService.class, url));
Invoker<RestService> invoker = protocol.refer(RestService.class, url);
RestService client = proxyFactory.getProxy(invoker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<dubbo:application name="rest-consumer" owner="programmer" organization="dubbo"/>

Expand Down