|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| package jtr.test.jee.client; |
|
11 |
| |
|
12 |
| import java.util.Map; |
|
13 |
| import java.util.Set; |
|
14 |
| import java.util.concurrent.ExecutionException; |
|
15 |
| import java.util.concurrent.Future; |
|
16 |
| |
|
17 |
| import javax.xml.bind.JAXBElement; |
|
18 |
| |
|
19 |
| import jtr.runners.AbstractWsRunner; |
|
20 |
| import jtr.test.IOutcome; |
|
21 |
| import jtr.test.jee.ping.client.IncrementMultResult; |
|
22 |
| import jtr.test.jee.ping.client.IncrementMultResultResponse; |
|
23 |
| import jtr.test.jee.ping.client.ObjectFactory; |
|
24 |
| import jtr.test.jee.ping.client.Ping; |
|
25 |
| import jtr.test.jee.ping.client.PingResponse; |
|
26 |
| import jtr.ws.IWsResponse; |
|
27 |
| import jtr.ws.IWsResponseListener; |
|
28 |
| import jtr.ws.WsProviderException; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class WsPingTest extends AbstractWsRunner{ |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
20
| public WsPingTest() {
|
|
40 |
| } |
|
41 |
| |
|
42 |
6000
| public void test() throws Throwable {
|
|
43 |
6000
| userMsg = "Using WS-binding "+getBinding().getUniqueName();
|
|
44 |
6000
| if(getBinding().getUniqueName().contains("pingWS")) {
|
|
45 |
2000
| testSynchInvocation();
|
|
46 |
| } else { |
|
47 |
4000
| if(getBinding().getUniqueName().contains("oneWayWS")) {
|
|
48 |
2000
| testOneWayInvocation();
|
|
49 |
2000
| } else if(getBinding().getUniqueName().contains("inoutWS")) {
|
|
50 |
2000
| testIncrementMultResult();
|
|
51 |
| } |
|
52 |
| } |
|
53 |
| } |
|
54 |
| |
|
55 |
2000
| private void testSynchInvocation() throws WsProviderException, InterruptedException, ExecutionException {
|
|
56 |
| |
|
57 |
| |
|
58 |
2000
| ObjectFactory of = new ObjectFactory();
|
|
59 |
2000
| Ping ping = new Ping();
|
|
60 |
2000
| ping.setPinger(getName());
|
|
61 |
2000
| JAXBElement<Ping> pingReq = of.createPing(ping);
|
|
62 |
| |
|
63 |
| |
|
64 |
2000
| JAXBElement<PingResponse> pong = (JAXBElement<PingResponse>) invoke(getBinding(), pingReq);
|
|
65 |
1999
| System.out.println("WS Received PONG: "+pong.getValue().getReturn());
|
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
2000
| invokeOneWay(getBinding(), pingReq);
|
|
71 |
| |
|
72 |
| |
|
73 |
2000
| Future res = invokeAsync(getBinding(), pingReq, new IWsResponseListener() {
|
|
74 |
1999
| public void handleResponse(IWsResponse rsp) {
|
|
75 |
1999
| try {
|
|
76 |
1999
| if(rsp!=null) {
|
|
77 |
2000
| System.out.println("\nWS Received asynch-listened for PONG: "+((JAXBElement<PingResponse>)rsp.get()).getValue().getReturn());
|
|
78 |
2000
| responseInspection(rsp);
|
|
79 |
| } |
|
80 |
| } catch (ExecutionException ex) { |
|
81 |
0
| ex.printStackTrace();
|
|
82 |
| } catch (InterruptedException ex) { |
|
83 |
0
| ex.printStackTrace();
|
|
84 |
| } |
|
85 |
| } |
|
86 |
| }); |
|
87 |
2000
| System.out.print("WS Waiting for a response ");
|
|
88 |
2000
| while(!res.isDone()) {
|
|
89 |
4834633
| System.out.print(".");
|
|
90 |
| } |
|
91 |
2000
| System.out.println("\nWS Received!");
|
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
2000
| IWsResponse rsp = invokeAsync(getBinding(), pingReq);
|
|
97 |
2000
| System.out.print("WS Waiting for a response ");
|
|
98 |
2000
| while(!rsp.isDone()) {
|
|
99 |
1611653
| System.out.print(".");
|
|
100 |
| } |
|
101 |
2000
| System.out.println("\nWS Received asynch PONG: "+((JAXBElement<PingResponse>)rsp.get()).getValue().getReturn());
|
|
102 |
2000
| responseInspection(rsp);
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
2000
| private void testOneWayInvocation() throws WsProviderException {
|
|
107 |
2000
| userMsg = userMsg + "\nThis invocation should fail.";
|
|
108 |
2000
| invokeOneWay(getBinding(), new String[] {"foo","bar"});
|
|
109 |
| } |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
2000
| private void testIncrementMultResult() throws WsProviderException {
|
|
116 |
2000
| ObjectFactory of = new ObjectFactory();
|
|
117 |
2000
| IncrementMultResult par = of.createIncrementMultResult();
|
|
118 |
2000
| par.setArg0(12.333);
|
|
119 |
2000
| par.setArg1(2.123);
|
|
120 |
2000
| par.setArg2(12.333*2.123);
|
|
121 |
2000
| JAXBElement<IncrementMultResult> parReq = of.createIncrementMultResult(par);
|
|
122 |
| |
|
123 |
2000
| JAXBElement<IncrementMultResultResponse> rsp = (JAXBElement) invoke(getBinding(), parReq);
|
|
124 |
2000
| System.out.println("WS Received: "+rsp.getValue());
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
4000
| private void responseInspection(IWsResponse rsp) {
|
|
133 |
4000
| System.out.println("WS Exploring the context...");
|
|
134 |
4000
| Map<String,Object> ctx = rsp.getContext();
|
|
135 |
4000
| Set<Map.Entry<String,Object>> entrySet = ctx.entrySet();
|
|
136 |
3999
| System.out.println();
|
|
137 |
4000
| for(Map.Entry<String,Object> entry : entrySet) {
|
|
138 |
52000
| System.out.println("WS KEY: "+entry.getKey()+", VALUE: "+entry.getValue());
|
|
139 |
| } |
|
140 |
| } |
|
141 |
| |
|
142 |
2000
| public void receiveFailureNotification(Throwable throwable, String string) {
|
|
143 |
| } |
|
144 |
| |
|
145 |
20
| public void cleanupResources() {
|
|
146 |
| } |
|
147 |
| |
|
148 |
6000
| public void enrichOutcome(IOutcome outcome) {
|
|
149 |
6000
| outcome.setUserObject(userMsg);
|
|
150 |
| } |
|
151 |
| |
|
152 |
| private String userMsg; |
|
153 |
| } |