1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.cxf; |
12 | |
|
13 | |
import org.mule.DefaultMuleMessage; |
14 | |
import org.mule.api.MuleMessage; |
15 | |
import org.mule.api.config.MuleProperties; |
16 | |
import org.mule.api.endpoint.InboundEndpoint; |
17 | |
import org.mule.transport.AbstractMessageRequester; |
18 | |
|
19 | |
import java.util.Iterator; |
20 | |
import java.util.Properties; |
21 | |
|
22 | |
import org.apache.cxf.endpoint.ClientImpl; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class CxfMessageRequester extends AbstractMessageRequester |
29 | |
{ |
30 | |
|
31 | |
protected CxfConnector connector; |
32 | |
private ClientWrapper wrapper; |
33 | |
|
34 | |
public CxfMessageRequester(InboundEndpoint endpoint) |
35 | |
{ |
36 | 18 | super(endpoint); |
37 | 18 | this.connector = (CxfConnector)endpoint.getConnector(); |
38 | 18 | } |
39 | |
|
40 | |
protected void doConnect() throws Exception |
41 | |
{ |
42 | 18 | wrapper = new ClientWrapper(); |
43 | 18 | wrapper.setBus(connector.getCxfBus()); |
44 | 18 | wrapper.setEndpoint(endpoint); |
45 | 18 | wrapper.initialize(); |
46 | 18 | } |
47 | |
|
48 | |
protected void doDisconnect() throws Exception |
49 | |
{ |
50 | 18 | } |
51 | |
|
52 | |
protected void doDispose() |
53 | |
{ |
54 | |
|
55 | 18 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
protected MuleMessage doRequest(long timeout) throws Exception |
70 | |
{ |
71 | 22 | ((ClientImpl)wrapper.getClient()).setSynchronousTimeout((int)timeout); |
72 | |
|
73 | 22 | String method = (String)endpoint.getProperty(MuleProperties.MULE_METHOD_PROPERTY); |
74 | |
|
75 | 22 | if (method == null) |
76 | |
{ |
77 | 0 | method = (String)endpoint.getProperty(CxfConstants.OPERATION); |
78 | |
} |
79 | |
|
80 | 22 | Properties params = endpoint.getEndpointURI().getUserParams(); |
81 | 22 | Object args[] = new Object[params.size()]; |
82 | 22 | int i = 0; |
83 | 60 | for (Iterator<Object> iterator = params.values().iterator(); iterator.hasNext(); i++) |
84 | |
{ |
85 | 38 | args[i] = iterator.next().toString(); |
86 | |
} |
87 | |
|
88 | 22 | Object[] response = wrapper.getClient().invoke(method, args); |
89 | |
|
90 | 22 | if (response != null && response.length == 1) |
91 | |
{ |
92 | 22 | return new DefaultMuleMessage(response[0]); |
93 | |
} |
94 | |
else |
95 | |
{ |
96 | 0 | return new DefaultMuleMessage(response); |
97 | |
} |
98 | |
} |
99 | |
|
100 | |
|
101 | |
} |