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 | 0 | super(endpoint); |
47 | 0 | this.connector = (AxisConnector)endpoint.getConnector(); |
48 | 0 | AxisProperties.setProperty("axis.doAutoTypes", Boolean.toString(connector.isDoAutoTypes())); |
49 | 0 | } |
50 | |
|
51 | |
protected void doConnect() throws Exception |
52 | |
{ |
53 | 0 | if (service == null) |
54 | |
{ |
55 | 0 | service = createService(endpoint); |
56 | |
} |
57 | 0 | } |
58 | |
|
59 | |
protected void doDisconnect() throws Exception |
60 | |
{ |
61 | 0 | if (service != null) |
62 | |
{ |
63 | 0 | service = null; |
64 | |
} |
65 | 0 | } |
66 | |
|
67 | |
protected void doDispose() |
68 | |
{ |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
protected synchronized EngineConfiguration getClientConfig(ImmutableEndpoint endpoint) |
73 | |
{ |
74 | 0 | if (clientConfig == null) |
75 | |
{ |
76 | |
|
77 | |
String config; |
78 | 0 | config = (String)endpoint.getProperty(AxisConnector.AXIS_CLIENT_CONFIG_PROPERTY); |
79 | |
|
80 | 0 | if (config != null) |
81 | |
{ |
82 | 0 | clientConfig = new FileProvider(config); |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 0 | clientConfig = connector.getClientProvider(); |
87 | |
} |
88 | |
} |
89 | 0 | return clientConfig; |
90 | |
} |
91 | |
|
92 | |
protected Service createService(ImmutableEndpoint endpoint) throws Exception |
93 | |
{ |
94 | |
|
95 | 0 | EngineConfiguration config = getClientConfig(endpoint); |
96 | 0 | 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 | 0 | Call call = new Call(service); |
113 | 0 | String uri = endpoint.getEndpointURI().toString(); |
114 | 0 | call.setSOAPActionURI(uri); |
115 | 0 | call.setTargetEndpointAddress(uri); |
116 | |
|
117 | 0 | Properties params = endpoint.getEndpointURI().getUserParams(); |
118 | 0 | String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY); |
119 | 0 | call.setOperationName(method); |
120 | |
|
121 | 0 | String args[] = new String[params.size()]; |
122 | 0 | int i = 0; |
123 | 0 | for (Iterator iterator = params.values().iterator(); iterator.hasNext(); i++) |
124 | |
{ |
125 | 0 | args[i] = iterator.next().toString(); |
126 | |
} |
127 | |
|
128 | 0 | call.setOperationName(method); |
129 | 0 | call.setProperty(MuleProperties.MULE_ENDPOINT_PROPERTY, endpoint); |
130 | 0 | call.setProperty(MuleProperties.MULE_CONTEXT_PROPERTY, connector.getMuleContext()); |
131 | |
|
132 | 0 | Object result = call.invoke(method, args); |
133 | 0 | return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext()); |
134 | |
} |
135 | |
|
136 | |
public MuleMessage request(String endpoint, Object[] args) throws Exception |
137 | |
{ |
138 | 0 | Call call = new Call(service); |
139 | |
|
140 | 0 | call.setSOAPActionURI(endpoint); |
141 | 0 | call.setTargetEndpointAddress(endpoint); |
142 | |
|
143 | 0 | if (!endpoint.startsWith("axis:")) |
144 | |
{ |
145 | 0 | endpoint = "axis:" + endpoint; |
146 | |
} |
147 | 0 | EndpointURI ep = new MuleEndpointURI(endpoint, connector.getMuleContext()); |
148 | 0 | String method = (String)ep.getParams().remove(MuleProperties.MULE_METHOD_PROPERTY); |
149 | 0 | call.setOperationName(method); |
150 | |
|
151 | 0 | call.setOperationName(method); |
152 | 0 | Object result = call.invoke(method, args); |
153 | 0 | return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext()); |
154 | |
} |
155 | |
|
156 | |
public MuleMessage request(String endpoint, SOAPEnvelope envelope) throws Exception |
157 | |
{ |
158 | 0 | Call call = new Call(service); |
159 | |
|
160 | 0 | call.setSOAPActionURI(endpoint); |
161 | 0 | call.setTargetEndpointAddress(endpoint); |
162 | 0 | Object result = call.invoke(new Message(envelope)); |
163 | 0 | return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext()); |
164 | |
} |
165 | |
|
166 | |
} |