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 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 return MessageExchangePattern.REQUEST_RESPONSE;
38 }
39
40 @Override
41 protected MessageExchangePattern getOutboundMessageExchangePattern()
42 {
43 return MessageExchangePattern.REQUEST_RESPONSE;
44 }
45
46 public WSProxyBuilder outboundTransformers(Transformer... outboundTransformers)
47 {
48 this.outboundTransformers = Arrays.asList((MessageProcessor[]) outboundTransformers);
49 return this;
50 }
51
52 public WSProxyBuilder outboundResponseTransformers(Transformer... outboundResponseTransformers)
53 {
54 this.outboundResponseTransformers = Arrays.asList((MessageProcessor[]) outboundResponseTransformers);
55 return this;
56 }
57
58 public WSProxyBuilder wsldLocation(URI wsldLocation)
59 {
60 this.wsldLocation = wsldLocation;
61 return this;
62 }
63
64 public WSProxyBuilder wsdlFile(File wsdlFile)
65 {
66 this.wsdlFile = wsdlFile;
67 return this;
68 }
69
70 @Override
71 protected WSProxy buildFlowConstruct(MuleContext muleContext) throws MuleException
72 {
73 if (wsdlFile != null)
74 {
75 return buildStaticWsdlContentsWSProxy(muleContext);
76 }
77
78 if (wsldLocation != null)
79 {
80 return buildStaticWsdlUriWSProxy(muleContext);
81 }
82
83 return buildDynamicWsdlUriWSProxy(muleContext);
84 }
85
86 private WSProxy buildDynamicWsdlUriWSProxy(MuleContext muleContext) throws MuleException
87 {
88 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 return new WSProxy(name, muleContext, getOrBuildInboundEndpoint(muleContext),
97 getOrBuildOutboundEndpoint(muleContext), FileUtils.readFileToString(wsdlFile));
98 }
99 catch (final IOException ioe)
100 {
101 throw new ConfigurationException(ioe);
102 }
103 }
104
105 private WSProxy buildStaticWsdlUriWSProxy(MuleContext muleContext) throws MuleException
106 {
107 return new WSProxy(name, muleContext, getOrBuildInboundEndpoint(muleContext),
108 getOrBuildOutboundEndpoint(muleContext), wsldLocation);
109 }
110 }