View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.soap;
14  
15  import com.eviware.soapui.impl.WsdlInterfaceFactory;
16  import com.eviware.soapui.impl.wsdl.WsdlInterface;
17  import com.eviware.soapui.impl.wsdl.WsdlProject;
18  import com.eviware.soapui.impl.wsdl.support.Constants;
19  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
20  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
21  import com.eviware.soapui.settings.WsdlSettings;
22  import org.apache.log4j.Logger;
23  
24  import javax.wsdl.Binding;
25  import javax.wsdl.BindingOperation;
26  import javax.wsdl.extensions.soap12.SOAP12Binding;
27  import java.util.Collections;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /***
32   * BindingImporter that can import a WsdlInterface from an SOAP 1.2/HTTP binding
33   * 
34   * @author Ole.Matzura
35   */
36  
37  public class Soap12HttpBindingImporter extends AbstractSoapBindingImporter
38  {
39     private final static Logger log = Logger.getLogger( Soap12HttpBindingImporter.class );
40     
41     public boolean canImport(Binding binding)
42     {
43        List<?> list = binding.getExtensibilityElements();
44        SOAP12Binding soapBinding = WsdlUtils.getExtensiblityElement( list, SOAP12Binding.class );
45        return soapBinding == null ? false : 
46           soapBinding.getTransportURI().startsWith( Constants.SOAP_HTTP_TRANSPORT ) ||
47           soapBinding.getTransportURI().startsWith( Constants.SOAP12_HTTP_BINDING_NS );
48     }
49  
50     @SuppressWarnings("unchecked")
51  	public WsdlInterface importBinding( WsdlProject project, WsdlContext wsdlContext, Binding binding ) throws Exception
52     {
53     	String name = project.getSettings().getBoolean( WsdlSettings.NAME_WITH_BINDING ) ? 
54     				binding.getQName().getLocalPart() : binding.getPortType().getQName().getLocalPart();
55     	
56        WsdlInterface iface = (WsdlInterface) project.addNewInterface( name, WsdlInterfaceFactory.WSDL_TYPE );
57        iface.setBindingName( binding.getQName() );
58        iface.setSoapVersion( SoapVersion.Soap12 );
59      
60        String [] endpoints = WsdlUtils.getEndpointsForBinding( wsdlContext.getDefinition(), binding );
61        for (int i = 0; i < endpoints.length; i++)
62        {
63           log.info("importing endpoint " + endpoints[i]);
64           iface.addEndpoint( endpoints[i] );
65        }
66        
67        List<BindingOperation> list = binding.getBindingOperations();
68        Collections.sort( list, new BindingOperationComparator());
69        
70        for (Iterator<BindingOperation> iter = list.iterator(); iter.hasNext();)
71        {
72           BindingOperation operation = (BindingOperation) iter.next();
73           
74           // sanity check
75           if( operation.getOperation() == null || operation.getOperation().isUndefined() )
76           {
77           	log.error( "BindingOperation [" + operation.getName() + "] is missing or referring to an invalid operation");
78           }
79           else
80           {
81           	log.info("importing operation " + operation.getName() );
82              iface.addNewOperation( operation );
83           }
84        }
85        
86        initWsAddressing(binding, iface, wsdlContext.getDefinition());
87        
88        return iface;
89     }
90     
91  }