View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 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.io.IOException;
    16
    17  import javax.xml.namespace.QName;
    18
    19  import org.apache.xmlbeans.SchemaType;
    20  import org.apache.xmlbeans.SchemaTypeLoader;
    21  import org.apache.xmlbeans.XmlBeans;
    22  import org.apache.xmlbeans.XmlException;
    23  import org.apache.xmlbeans.XmlObject;
    24  import org.apache.xmlbeans.XmlOptions;
    25  import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
    26
    27  import com.eviware.soapui.SoapUI;
    28  import com.eviware.soapui.impl.wsdl.support.Constants;
    29
    30  /***
    31   * SoapVersion for SOAP 1.1
    32   *
    33   * @author ole.matzura
    34   */
    35
    36  public class SoapVersion11 extends AbstractSoapVersion
    37  {
    38     private final static QName envelopeQName  = new QName(Constants.SOAP11_ENVELOPE_NS, "Envelope");
    39     private final static QName bodyQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Body");
    40     private final static QName faultQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Fault");
    41     private final static QName headerQName = new QName(Constants.SOAP11_ENVELOPE_NS, "Header");
    42
    43     SchemaTypeLoader soapSchema;
    44  	SchemaType soapEnvelopeType;
    45  	private XmlObject soapSchemaXml;
    46  	private XmlObject soapEncodingXml;
    47  	private SchemaType soapFaultType;
    48
    49  	public final static SoapVersion11 instance = new SoapVersion11();
    50
    51     private SoapVersion11()
    52     {
    53     	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    54     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
    55
    56     	try
    57     	{
    58     		XmlOptions options = new XmlOptions();
    59           options.setCompileNoValidation();
    60           options.setCompileNoPvrRule();
    61           options.setCompileDownloadUrls();
    62           options.setCompileNoUpaRule();
    63           options.setValidateTreatLaxAsSkip();
    64
    65  	   	soapSchemaXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEnvelope.xsd"), options);
    66  			soapSchema = XmlBeans.loadXsd(new XmlObject[] { soapSchemaXml });
    67
    68  	   	soapEnvelopeType = soapSchema.findDocumentType( envelopeQName );
    69  	   	soapFaultType = soapSchema.findDocumentType( faultQName );
    70
    71  	   	soapEncodingXml = XmlObject.Factory.parse(SoapUI.class.getResource("/soapEncoding.xsd"), options);
    72     	}
    73     	catch( Exception e )
    74     	{
    75     		SoapUI.logError( e );
    76     	}
    77     	finally
    78     	{
    79     		Thread.currentThread().setContextClassLoader( contextClassLoader );
    80     	}
    81     }
    82
    83  	public SchemaType getEnvelopeType()
    84  	{
    85  		return EnvelopeDocument.type;
    86  	}
    87
    88  	public String getEnvelopeNamespace()
    89  	{
    90  		return Constants.SOAP11_ENVELOPE_NS;
    91  	}
    92
    93  	public String getEncodingNamespace()
    94  	{
    95  		return Constants.SOAP_ENCODING_NS;
    96  	}
    97
    98  	public XmlObject getSoapEncodingSchema() throws XmlException, IOException
    99  	{
    100 		return soapEncodingXml;
    101 	}
    102
    103 	public XmlObject getSoapEnvelopeSchema() throws XmlException, IOException
    104 	{
    105 		return soapSchemaXml;
    106 	}
    107
    108 	public String toString()
    109 	{
    110 		return "SOAP 1.1";
    111 	}
    112
    113 	public String getContentTypeHttpHeader(String encoding, String soapAction)
    114 	{
    115 		if (encoding == null || encoding.trim().length() == 0)
    116 			return getContentType();
    117 		else
    118 			return getContentType() + ";charset=" + encoding;
    119 	}
    120
    121 	public String getSoapActionHeader( String soapAction )
    122 	{
    123 		if (soapAction == null || soapAction.length() == 0)
    124 		{
    125 			soapAction = "\"\"";
    126 		}
    127 		else
    128 		{
    129 			soapAction = "\"" + soapAction + "\"";
    130 		}
    131
    132 		return soapAction;
    133 	}
    134
    135 	public String getContentType()
    136 	{
    137 		return "text/xml";
    138 	}
    139
    140 	public QName getBodyQName()
    141 	{
    142 		return bodyQName;
    143 	}
    144
    145 	public QName getEnvelopeQName()
    146 	{
    147 		return envelopeQName;
    148 	}
    149
    150 	public QName getHeaderQName()
    151 	{
    152 		return headerQName;
    153 	}
    154
    155 	protected SchemaTypeLoader getSoapEnvelopeSchemaLoader()
    156 	{
    157 		return soapSchema;
    158 	}
    159
    160 	public SchemaType getFaultType()
    161 	{
    162 		return soapFaultType;
    163 	}
    164
    165 	public String getName()
    166 	{
    167 		return "SOAP 1.1";
    168 	}
    169 }