Skip to content

Commit 42c3a07

Browse files
committed
Merge remote-tracking branch 'origin/2.6.x' into dubbo-2.6.11
2 parents 41b0a22 + 6ea05b5 commit 42c3a07

File tree

15 files changed

+405
-8
lines changed

15 files changed

+405
-8
lines changed

dependencies-bom/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
<xmemcached_version>1.3.6</xmemcached_version>
103103
<cxf_version>3.1.15</cxf_version>
104104
<thrift_version>0.8.0</thrift_version>
105-
<hessian_version>4.0.38</hessian_version>
105+
<hessian_version>4.0.51</hessian_version>
106106
<servlet_version>3.1.0</servlet_version>
107107
<jetty_version>6.1.26</jetty_version>
108108
<validation_version>1.1.0.Final</validation_version>
@@ -127,7 +127,7 @@
127127

128128
<jaxb_version>2.2.7</jaxb_version>
129129
<activation_version>1.2.0</activation_version>
130-
<hessian_lite_version>3.2.8</hessian_lite_version>
130+
<hessian_lite_version>3.2.11</hessian_lite_version>
131131
<alibaba_spring_context_support_version>1.0.2</alibaba_spring_context_support_version>
132132
<yaml_version>1.17</yaml_version>
133133
</properties>

dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.alibaba.dubbo.config.model.ApplicationModel;
3030
import com.alibaba.dubbo.config.model.ConsumerModel;
3131
import com.alibaba.dubbo.config.support.Parameter;
32+
import com.alibaba.dubbo.registry.support.ConsumerInvokerWrapper;
33+
import com.alibaba.dubbo.registry.support.ProviderConsumerRegTable;
3234
import com.alibaba.dubbo.rpc.Invoker;
3335
import com.alibaba.dubbo.rpc.Protocol;
3436
import com.alibaba.dubbo.rpc.ProxyFactory;
@@ -47,11 +49,13 @@
4749
import java.lang.reflect.Method;
4850
import java.util.ArrayList;
4951
import java.util.Arrays;
52+
import java.util.Collections;
5053
import java.util.HashMap;
5154
import java.util.HashSet;
5255
import java.util.List;
5356
import java.util.Map;
5457
import java.util.Properties;
58+
import java.util.Set;
5559

5660
import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidLocalHost;
5761

