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