1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.soap; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.impl.MuleMessage; |
15 | |
import org.mule.impl.UMODescriptorAware; |
16 | |
import org.mule.impl.endpoint.MuleEndpoint; |
17 | |
import org.mule.providers.NullPayload; |
18 | |
import org.mule.umo.UMODescriptor; |
19 | |
import org.mule.umo.UMOEventContext; |
20 | |
import org.mule.umo.UMOMessage; |
21 | |
import org.mule.umo.endpoint.UMOEndpoint; |
22 | |
import org.mule.umo.lifecycle.Callable; |
23 | |
import org.mule.umo.lifecycle.Initialisable; |
24 | |
import org.mule.umo.lifecycle.InitialisationException; |
25 | |
import org.mule.umo.routing.UMOOutboundRouter; |
26 | |
import org.mule.util.StringUtils; |
27 | |
import org.mule.util.IOUtils; |
28 | |
|
29 | |
import java.io.IOException; |
30 | |
|
31 | |
import org.apache.commons.logging.Log; |
32 | |
import org.apache.commons.logging.LogFactory; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | public class WSProxyService implements Callable, UMODescriptorAware, Initialisable |
55 | |
{ |
56 | |
|
57 | |
private String urlWebservice; |
58 | |
private String wsdlEndpoint; |
59 | |
private String wsdlFile; |
60 | |
private String wsdlFileContents; |
61 | 0 | private boolean useFile = false; |
62 | |
|
63 | |
private static final String HTTP_REQUEST = "http.request"; |
64 | |
private static final String WSDL_PARAM_1 = "?wsdl"; |
65 | |
private static final String WSDL_PARAM_2 = "&wsdl"; |
66 | |
|
67 | 0 | protected static transient Log logger = LogFactory.getLog(WSProxyService.class); |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public String getWsdlEndpoint() |
73 | |
{ |
74 | 0 | return wsdlEndpoint; |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public void setWsdlEndpoint(String urlWsdl) |
82 | |
{ |
83 | 0 | this.wsdlEndpoint = urlWsdl; |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public String getWsdlFile() |
90 | |
{ |
91 | 0 | return wsdlFile; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
public void setWsdlFile(String wsdlFile) |
98 | |
{ |
99 | 0 | this.wsdlFile = wsdlFile; |
100 | 0 | } |
101 | |
|
102 | |
public Object onCall(UMOEventContext eventContext) throws Exception |
103 | |
{ |
104 | |
|
105 | 0 | UMOMessage message = eventContext.getMessage(); |
106 | |
|
107 | |
|
108 | |
|
109 | 0 | String httpRequest = ((String)message.getProperty(HTTP_REQUEST)).toLowerCase(); |
110 | |
|
111 | |
|
112 | 0 | if ((httpRequest.indexOf(WSDL_PARAM_1) != -1) || (httpRequest.indexOf(WSDL_PARAM_2) != -1)) |
113 | |
{ |
114 | 0 | logger.debug("Retrieving WSDL from web service"); |
115 | |
|
116 | |
String wsdlString; |
117 | |
|
118 | 0 | if (this.useFile) |
119 | |
{ |
120 | |
|
121 | |
|
122 | 0 | eventContext.setStopFurtherProcessing(true); |
123 | 0 | return wsdlFileContents; |
124 | |
} |
125 | |
|
126 | 0 | UMOEndpoint webServiceEndpoint = new MuleEndpoint(this.wsdlEndpoint, false); |
127 | 0 | UMOMessage replyWSDL = eventContext.sendEvent(new MuleMessage(NullPayload.getInstance()), webServiceEndpoint); |
128 | |
|
129 | 0 | wsdlString = replyWSDL.getPayloadAsString(); |
130 | |
|
131 | |
|
132 | 0 | wsdlString = wsdlString.replaceAll(this.urlWebservice, eventContext.getEndpointURI().getAddress()); |
133 | |
|
134 | |
|
135 | 0 | MuleMessage modifiedWsdl = new MuleMessage(wsdlString, message); |
136 | |
|
137 | 0 | logger.debug("WSDL retrieved successfully"); |
138 | |
|
139 | |
|
140 | |
|
141 | 0 | eventContext.setStopFurtherProcessing(true); |
142 | |
|
143 | 0 | return modifiedWsdl; |
144 | |
} |
145 | |
else |
146 | |
|
147 | |
{ |
148 | 0 | logger.debug("Forwarding SOAP message"); |
149 | 0 | return eventContext.getMessage(); |
150 | |
} |
151 | |
} |
152 | |
|
153 | |
|
154 | |
public void setDescriptor(UMODescriptor descriptor) |
155 | |
{ |
156 | 0 | UMOOutboundRouter router = (UMOOutboundRouter)descriptor.getOutboundRouter().getRouters().get(0); |
157 | 0 | UMOEndpoint endpoint = (UMOEndpoint)router.getEndpoints().get(0); |
158 | 0 | this.urlWebservice = endpoint.getEndpointURI().getAddress(); |
159 | |
|
160 | |
|
161 | |
int paramIndex; |
162 | 0 | if ((paramIndex = this.urlWebservice.indexOf("?")) != -1) |
163 | |
{ |
164 | 0 | this.urlWebservice = this.urlWebservice.substring(0, paramIndex); |
165 | |
} |
166 | 0 | } |
167 | |
|
168 | |
public void initialise() throws InitialisationException |
169 | |
{ |
170 | |
|
171 | 0 | if (StringUtils.isNotBlank(this.wsdlFile)) |
172 | |
{ |
173 | |
try |
174 | |
{ |
175 | 0 | this.wsdlFileContents = IOUtils.getResourceAsString(this.wsdlFile, getClass()); |
176 | |
|
177 | 0 | if (StringUtils.isNotBlank(this.wsdlFileContents)) |
178 | |
{ |
179 | 0 | this.useFile = true; |
180 | 0 | logger.info("Using file " + this.wsdlFile + " as WSDL file"); |
181 | |
} |
182 | |
} |
183 | 0 | catch (IOException fileError) |
184 | |
{ |
185 | 0 | throw new InitialisationException(CoreMessages.failedToLoad(this.wsdlFile), this); |
186 | 0 | } |
187 | |
} |
188 | |
|
189 | 0 | if (!this.useFile) |
190 | |
{ |
191 | |
|
192 | |
|
193 | 0 | if (StringUtils.isBlank(this.wsdlEndpoint)) |
194 | |
{ |
195 | 0 | this.wsdlEndpoint = this.urlWebservice.concat("?WSDL"); |
196 | 0 | logger.info("Defaulting to: " + this.wsdlEndpoint); |
197 | |
} |
198 | |
else |
199 | |
{ |
200 | 0 | logger.info("Using url " + this.wsdlEndpoint + " as WSDL"); |
201 | |
} |
202 | |
} |
203 | |
|
204 | 0 | } |
205 | |
} |