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