Skip to content

Commit 259c072

Browse files
kimmkinglovepoem
authored andcommitted
update CXF to latest version and add test case for webservice protocol (#1564)
* update cxf version and add test cases * support jdk7 * add profile for dependency in jdk9 * modify profile location * fix jaxb version * add dependency for jdk9 * extract dependencies to dependencies bom project
1 parent 2262450 commit 259c072

File tree

7 files changed

+291
-2
lines changed

7 files changed

+291
-2
lines changed

dependencies-bom/pom.xml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<curator_version>2.12.0</curator_version>
8585
<jedis_version>2.9.0</jedis_version>
8686
<xmemcached_version>1.3.6</xmemcached_version>
87-
<cxf_version>3.0.14</cxf_version>
87+
<cxf_version>3.1.15</cxf_version>
8888
<thrift_version>0.8.0</thrift_version>
8989
<hessian_version>4.0.38</hessian_version>
9090
<servlet_version>3.1.0</servlet_version>
@@ -107,6 +107,9 @@
107107
<logback_version>1.2.2</logback_version>
108108
<commons_lang3_version>3.4</commons_lang3_version>
109109
<embedded_redis_version>0.6</embedded_redis_version>
110+
111+
<jaxb_version>2.2.7</jaxb_version>
112+
<activation_version>1.2.0</activation_version>
110113
</properties>
111114

112115
<dependencyManagement>
@@ -321,6 +324,34 @@
321324
<artifactId>commons-lang3</artifactId>
322325
<version>${commons_lang3_version}</version>
323326
</dependency>
327+
328+
<!-- for dubbo-rpc-webservice -->
329+
<dependency>
330+
<groupId>javax.xml.bind</groupId>
331+
<artifactId>jaxb-api</artifactId>
332+
<version>${jaxb_version}</version>
333+
</dependency>
334+
<dependency>
335+
<groupId>com.sun.xml.bind</groupId>
336+
<artifactId>jaxb-impl</artifactId>
337+
<version>${jaxb_version}</version>
338+
</dependency>
339+
<dependency>
340+
<groupId>com.sun.xml.bind</groupId>
341+
<artifactId>jaxb-core</artifactId>
342+
<version>${jaxb_version}</version>
343+
</dependency>
344+
<dependency>
345+
<groupId>javax.activation</groupId>
346+
<artifactId>javax.activation-api</artifactId>
347+
<version>${activation_version}</version>
348+
</dependency>
349+
<dependency>
350+
<groupId>com.sun.activation</groupId>
351+
<artifactId>javax.activation</artifactId>
352+
<version>${activation_version}</version>
353+
</dependency>
354+
324355
<!-- Test lib -->
325356
<dependency>
326357
<groupId>org.apache.curator</groupId>

dubbo-rpc/dubbo-rpc-webservice/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
<artifactId>dubbo-remoting-http</artifactId>
4141
<version>${project.parent.version}</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>javax.xml.bind</groupId>
45+
<artifactId>jaxb-api</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.sun.xml.bind</groupId>
49+
<artifactId>jaxb-impl</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.sun.xml.bind</groupId>
53+
<artifactId>jaxb-core</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>javax.activation</groupId>
57+
<artifactId>javax.activation-api</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.sun.activation</groupId>
61+
<artifactId>javax.activation</artifactId>
62+
</dependency>
4363
<dependency>
4464
<groupId>org.apache.cxf</groupId>
4565
<artifactId>cxf-rt-frontend-simple</artifactId>
@@ -53,4 +73,5 @@
5373
<artifactId>spring-context</artifactId>
5474
</dependency>
5575
</dependencies>
76+
5677
</project>

dubbo-rpc/dubbo-rpc-webservice/src/main/java/com/alibaba/dubbo/rpc/protocol/webservice/WebServiceProtocol.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcExcept
9595
return new Runnable() {
9696
@Override
9797
public void run() {
98-
serverFactoryBean.destroy();
98+
if(serverFactoryBean.getServer()!= null) {
99+
serverFactoryBean.getServer().destroy();
100+
}
101+
if(serverFactoryBean.getBus()!=null) {
102+
serverFactoryBean.getBus().shutdown(true);
103+
}
99104
}
100105
};
101106
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.webservice;
18+
19+
/**
20+
* <code>TestService</code>
21+
*/
22+
23+
public interface DemoService {
24+
void sayHello(String name);
25+
26+
String echo(String text);
27+
28+
long timestamp();
29+
30+
void throwTimeout();
31+
32+
String getThreadName();
33+
34+
int getSize(String[] strs);
35+
36+
int getSize(Object[] os);
37+
38+
Object invoke(String service, String method) throws Exception;
39+
40+
int stringLength(String str);
41+
42+
User create(int age, String name);
43+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.webservice;
18+
19+
import com.alibaba.dubbo.rpc.RpcContext;
20+
21+
/**
22+
* DemoServiceImpl
23+
*/
24+
25+
public class DemoServiceImpl implements DemoService {
26+
public DemoServiceImpl() {
27+
super();
28+
}
29+
30+
public void sayHello(String name) {
31+
System.out.println("hello " + name);
32+
}
33+
34+
public String echo(String text) {
35+
return text;
36+
}
37+
38+
public long timestamp() {
39+
return System.currentTimeMillis();
40+
}
41+
42+
public String getThreadName() {
43+
return Thread.currentThread().getName();
44+
}
45+
46+
public int getSize(String[] strs) {
47+
if (strs == null)
48+
return -1;
49+
return strs.length;
50+
}
51+
52+
public int getSize(Object[] os) {
53+
if (os == null)
54+
return -1;
55+
return os.length;
56+
}
57+
58+
public Object invoke(String service, String method) throws Exception {
59+
System.out.println("RpcContext.getContext().getRemoteHost()=" + RpcContext.getContext().getRemoteHost());
60+
return service + ":" + method;
61+
}
62+
63+
public User create(int age, String name){
64+
User user = new User();
65+
user.setAge(age);
66+
user.setName(name);
67+
return user;
68+
}
69+
70+
public int stringLength(String str) {
71+
return str.length();
72+
}
73+
74+
public void throwTimeout() {
75+
try {
76+
Thread.sleep(6000);
77+
} catch (InterruptedException e) {
78+
}
79+
}
80+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.webservice;
18+
19+
public class User {
20+
private int age;
21+
private String name;
22+
23+
public int getAge() {
24+
return age;
25+
}
26+
27+
public void setAge(int age) {
28+
this.age = age;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.webservice;
18+
19+
import com.alibaba.dubbo.common.URL;
20+
import com.alibaba.dubbo.common.extension.ExtensionLoader;
21+
import com.alibaba.dubbo.rpc.Protocol;
22+
import com.alibaba.dubbo.rpc.ProxyFactory;
23+
import com.alibaba.dubbo.rpc.service.EchoService;
24+
import org.junit.Test;
25+
26+
import static junit.framework.Assert.assertEquals;
27+
28+
/**
29+
* @author kimmking
30+
*/
31+
32+
public class WebserviceProtocolTest {
33+
private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
34+
private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
35+
36+
@Test
37+
public void testDemoProtocol() throws Exception {
38+
DemoService service = new DemoServiceImpl();
39+
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("webservice://127.0.0.1:9019/" + DemoService.class.getName() + "?codec=exchange")));
40+
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("webservice://127.0.0.1:9019/" + DemoService.class.getName() + "?codec=exchange")));
41+
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
42+
}
43+
44+
@Test
45+
public void testWebserviceProtocol() throws Exception {
46+
DemoService service = new DemoServiceImpl();
47+
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("webservice://127.0.0.1:9019/" + DemoService.class.getName())));
48+
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("webservice://127.0.0.1:9019/" + DemoService.class.getName())));
49+
assertEquals(service.create(1,"kk").getName(), "kk");
50+
assertEquals(service.getSize(null), -1);
51+
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
52+
Object object = service.invoke("webservice://127.0.0.1:9019/" + DemoService.class.getName() + "", "invoke");
53+
System.out.println(object);
54+
assertEquals("webservice://127.0.0.1:9019/com.alibaba.dubbo.rpc.protocol.webservice.DemoService:invoke", object);
55+
56+
StringBuffer buf = new StringBuffer();
57+
for (int i = 0; i < 1024 * 32 + 32; i++)
58+
buf.append('A');
59+
assertEquals(32800,service.stringLength(buf.toString()));
60+
61+
// a method start with $ is illegal in soap
62+
// // cast to EchoService
63+
// EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("webservice://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
64+
// assertEquals(echo.echo(buf.toString()), buf.toString());
65+
// assertEquals(echo.$echo("test"), "test");
66+
// assertEquals(echo.$echo("abcdefg"), "abcdefg");
67+
// assertEquals(echo.$echo(1234), 1234);
68+
}
69+
70+
71+
}

0 commit comments

Comments
 (0)