1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.ws.construct.builder; |
12 | |
|
13 | |
import java.io.File; |
14 | |
import java.io.IOException; |
15 | |
import java.net.URI; |
16 | |
import java.util.Arrays; |
17 | |
|
18 | |
import org.mule.MessageExchangePattern; |
19 | |
import org.mule.api.MuleContext; |
20 | |
import org.mule.api.MuleException; |
21 | |
import org.mule.api.config.ConfigurationException; |
22 | |
import org.mule.api.processor.MessageProcessor; |
23 | |
import org.mule.api.transformer.Transformer; |
24 | |
import org.mule.construct.builder.AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder; |
25 | |
import org.mule.module.ws.construct.WSProxy; |
26 | |
import org.mule.util.FileUtils; |
27 | |
|
28 | 0 | public class WSProxyBuilder extends |
29 | |
AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder<WSProxyBuilder, WSProxy> |
30 | |
{ |
31 | |
protected URI wsldLocation; |
32 | |
protected File wsdlFile; |
33 | |
|
34 | |
@Override |
35 | |
protected MessageExchangePattern getInboundMessageExchangePattern() |
36 | |
{ |
37 | 0 | return MessageExchangePattern.REQUEST_RESPONSE; |
38 | |
} |
39 | |
|
40 | |
@Override |
41 | |
protected MessageExchangePattern getOutboundMessageExchangePattern() |
42 | |
{ |
43 | 0 | return MessageExchangePattern.REQUEST_RESPONSE; |
44 | |
} |
45 | |
|
46 | |
public WSProxyBuilder outboundTransformers(Transformer... outboundTransformers) |
47 | |
{ |
48 | 0 | this.outboundTransformers = Arrays.asList((MessageProcessor[]) outboundTransformers); |
49 | 0 | return this; |
50 | |
} |
51 | |
|
52 | |
public WSProxyBuilder outboundResponseTransformers(Transformer... outboundResponseTransformers) |
53 | |
{ |
54 | 0 | this.outboundResponseTransformers = Arrays.asList((MessageProcessor[]) outboundResponseTransformers); |
55 | 0 | return this; |
56 | |
} |
57 | |
|
58 | |
public WSProxyBuilder wsldLocation(URI wsldLocation) |
59 | |
{ |
60 | 0 | this.wsldLocation = wsldLocation; |
61 | 0 | return this; |
62 | |
} |
63 | |
|
64 | |
public WSProxyBuilder wsdlFile(File wsdlFile) |
65 | |
{ |
66 | 0 | this.wsdlFile = wsdlFile; |
67 | 0 | return this; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
protected WSProxy buildFlowConstruct(MuleContext muleContext) throws MuleException |
72 | |
{ |
73 | 0 | if (wsdlFile != null) |
74 | |
{ |
75 | 0 | return buildStaticWsdlContentsWSProxy(muleContext); |
76 | |
} |
77 | |
|
78 | 0 | if (wsldLocation != null) |
79 | |
{ |
80 | 0 | return buildStaticWsdlUriWSProxy(muleContext); |
81 | |
} |
82 | |
|
83 | 0 | return buildDynamicWsdlUriWSProxy(muleContext); |
84 | |
} |
85 | |
|
86 | |
private WSProxy buildDynamicWsdlUriWSProxy(MuleContext muleContext) throws MuleException |
87 | |
{ |
88 | 0 | return new WSProxy(name, muleContext, getOrBuildInboundEndpoint(muleContext), |
89 | |
getOrBuildOutboundEndpoint(muleContext)); |
90 | |
} |
91 | |
|
92 | |
private WSProxy buildStaticWsdlContentsWSProxy(MuleContext muleContext) throws MuleException |
93 | |
{ |
94 | |
try |
95 | |
{ |
96 | 0 | return new WSProxy(name, muleContext, getOrBuildInboundEndpoint(muleContext), |
97 | |
getOrBuildOutboundEndpoint(muleContext), FileUtils.readFileToString(wsdlFile)); |
98 | |
} |
99 | 0 | catch (final IOException ioe) |
100 | |
{ |
101 | 0 | throw new ConfigurationException(ioe); |
102 | |
} |
103 | |
} |
104 | |
|
105 | |
private WSProxy buildStaticWsdlUriWSProxy(MuleContext muleContext) throws MuleException |
106 | |
{ |
107 | 0 | return new WSProxy(name, muleContext, getOrBuildInboundEndpoint(muleContext), |
108 | |
getOrBuildOutboundEndpoint(muleContext), wsldLocation); |
109 | |
} |
110 | |
} |