标签:style blog class code c java
前言:自上周五开始,因为公司刚好来人培训,因为我还在出差,熬了一个周末早9-晚9两天搞完了三天的课程,觉得还不错。。但是很多东西还是要自己摸索的。到今天来一个小结吧。
1.webService 说白了,就是为企业执行SOA的一个工具而已。
2.消息中间件,作为SOA架构的一条esb,即企业服务总线。

简介:这套东西要用到2个webservice(Webservice_Server&webService_Client),一个作为 hwHosting的webservice,一个作为jsClient的。在中间件上的webservice是通过webService_Server来重新部署一个新的地址,也就是说,我在调用java上的webService上时,数据会传到中间件上去。然后到中间件上的时候按照xslt---》javascript的方向来实现。
1.(webService_Server_for_hwHosting),主要是作为hwHosting的webservice,向中间件提供的部分。
|
1
2
3
4
5
6
7 |
@WebServicepublic
interface HelloWorld { @WebMethod public
String sayHello(@WebParam(name="name")String name);} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
public
class HelloWorldImpl implements
HelloWorld { public
String sayHello(String name) { return
"somethind"; } public
static void
main(String[] args) { HelloWorldImpl implementor = new
HelloWorldImpl(); JaxWsServerFactoryBean svrFactory = new
JaxWsServerFactoryBean(); svrFactory.setServiceClass(HelloWorld.class); svrFactory.setServiceBean(implementor); svrFactory.getInInterceptors().add(new
LoggingInInterceptor()); svrFactory.getOutInterceptors().add(new
LoggingOutInterceptor()); svrFactory.create(); }} |
2.webService_Server_for_hwHosting,主要用来调用,测试服务
|
1
2
3
4
5
6
7
8
9
10
11
12
13 |
public
class HelloClient { public
static void
main(String[] args) { JaxWsProxyFactoryBean factory = new
JaxWsProxyFactoryBean(); //factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new
LoggingOutInterceptor()); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://127.0.0.1:1506/services/HelloWorldService.HelloWorldServiceHttpSoap11Endpoint");//这个地址是通过中间件的webService的wsdl文件中的endPoint中找到的 HelloWorld client = (HelloWorld) factory.create(); <span style="color: rgb(255, 0, 0);">String reply = client.sayHello("2");</span> System.out.println("Server said: "
+ reply); System.exit(0); }} |
3.webService_Client_for_jsClient
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
@WebServicepublic
interface IMultiMethod { @WebMethod public
String testJs1(@WebParam(name="name")String name); @WebMethod public
String testJs2(@WebParam(name="name")String name); @WebMethod public
String testJs3(@WebParam(name="name")String name); @WebMethod public
String testJs4(@WebParam(name="name")String name);} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 |
public
class MultiMethodImpl implements
IMultiMethod { public
String testJs1(String name) { return
"testJs1"; } public
String testJs2(String name) { return
"testJs2"; } public
String testJs3(String name) { return
"testJs3"; } public
String testJs4(String name) { return
"testJs4"; } public
static void
main(String[] args) { MultiMethodImpl implementor = new
MultiMethodImpl(); JaxWsServerFactoryBean svrFactory = new
JaxWsServerFactoryBean(); svrFactory.setServiceClass(IMultiMethod.class); svrFactory.setServiceBean(implementor); svrFactory.getInInterceptors().add(new
LoggingInInterceptor()); svrFactory.getOutInterceptors().add(new
LoggingOutInterceptor()); svrFactory.create(); } |
4.下面是一些测试数据。
4.1传入的数据:一定要注意这里面有命名空间,再我处理的时候有很多的不便,所以我加入了一个xslt来去除 这个命名空间。
|
1
2
3
4
5
6
7
8
9 |
4.2 xslt文件:一定要注意,在传过来的xml文件中有命名空间,所以我们的xslt文件也要有命名空间,如高亮区
|
1
2
3
4
5
6
7
8
9
10
11
12 |
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"<xsl:template match="/ns2:sayHello"><span style="color: rgb(255, 0, 0);">//match会选择在/ns:sayHello命名空间下的部分</span><sayHello><name><xsl:value-of select="name"
/></name></sayHello></xsl:template></xsl:stylesheet> |
4.3 结果:如图所示,已经将原有的ns2去掉了。
|
1
2
3
4
5 |
<sayHello><name>2</name></sayHello> |
5.下面继续看javascript的写法,主要是看我通过jsHosting传过来的数字,来判断,去调用jsClient的哪个具体的 方法
|
1
2
3
4
5
6
7
8
9 |
var
next = output.append(input[0]);var
methodName=next.getField(‘/sayHello/name‘)next.setProperty(‘methodName‘,methodName)switch(methodName){ case
"1":next.setProperty("rhapsody:consumerOperation",‘testJs1‘);break; case
"2":next.setProperty("rhapsody:consumerOperation",‘testJs2‘);break; case
"3":next.setProperty("rhapsody:consumerOperation",‘testJs3‘);break; case
"4":next.setProperty("rhapsody:consumerOperation",‘testJs4‘);break;} |
6.最终返回值:根据我传入的2,返回为testJs2,这样完成了所有的测试。
|
1
2
3
4
5 |
<ns2:testJs2Response><return>testJs2</return></ns2:testJs2Response> |
Stop compliant,just code,just do something even if it maybe easy a lot....
很多东西都是在不段的积累中,幸福是来自于追求的路上,而不是获得以后。
webService_cxf_消息中间件_5.16,布布扣,bubuko.com
标签:style blog class code c java
原文地址:http://www.cnblogs.com/weizizhe/p/3731723.html