1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.soap.axis; |
12 | |
|
13 | |
import org.mule.api.MuleMessage; |
14 | |
import org.mule.api.config.MuleProperties; |
15 | |
import org.mule.api.endpoint.EndpointURI; |
16 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
17 | |
import org.mule.api.endpoint.InboundEndpoint; |
18 | |
import org.mule.endpoint.MuleEndpointURI; |
19 | |
import org.mule.transport.AbstractMessageRequester; |
20 | |
|
21 | |
import java.util.Iterator; |
22 | |
import java.util.Properties; |
23 | |
|
24 | |
import javax.xml.soap.SOAPEnvelope; |
25 | |
|
26 | |
import org.apache.axis.AxisProperties; |
27 | |
import org.apache.axis.EngineConfiguration; |
28 | |
import org.apache.axis.Message; |
29 | |
import org.apache.axis.client.Call; |
30 | |
import org.apache.axis.client.Service; |
31 | |
import org.apache.axis.configuration.FileProvider; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class AxisMessageRequester extends AbstractMessageRequester |
38 | |
{ |
39 | |
|
40 | |
protected EngineConfiguration clientConfig; |
41 | |
protected AxisConnector connector; |
42 | |
protected Service service; |
43 | |
|
44 | |
public AxisMessageRequester(InboundEndpoint endpoint) |
45 | |
{ |
46 | 40 | super(endpoint); |
47 | 40 | this.connector = (AxisConnector)endpoint.getConnector(); |
48 | 40 | AxisProperties.setProperty("axis.doAutoTypes", Boolean.toString(connector.isDoAutoTypes())); |
49 | 40 | } |
50 | |
|
51 | |
protected void doConnect() throws Exception |
52 | |
{ |
53 | 40 | if (service == null) |
54 | |
{ |
55 | 40 | service = createService(endpoint); |
56 | |
} |
57 | 40 | } |
58 | |
|
59 | |
protected void doDisconnect() throws Exception |
60 | |
{ |
61 | 40 | if (service != null) |
62 | |
{ |
63 | 40 | service = null; |
64 | |
} |
65 | 40 | } |
66 | |
|
67 | |
protected void doDispose() |
68 | |
{ |
69 | |
|
70 | 40 | } |
71 | |
|
72 | |
protected synchronized EngineConfiguration getClientConfig(ImmutableEndpoint endpoint) |
73 | |
{ |
74 | 40 | if (clientConfig == null) |
75 | |
{ |
76 | |
|
77 | |
String config; |
78 | 40 | config = (String)endpoint.getProperty(AxisConnector.AXIS_CLIENT_CONFIG_PROPERTY); |
79 | |
|
80 | 40 | if (config != null) |
81 | |
{ |
82 | 0 | clientConfig = new FileProvider(config); |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 40 | clientConfig = connector.getClientProvider(); |
87 | |
} |
88 | |
} |
89 | 40 | return clientConfig; |
90 | |
} |
91 | |
|
92 | |
protected Service createService(ImmutableEndpoint endpoint) throws Exception |
93 | |
{ |
94 | |
|
95 | 40 | EngineConfiguration config = getClientConfig(endpoint); |
96 | 40 | return new Service(config); |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
protected MuleMessage doRequest(long timeout) throws Exception |
111 | |
{ |
112 | 48 | Call call = new Call(service); |
113 | 48 | String uri = endpoint.getEndpointURI().toString(); |
114 | 48 | call.setSOAPActionURI(uri); |
115 | 48 | call.setTargetEndpointAddress(uri); |
116 | |
|
117 | 48 | Properties params = endpoint.getEndpointURI().getUserParams(); |
118 | 48 | String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY); |
119 | 48 | call.setOperationName(method); |
120 | |
|
121 | 48 | String args[] = new String[params.size()]; |
122 | 48 | int i = 0; |
123 | 80 | for (Iterator iterator = params.values().iterator(); iterator.hasNext(); i++) |
124 | |
{ |
125 | 32 | args[i] = iterator.next().toString(); |
126 | |
} |
127 | |
|
128 | 48 | call.setOperationName(method); |
129 | 48 | call.setProperty(MuleProperties.MULE_ENDPOINT_PROPERTY, endpoint); |
130 | 48 | Object result = call.invoke(method, args); |
131 | 48 | return AxisMessageDispatcher.createMessage(result, call); |
132 | |
} |
133 | |
|
134 | |
public MuleMessage request(String endpoint, Object[] args) throws Exception |
135 | |
{ |
136 | 0 | Call call = new Call(service); |
137 | |
|
138 | 0 | call.setSOAPActionURI(endpoint); |
139 | 0 | call.setTargetEndpointAddress(endpoint); |
140 | |
|
141 | 0 | if (!endpoint.startsWith("axis:")) |
142 | |
{ |
143 | 0 | endpoint = "axis:" + endpoint; |
144 | |
} |
145 | 0 | EndpointURI ep = new MuleEndpointURI(endpoint); |
146 | 0 | String method = (String)ep.getParams().remove(MuleProperties.MULE_METHOD_PROPERTY); |
147 | 0 | call.setOperationName(method); |
148 | |
|
149 | 0 | call.setOperationName(method); |
150 | 0 | Object result = call.invoke(method, args); |
151 | 0 | return AxisMessageDispatcher.createMessage(result, call); |
152 | |
} |
153 | |
|
154 | |
public MuleMessage request(String endpoint, SOAPEnvelope envelope) throws Exception |
155 | |
{ |
156 | 0 | Call call = new Call(service); |
157 | |
|
158 | 0 | call.setSOAPActionURI(endpoint); |
159 | 0 | call.setTargetEndpointAddress(endpoint); |
160 | 0 | Object result = call.invoke(new Message(envelope)); |
161 | 0 | return AxisMessageDispatcher.createMessage(result, call); |
162 | |
} |
163 | |
|
164 | |
} |