View Javadoc

    1   package org.codehaus.xfire.transport;
    2
    3   import java.util.ArrayList;
    4   import java.util.List;
    5
    6   import javax.wsdl.Binding;
    7   import javax.wsdl.BindingInput;
    8   import javax.wsdl.BindingOperation;
    9   import javax.wsdl.BindingOutput;
    10  import javax.wsdl.Definition;
    11  import javax.wsdl.Operation;
    12  import javax.wsdl.Port;
    13  import javax.wsdl.PortType;
    14  import javax.wsdl.extensions.soap.SOAPBinding;
    15  import javax.wsdl.extensions.soap.SOAPBody;
    16  import javax.wsdl.extensions.soap.SOAPHeader;
    17  import javax.xml.namespace.QName;
    18
    19  import org.codehaus.xfire.service.Service;
    20  import org.codehaus.xfire.service.ServiceInfo;
    21  import org.codehaus.xfire.soap.SoapConstants;
    22  import org.codehaus.xfire.wsdl11.WSDL11ParameterBinding;
    23  import org.codehaus.xfire.wsdl11.WSDL11Transport;
    24  import org.codehaus.xfire.wsdl11.builder.WSDLBuilder;
    25
    26  import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
    27  import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
    28  import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
    29  import com.ibm.wsdl.extensions.soap.SOAPHeaderImpl;
    30  import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
    31
    32  /***
    33   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    34   * @since Dec 21, 2004
    35   */
    36  public abstract class AbstractWSDLTransport
    37      extends AbstractTransport
    38      implements WSDL11Transport
    39  {
    40      public abstract String getServiceURL(Service service);
    41
    42      public abstract String getTransportURI(Service service);
    43
    44       /***
    45       * @see org.codehaus.xfire.transport.Transport#createBinding(javax.wsdl.PortType)
    46       */
    47      public Binding createBinding(WSDLBuilder builder, PortType portType, WSDL11ParameterBinding paramBinding)
    48      {
    49          Definition def = builder.getDefinition();
    50          ServiceInfo info = builder.getService().getServiceInfo();
    51
    52          Binding binding = def.createBinding();
    53          binding.setQName( new QName( info.getName().getNamespaceURI(),
    54                                       info.getName().getLocalPart() + getName() + "Binding" ) );
    55          binding.setPortType( portType );
    56          binding.setUndefined(false);
    57
    58          binding.addExtensibilityElement( createSoapBinding(builder.getService(), paramBinding) );
    59
    60          return binding;
    61      }
    62
    63      protected SOAPBinding createSoapBinding(Service endpoint, WSDL11ParameterBinding binding)
    64      {
    65          SOAPBinding soapBind = new SOAPBindingImpl();
    66
    67          String style = binding.getStyle();
    68          if ( style.equals( SoapConstants.STYLE_WRAPPED ) )
    69              style = SoapConstants.STYLE_DOCUMENT;
    70
    71          soapBind.setStyle( style );
    72          soapBind.setTransportURI( getTransportURI(endpoint) );
    73
    74          return soapBind;
    75      }
    76
    77      /***
    78       * @see org.codehaus.xfire.transport.Transport#createPort(javax.wsdl.Binding)
    79       */
    80      public Port createPort(WSDLBuilder builder, Binding transportBinding)
    81      {
    82          Definition def = builder.getDefinition();
    83          Service service = builder.getService();
    84
    85          SOAPAddressImpl add = new SOAPAddressImpl();
    86          add.setLocationURI( getServiceURL( service ) );
    87
    88          Port port = def.createPort();
    89          port.setBinding( transportBinding );
    90          port.setName( service.getName() + getName() + "Port" );
    91          port.addExtensibilityElement( add );
    92
    93          return port;
    94      }
    95
    96      /***
    97       * @see org.codehaus.xfire.transport.Transport#createBindingOperation(javax.wsdl.Message, javax.wsdl.Message, org.codehaus.xfire.java.JavaService)
    98       */
    99      public BindingOperation createBindingOperation(WSDLBuilder builder,
    100                                                    PortType portType,
    101                                                    Operation wsdlOp,
    102                                                    WSDL11ParameterBinding binding)
    103     {
    104         Definition def = builder.getDefinition();
    105         BindingOperation bindOp = def.createBindingOperation();
    106
    107         // Create bindings
    108         SOAPBody body = createSoapBody(builder.getService(), binding);
    109
    110         SOAPOperationImpl soapOp = new SOAPOperationImpl();
    111         soapOp.setSoapActionURI("");
    112
    113         BindingInput bindIn = def.createBindingInput();
    114         bindIn.setName( wsdlOp.getInput().getName() );
    115         bindIn.addExtensibilityElement( body );
    116
    117         if (wsdlOp.getOutput() != null)
    118         {
    119             BindingOutput bindOut = def.createBindingOutput();
    120             bindOut.setName( wsdlOp.getOutput().getName() );
    121             bindOut.addExtensibilityElement( body );
    122             bindOp.setBindingOutput( bindOut );
    123         }
    124
    125         bindOp.setName( wsdlOp.getName() );
    126         bindOp.setOperation( wsdlOp );
    127         bindOp.setBindingInput( bindIn );
    128         bindOp.addExtensibilityElement( soapOp );
    129
    130         return bindOp;
    131     }
    132
    133     public SOAPBody createSoapBody( Service endpoint, WSDL11ParameterBinding binding )
    134     {
    135         SOAPBody body = new SOAPBodyImpl();
    136         body.setUse( binding.getUse() );
    137
    138         if ( binding.getStyle().equals( SoapConstants.STYLE_RPC ) )
    139         {
    140             body.setNamespaceURI( endpoint.getServiceInfo().getName().getNamespaceURI() );
    141         }
    142
    143         if ( binding.getUse().equals( SoapConstants.USE_ENCODED ) )
    144         {
    145             List encodingStyles = new ArrayList();
    146             encodingStyles.add( endpoint.getSoapVersion().getSoapEncodingStyle() );
    147
    148             body.setEncodingStyles(encodingStyles);
    149         }
    150
    151         return body;
    152     }
    153
    154     public SOAPHeader createSoapHeader( Service endpoint, WSDL11ParameterBinding binding )
    155     {
    156         SOAPHeader header = new SOAPHeaderImpl();
    157         header.setUse( binding.getUse() );
    158
    159         if ( binding.getStyle().equals( SoapConstants.STYLE_RPC ) )
    160         {
    161             header.setNamespaceURI( endpoint.getServiceInfo().getName().getNamespaceURI() );
    162         }
    163
    164         if ( binding.getUse().equals( SoapConstants.USE_ENCODED ) )
    165         {
    166             List encodingStyles = new ArrayList();
    167             encodingStyles.add( endpoint.getSoapVersion().getSoapEncodingStyle() );
    168
    169             header.setEncodingStyles(encodingStyles);
    170         }
    171
    172         return header;
    173     }
    174 }