View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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 java.util.Collections;
16  import java.util.Iterator;
17  import java.util.List;
18  
19  import javax.wsdl.Binding;
20  import javax.wsdl.BindingOperation;
21  import javax.wsdl.extensions.soap12.SOAP12Binding;
22  
23  import org.apache.log4j.Logger;
24  
25  import com.eviware.soapui.impl.WsdlInterfaceFactory;
26  import com.eviware.soapui.impl.wsdl.WsdlInterface;
27  import com.eviware.soapui.impl.wsdl.WsdlProject;
28  import com.eviware.soapui.impl.wsdl.support.Constants;
29  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
30  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
31  import com.eviware.soapui.settings.WsdlSettings;
32  
33  /***
34   * BindingImporter that can import a WsdlInterface from an SOAP 1.2/HTTP binding
35   * 
36   * @author Ole.Matzura
37   */
38  
39  public class Soap12HttpBindingImporter extends AbstractSoapBindingImporter
40  {
41  	private final static Logger log = Logger.getLogger( Soap12HttpBindingImporter.class );
42  
43  	public boolean canImport( Binding binding )
44  	{
45  		List<?> list = binding.getExtensibilityElements();
46  		SOAP12Binding soapBinding = WsdlUtils.getExtensiblityElement( list, SOAP12Binding.class );
47  		return soapBinding == null ? false : soapBinding.getTransportURI().startsWith( Constants.SOAP_HTTP_TRANSPORT )
48  				|| soapBinding.getTransportURI().startsWith( Constants.SOAP12_HTTP_BINDING_NS )
49  				|| soapBinding.getTransportURI().startsWith( Constants.SOAP_MICROSOFT_TCP );
50  	}
51  
52  	@SuppressWarnings( "unchecked" )
53  	public WsdlInterface importBinding( WsdlProject project, WsdlContext wsdlContext, Binding binding ) throws Exception
54  	{
55  		String name = project.getSettings().getBoolean( WsdlSettings.NAME_WITH_BINDING ) ? binding.getQName()
56  				.getLocalPart() : binding.getPortType().getQName().getLocalPart();
57  
58  		WsdlInterface iface = ( WsdlInterface )project.addNewInterface( name, WsdlInterfaceFactory.WSDL_TYPE );
59  		iface.setBindingName( binding.getQName() );
60  		iface.setSoapVersion( SoapVersion.Soap12 );
61  
62  		String[] endpoints = WsdlUtils.getEndpointsForBinding( wsdlContext.getDefinition(), binding );
63  		for( int i = 0; i < endpoints.length; i++ )
64  		{
65  			log.info( "importing endpoint " + endpoints[i] );
66  			iface.addEndpoint( endpoints[i] );
67  		}
68  
69  		List<BindingOperation> list = binding.getBindingOperations();
70  		Collections.sort( list, new BindingOperationComparator() );
71  
72  		for( Iterator<BindingOperation> iter = list.iterator(); iter.hasNext(); )
73  		{
74  			BindingOperation operation = ( BindingOperation )iter.next();
75  
76  			// sanity check
77  			if( operation.getOperation() == null || operation.getOperation().isUndefined() )
78  			{
79  				log
80  						.error( "BindingOperation [" + operation.getName()
81  								+ "] is missing or referring to an invalid operation" );
82  			}
83  			else
84  			{
85  				log.info( "importing operation " + operation.getName() );
86  				iface.addNewOperation( operation );
87  			}
88  		}
89  
90  		initWsAddressing( binding, iface, wsdlContext.getDefinition() );
91  
92  		return iface;
93  	}
94  
95  }