Coverage Report - org.mule.transport.cxf.transport.MuleUniversalTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleUniversalTransport
65%
42/65
33%
4/12
0
MuleUniversalTransport$HttpAddressType
67%
4/6
N/A
0
MuleUniversalTransport$HttpEndpointInfo
100%
10/10
50%
2/4
0
 
 1  
 /*
 2  
  * $Id: MuleUniversalTransport.java 11549 2008-04-09 05:12:30Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.cxf.transport;
 12  
 
 13  
 import org.mule.transport.cxf.CxfConnector;
 14  
 
 15  
 import java.io.IOException;
 16  
 import java.util.ArrayList;
 17  
 import java.util.HashMap;
 18  
 import java.util.HashSet;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 import java.util.Set;
 23  
 
 24  
 import javax.wsdl.Port;
 25  
 import javax.wsdl.extensions.http.HTTPAddress;
 26  
 import javax.wsdl.extensions.soap.SOAPAddress;
 27  
 import javax.xml.namespace.QName;
 28  
 
 29  
 import org.apache.cxf.Bus;
 30  
 import org.apache.cxf.service.Service;
 31  
 import org.apache.cxf.service.model.BindingInfo;
 32  
 import org.apache.cxf.service.model.EndpointInfo;
 33  
 import org.apache.cxf.service.model.ServiceInfo;
 34  
 import org.apache.cxf.transport.AbstractTransportFactory;
 35  
 import org.apache.cxf.transport.Conduit;
 36  
 import org.apache.cxf.transport.ConduitInitiator;
 37  
 import org.apache.cxf.transport.Destination;
 38  
 import org.apache.cxf.transport.DestinationFactory;
 39  
 import org.apache.cxf.ws.addressing.AttributedURIType;
 40  
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 41  
 import org.apache.cxf.wsdl11.WSDLEndpointFactory;
 42  
 import org.xmlsoap.schemas.wsdl.http.AddressType;
 43  
 
 44  
 public class MuleUniversalTransport extends AbstractTransportFactory
 45  
     implements ConduitInitiator, DestinationFactory, WSDLEndpointFactory
 46  
 {
 47  
 
 48  
     public static final String TRANSPORT_ID = "http://mule.codehaus.org/cxf";
 49  
 
 50  2
     private static Set<String> PREFIXES = new HashSet<String>();
 51  
     static
 52  
     {
 53  2
         PREFIXES.add("http://");
 54  2
         PREFIXES.add("https://");
 55  2
         PREFIXES.add("jms://");
 56  2
         PREFIXES.add("vm://");
 57  2
         PREFIXES.add("xmpp://");
 58  2
         PREFIXES.add("smtp://");
 59  2
         PREFIXES.add("tcp://");
 60  2
     }
 61  
 
 62  130
     private Map<String, Destination> destinations = new HashMap<String, Destination>();
 63  
 
 64  
     private Bus bus;
 65  
 
 66  
     private CxfConnector connector;
 67  
 
 68  
     public MuleUniversalTransport(CxfConnector connector)
 69  
     {
 70  130
         super();
 71  
 
 72  130
         ArrayList<String> tids = new ArrayList<String>();
 73  130
         tids.add("http://schemas.xmlsoap.org/soap/http");
 74  130
         setTransportIds(tids);
 75  
 
 76  130
         this.connector = connector;
 77  130
     }
 78  
 
 79  
     public Destination getDestination(EndpointInfo ei) throws IOException
 80  
     {
 81  354
         return getDestination(ei, createReference(ei));
 82  
     }
 83  
 
 84  
     protected Destination getDestination(EndpointInfo ei, EndpointReferenceType reference) throws IOException
 85  
     {
 86  354
         String uri = reference.getAddress().getValue();
 87  354
         int idx = uri.indexOf('?');
 88  354
         if (idx != -1)
 89  
         {
 90  0
             uri = uri.substring(0, idx);
 91  
         }
 92  
 
 93  354
         synchronized (this)
 94  
         {
 95  354
             Destination d = destinations.get(uri);
 96  354
             if (d == null)
 97  
             {
 98  290
                 d = createDestination(ei, reference);
 99  290
                 destinations.put(uri, d);
 100  
             }
 101  354
             return d;
 102  0
         }
 103  
     }
 104  
 
 105  
     private Destination createDestination(EndpointInfo ei, EndpointReferenceType reference)
 106  
     {
 107  290
         return new MuleUniversalDestination(this, reference, ei);
 108  
     }
 109  
 
 110  
     public Conduit getConduit(EndpointInfo ei) throws IOException
 111  
     {
 112  72
         return new MuleUniversalConduit(this, connector, ei, null);
 113  
     }
 114  
 
 115  
     public Conduit getConduit(EndpointInfo ei, EndpointReferenceType target) throws IOException
 116  
     {
 117  0
         return new MuleUniversalConduit(this, connector, ei, target);
 118  
     }
 119  
 
 120  
     EndpointReferenceType createReference(EndpointInfo ei)
 121  
     {
 122  354
         EndpointReferenceType epr = new EndpointReferenceType();
 123  354
         AttributedURIType address = new AttributedURIType();
 124  354
         address.setValue(ei.getAddress());
 125  354
         epr.setAddress(address);
 126  354
         return epr;
 127  
     }
 128  
 
 129  
     @Override
 130  
     public Set<String> getUriPrefixes()
 131  
     {
 132  342
         return PREFIXES;
 133  
     }
 134  
 
 135  
     public Bus getBus()
 136  
     {
 137  0
         return bus;
 138  
     }
 139  
 
 140  
     public void setBus(Bus bus)
 141  
     {
 142  0
         this.bus = bus;
 143  0
     }
 144  
 
 145  
     void remove(MuleUniversalDestination destination)
 146  
     {
 147  576
         destinations.remove(destination.getAddress().getAddress().getValue());
 148  576
     }
 149  
 
 150  
     public CxfConnector getConnector()
 151  
     {
 152  0
         return connector;
 153  
     }
 154  
 
 155  
     // Stuff relating to building of the <soap:address/> -
 156  
     // I have no idea how this really works, but it does
 157  
 
 158  
     public void createPortExtensors(EndpointInfo ei, Service service)
 159  
     {
 160  
         // TODO
 161  272
     }
 162  
 
 163  
     @SuppressWarnings("unchecked")
 164  
     public EndpointInfo createEndpointInfo(ServiceInfo serviceInfo, BindingInfo b, Port port)
 165  
     {
 166  272
         if (port != null)
 167  
         {
 168  0
             List ees = port.getExtensibilityElements();
 169  0
             for (Iterator itr = ees.iterator(); itr.hasNext();)
 170  
             {
 171  0
                 Object extensor = itr.next();
 172  
 
 173  0
                 if (extensor instanceof HTTPAddress)
 174  
                 {
 175  0
                     final HTTPAddress httpAdd = (HTTPAddress) extensor;
 176  
 
 177  0
                     EndpointInfo info = new HttpEndpointInfo(serviceInfo,
 178  
                         "http://schemas.xmlsoap.org/wsdl/http/");
 179  0
                     info.setAddress(httpAdd.getLocationURI());
 180  0
                     info.addExtensor(httpAdd);
 181  0
                     return info;
 182  
                 }
 183  0
                 else if (extensor instanceof AddressType)
 184  
                 {
 185  0
                     final AddressType httpAdd = (AddressType) extensor;
 186  
 
 187  0
                     EndpointInfo info = new HttpEndpointInfo(serviceInfo,
 188  
                         "http://schemas.xmlsoap.org/wsdl/http/");
 189  0
                     info.setAddress(httpAdd.getLocation());
 190  0
                     info.addExtensor(httpAdd);
 191  0
                     return info;
 192  
                 }
 193  0
             }
 194  
         }
 195  272
         HttpEndpointInfo hei = new HttpEndpointInfo(serviceInfo, "http://schemas.xmlsoap.org/wsdl/http/");
 196  272
         AddressType at = new HttpAddressType();
 197  272
         hei.addExtensor(at);
 198  
 
 199  272
         return hei;
 200  
     }
 201  
 
 202  
     private static class HttpEndpointInfo extends EndpointInfo
 203  
     {
 204  
         AddressType saddress;
 205  
 
 206  
         HttpEndpointInfo(ServiceInfo serv, String trans)
 207  
         {
 208  272
             super(serv, trans);
 209  272
         }
 210  
 
 211  
         public void setAddress(String s)
 212  
         {
 213  284
             super.setAddress(s);
 214  284
             if (saddress != null)
 215  
             {
 216  284
                 saddress.setLocation(s);
 217  
             }
 218  284
         }
 219  
 
 220  
         public void addExtensor(Object el)
 221  
         {
 222  272
             super.addExtensor(el);
 223  272
             if (el instanceof AddressType)
 224  
             {
 225  272
                 saddress = (AddressType) el;
 226  
             }
 227  272
         }
 228  
     }
 229  
 
 230  
     private static class HttpAddressType extends AddressType implements HTTPAddress, SOAPAddress
 231  
     {
 232  
         public HttpAddressType()
 233  
         {
 234  272
             super();
 235  272
             setElementType(new QName("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
 236  272
         }
 237  
 
 238  
         public String getLocationURI()
 239  
         {
 240  12
             return getLocation();
 241  
         }
 242  
 
 243  
         public void setLocationURI(String locationURI)
 244  
         {
 245  0
             setLocation(locationURI);
 246  0
         }
 247  
 
 248  
     }
 249  
 }