1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.soap.xfire.transport;
12
13 import org.mule.providers.soap.xfire.MuleInvoker;
14 import org.mule.umo.manager.UMOWorkManager;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.codehaus.xfire.MessageContext;
19 import org.codehaus.xfire.service.Binding;
20 import org.codehaus.xfire.service.Service;
21 import org.codehaus.xfire.soap.Soap11;
22 import org.codehaus.xfire.soap.Soap12;
23 import org.codehaus.xfire.soap.SoapTransport;
24 import org.codehaus.xfire.soap.SoapTransportHelper;
25 import org.codehaus.xfire.soap.SoapVersion;
26 import org.codehaus.xfire.transport.AbstractTransport;
27 import org.codehaus.xfire.transport.Channel;
28 import org.codehaus.xfire.transport.DefaultEndpoint;
29 import org.codehaus.xfire.transport.MapSession;
30 import org.codehaus.xfire.transport.Session;
31 import org.codehaus.xfire.wsdl11.WSDL11Transport;
32
33
34
35
36 public class MuleLocalTransport extends AbstractTransport implements SoapTransport, WSDL11Transport
37 {
38
39 public static final String SOAP11_HTTP_BINDING = "http://schemas.xmlsoap.org/soap/http";
40 public static final String SOAP12_HTTP_BINDING = "http://www.w3.org/2003/05/soap/bindings/HTTP/";
41 public static final String BINDING_ID = "urn:xfire:transport:local";
42 public static final String URI_PREFIX = "xfire.local://";
43
44
45
46
47 protected transient Log logger = LogFactory.getLog(getClass());
48
49 private Session session;
50 private boolean maintainSession;
51 protected final UMOWorkManager workManager;
52
53 public MuleLocalTransport(UMOWorkManager workManager)
54 {
55 super();
56 SoapTransportHelper.createSoapTransport(this);
57 this.workManager = workManager;
58 }
59
60 public String getServiceURL(Service service)
61 {
62 String ep = ((MuleInvoker) service.getInvoker()).getEndpoint().getEndpointURI().getAddress();
63 return ep + "/" + service.getSimpleName();
64 }
65
66 protected Channel createNewChannel(String uri)
67 {
68 logger.debug("Creating new channel for uri: " + uri);
69
70 MuleLocalChannel c = new MuleLocalChannel(uri, this, session);
71 c.setWorkManager(workManager);
72 c.setEndpoint(new DefaultEndpoint());
73
74 return c;
75 }
76
77 public void setMaintainSession(boolean maintainSession)
78 {
79 this.maintainSession = maintainSession;
80 resetSession();
81 }
82
83 public void resetSession()
84 {
85 if (maintainSession)
86 {
87 session = new MapSession();
88 }
89 else
90 {
91 session = null;
92 }
93 }
94
95 protected String getUriPrefix()
96 {
97 return URI_PREFIX;
98 }
99
100 public String[] getSupportedBindings()
101 {
102 return new String[]{BINDING_ID};
103 }
104
105 public String[] getKnownUriSchemes()
106 {
107 return new String[]{URI_PREFIX};
108 }
109
110 public String getName()
111 {
112 return "Local";
113 }
114
115 public String[] getSoapTransportIds()
116 {
117 return new String[]{BINDING_ID};
118 }
119
120 public Binding findBinding(MessageContext context, Service service)
121 {
122 SoapVersion version = context.getCurrentMessage().getSoapVersion();
123
124 if (version instanceof Soap11)
125 {
126 return service.getBinding(SOAP11_HTTP_BINDING);
127 }
128 else if (version instanceof Soap12)
129 {
130 return service.getBinding(SOAP12_HTTP_BINDING);
131 }
132
133 return super.findBinding(context, service);
134 }
135 }