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 public static final String SOAP11_HTTP_BINDING = "http://schemas.xmlsoap.org/soap/http";
39 public static final String SOAP12_HTTP_BINDING = "http://www.w3.org/2003/05/soap/bindings/HTTP/";
40 public static final String BINDING_ID = "urn:xfire:transport:local";
41 public static final String URI_PREFIX = "xfire.local://";
42
43
44
45
46 protected transient Log logger = LogFactory.getLog(getClass());
47
48 private Session session;
49 private boolean maintainSession;
50 protected final UMOWorkManager workManager;
51
52 public MuleLocalTransport(UMOWorkManager workManager)
53 {
54 super();
55 SoapTransportHelper.createSoapTransport(this);
56 this.workManager = workManager;
57 }
58
59 public String getServiceURL(Service service)
60 {
61 String ep = ((MuleInvoker) service.getInvoker()).getEndpoint().getEndpointURI().getAddress();
62 return ep + "/" + service.getSimpleName();
63 }
64
65 protected Channel createNewChannel(String uri)
66 {
67 logger.debug("Creating new channel for uri: " + uri);
68
69 MuleLocalChannel c = new MuleLocalChannel(uri, this, session);
70 c.setWorkManager(workManager);
71 c.setEndpoint(new DefaultEndpoint());
72
73 return c;
74 }
75
76 public void setMaintainSession(boolean maintainSession)
77 {
78 this.maintainSession = maintainSession;
79 resetSession();
80 }
81
82 public void resetSession()
83 {
84 if (maintainSession)
85 {
86 session = new MapSession();
87 }
88 else
89 {
90 session = null;
91 }
92 }
93
94 protected String getUriPrefix()
95 {
96 return URI_PREFIX;
97 }
98
99 public String[] getSupportedBindings()
100 {
101 return new String[]{BINDING_ID};
102 }
103
104 public String[] getKnownUriSchemes()
105 {
106 return new String[]{URI_PREFIX};
107 }
108
109 public String getName()
110 {
111 return "Local";
112 }
113
114 public String[] getSoapTransportIds()
115 {
116 return new String[]{BINDING_ID};
117 }
118
119 public Binding findBinding(MessageContext context, Service service)
120 {
121 SoapVersion version = context.getCurrentMessage().getSoapVersion();
122
123 if (version instanceof Soap11)
124 {
125 return service.getBinding(SOAP11_HTTP_BINDING);
126 }
127 else if (version instanceof Soap12)
128 {
129 return service.getBinding(SOAP12_HTTP_BINDING);
130 }
131
132 return super.findBinding(context, service);
133 }
134 }