@@ -423,7 +427,14 @@ private T createProxy(Map<String, String> map) {
423427
if (c && !invoker.isAvailable()) {
424428
// make it possible for consumer to retry later if provider is temporarily unavailable
425429
initialized = false;
426-
throw new IllegalStateException("Failed to check the status of the service " + interfaceName + ". No provider available for the service " + (group == null ? "" : group + "/") + interfaceName + (version == null ? "" : ":" + version) + " from the url " + invoker.getUrl() + " to the consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion());
430+
final String serviceKey = (group == null ? "" : group + "/") + interfaceName + (version == null ? "" :
431+
":" + version);
432+
Set<ConsumerInvokerWrapper> consumerInvoker = ProviderConsumerRegTable.getConsumerInvoker(serviceKey);
433+
if (consumerInvoker != Collections.<ConsumerInvokerWrapper>emptySet()) {
434+
//since create proxy error , so we must be the first consumer. Simply clear ConcurrentHashSet
435+
consumerInvoker.clear();
436+
}
437+
throw new IllegalStateException("Failed to check the status of the service " + interfaceName + ". No provider available for the service " + serviceKey + " from the url " + invoker.getUrl() + " to the consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion());
427438
}
428439
if (logger.isInfoEnabled()) {
429440
logger.info("Refer dubbo service " + interfaceClass.getName() + " from url " + invoker.getUrl());

dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/support/MockInvoker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ public static Throwable getThrowable(String throwstr) {
147147
}
148148

149149
@SuppressWarnings("unchecked")
150-
private Invoker<T> getInvoker(String mockService) {
150+
private Invoker<T> getInvoker(String mock) {
151+
Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface());
152+
String mockService = ConfigUtils.isDefault(mock) ? serviceType.getName() + "Mock" : mock;
151153
Invoker<T> invoker = (Invoker<T>) mocks.get(mockService);
152154
if (invoker != null) {
153155
return invoker;
154156
}
155157

156-
Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface());
157-
T mockObject = (T) getMockObject(mockService, serviceType);
158+
T mockObject = (T) getMockObject(mock, serviceType);
158159
invoker = proxyFactory.getInvoker(mockObject, serviceType, url);
159160
if (mocks.size() < 10000) {
160161
mocks.put(mockService, invoker);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.support;
18+
19+
public interface DemoServiceA {
20+
String methodA();
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.support;
18+
19+
/**
20+
* default mock service for DemoServiceA
21+
*/
22+
public class DemoServiceAMock implements DemoServiceA{
23+
public static final String MOCK_VALUE = "mockA";
24+
@Override
25+
public String methodA() {
26+
return MOCK_VALUE;
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.support;
18+
19+
public interface DemoServiceB {
20+
String methodB();
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.support;
18+
19+
/**
20+
* default mock service for DemoServiceA
21+
*/
22+
public class DemoServiceBMock implements DemoServiceB {
23+
public static final String MOCK_VALUE = "mockB";
24+
25+
@Override
26+
public String methodB() {
27+
return MOCK_VALUE;
28+
}
29+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.support;
18+
19+
import com.alibaba.dubbo.common.URL;
20+
import com.alibaba.dubbo.rpc.RpcInvocation;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
import java.lang.reflect.Type;
25+
import java.util.ArrayList;
26+
import java.util.HashMap;
27+
28+
import static com.alibaba.dubbo.common.Constants.MOCK_KEY;
29+
30+
31+
public class MockInvokerTest {
32+
33+
@Test
34+
public void testParseMockValue() throws Exception {
35+
Assert.assertNull(MockInvoker.parseMockValue("null"));
36+
Assert.assertNull(MockInvoker.parseMockValue("empty"));
37+
38+
Assert.assertTrue((Boolean) MockInvoker.parseMockValue("true"));
39+
Assert.assertFalse((Boolean) MockInvoker.parseMockValue("false"));
40+
41+
Assert.assertEquals(123, MockInvoker.parseMockValue("123"));
42+
Assert.assertEquals("foo", MockInvoker.parseMockValue("foo"));
43+
Assert.assertEquals("foo", MockInvoker.parseMockValue("\"foo\""));
44+
Assert.assertEquals("foo", MockInvoker.parseMockValue("\'foo\'"));
45+
46+
Assert.assertEquals(
47+
new HashMap<Object, Object>(), MockInvoker.parseMockValue("{}"));
48+
Assert.assertEquals(
49+
new ArrayList<Object>(), MockInvoker.parseMockValue("[]"));
50+
Assert.assertEquals("foo",
51+
MockInvoker.parseMockValue("foo", new Type[]{String.class}));
52+
}
53+
54+
@Test
55+
public void testInvoke() {
56+
URL url = URL.valueOf("remote://1.2.3.4/" + String.class.getName());
57+
url = url.addParameter(MOCK_KEY, "return ");
58+
MockInvoker mockInvoker = new MockInvoker(url);
59+
60+
RpcInvocation invocation = new RpcInvocation();
61+
invocation.setMethodName("getSomething");
62+
Assert.assertEquals(new HashMap<Object, Object>(),
63+
mockInvoker.invoke(invocation).getAttachments());
64+
}
65+
66+
@Test
67+
public void testGetDefaultObject() {
68+
// test methodA in DemoServiceAMock
69+
final Class<DemoServiceA> demoServiceAClass = DemoServiceA.class;
70+
URL url = URL.valueOf("remote://1.2.3.4/" + demoServiceAClass.getName());
71+
url = url.addParameter(MOCK_KEY, "force:true");
72+
MockInvoker mockInvoker = new MockInvoker(url);
73+
74+
RpcInvocation invocation = new RpcInvocation();
75+
invocation.setMethodName("methodA");
76+
Assert.assertEquals(new HashMap<Object, Object>(),
77+
mockInvoker.invoke(invocation).getAttachments());
78+
79+
// test methodB in DemoServiceBMock
80+
final Class<DemoServiceB> demoServiceBClass = DemoServiceB.class;
81+
url = URL.valueOf("remote://1.2.3.4/" + demoServiceBClass.getName());
82+
url = url.addParameter(MOCK_KEY, "force:true");
83+
mockInvoker = new MockInvoker(url);
84+
invocation = new RpcInvocation();
85+
invocation.setMethodName("methodB");
86+
Assert.assertEquals(new HashMap<Object, Object>(),
87+
mockInvoker.invoke(invocation).getAttachments());
88+
}
89+
90+
@Test
91+
public void testNormalizeMock() {
92+
Assert.assertNull(MockInvoker.normalizeMock(null));
93+
94+
Assert.assertEquals("", MockInvoker.normalizeMock(""));
95+
Assert.assertEquals("", MockInvoker.normalizeMock("fail:"));
96+
Assert.assertEquals("", MockInvoker.normalizeMock("force:"));
97+
Assert.assertEquals("throw", MockInvoker.normalizeMock("throw"));
98+
Assert.assertEquals("default", MockInvoker.normalizeMock("fail"));
99+
Assert.assertEquals("default", MockInvoker.normalizeMock("force"));
100+
Assert.assertEquals("default", MockInvoker.normalizeMock("true"));
101+
Assert.assertEquals("default",
102+
MockInvoker.normalizeMock("default"));
103+
Assert.assertEquals("return null",
104+
MockInvoker.normalizeMock("return"));
105+
Assert.assertEquals("return null",
106+
MockInvoker.normalizeMock("return null"));
107+
}
108+
}

dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.alibaba.dubbo.rpc.RpcContext;
2525
import com.alibaba.dubbo.rpc.RpcException;
2626
import com.alibaba.dubbo.rpc.protocol.AbstractProxyProtocol;
27-
27+
import com.alibaba.dubbo.rpc.protocol.hessian.serialization.Hessian2FactoryUtil;
2828
import com.alibaba.dubbo.rpc.service.GenericService;
2929
import com.alibaba.dubbo.rpc.support.ProtocolUtils;
3030
import com.caucho.hessian.HessianException;
@@ -122,6 +122,7 @@ protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
122122
int timeout = url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
123123
hessianProxyFactory.setConnectTimeout(timeout);
124124
hessianProxyFactory.setReadTimeout(timeout);
125+
hessianProxyFactory.setSerializerFactory(Hessian2FactoryUtil.getInstance().getSerializerFactory());
125126
return (T) hessianProxyFactory.create(serviceType, url.setProtocol("http").toJavaURL(), Thread.currentThread().getContextClassLoader());
126127
}
127128

@@ -181,7 +182,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response)
181182
}
182183

183184
try {
184-
skeleton.invoke(request.getInputStream(), response.getOutputStream());
185+
skeleton.invoke(request.getInputStream(), response.getOutputStream(), Hessian2FactoryUtil.getInstance().getSerializerFactory());
185186
} catch (Throwable e) {
186187
throw new ServletException(e);
187188
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.protocol.hessian.serialization;
18+
19+
import com.caucho.hessian.io.SerializerFactory;
20+
21+
public abstract class AbstractHessian2FactoryInitializer implements Hessian2FactoryInitializer {
22+
private static SerializerFactory SERIALIZER_FACTORY;
23+
24+
@Override
25+
public SerializerFactory getSerializerFactory() {
26+
if (SERIALIZER_FACTORY != null) {
27+
return SERIALIZER_FACTORY;
28+
}
29+
synchronized (this) {
30+
SERIALIZER_FACTORY = createSerializerFactory();
31+
}
32+
return SERIALIZER_FACTORY;
33+
}
34+
35+
protected abstract SerializerFactory createSerializerFactory();
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.rpc.protocol.hessian.serialization;
18+
19+
import com.caucho.hessian.io.SerializerFactory;
20+
21+
public class DefaultHessian2FactoryInitializer extends AbstractHessian2FactoryInitializer {
22+
@Override
23+
protected SerializerFactory createSerializerFactory() {
24+
return new SerializerFactory();
25+
}
26+
}

0 commit comments

Comments
 (0)