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