001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.support.soap;
014:
015: import java.io.IOException;
016:
017: import javax.xml.namespace.QName;
018:
019: import org.apache.xmlbeans.SchemaType;
020: import org.apache.xmlbeans.SchemaTypeLoader;
021: import org.apache.xmlbeans.XmlBeans;
022: import org.apache.xmlbeans.XmlException;
023: import org.apache.xmlbeans.XmlObject;
024: import org.w3.x2003.x05.soapEnvelope.EnvelopeDocument;
025: import org.w3.x2003.x05.soapEnvelope.FaultDocument;
026:
027: import com.eviware.soapui.SoapUI;
028: import com.eviware.soapui.impl.wsdl.support.Constants;
029:
030: /**
031: * SoapVersion for SOAP 1.2
032: *
033: * @author ole.matzura
034: */
035:
036: public class SoapVersion12 extends AbstractSoapVersion {
037: private final static QName envelopeQName = new QName(
038: Constants.SOAP12_ENVELOPE_NS, "Envelope");
039: private final static QName bodyQName = new QName(
040: Constants.SOAP12_ENVELOPE_NS, "Body");
041: private final static QName faultQName = new QName(
042: Constants.SOAP11_ENVELOPE_NS, "Fault");
043: private final static QName headerQName = new QName(
044: Constants.SOAP12_ENVELOPE_NS, "Header");
045: public final static SoapVersion12 instance = new SoapVersion12();
046:
047: private SchemaTypeLoader soapSchema;
048: private XmlObject soapSchemaXml;
049: private XmlObject soapEncodingXml;
050:
051: private SoapVersion12() {
052: ClassLoader contextClassLoader = Thread.currentThread()
053: .getContextClassLoader();
054: Thread.currentThread().setContextClassLoader(
055: SoapUI.class.getClassLoader());
056:
057: try {
058: soapSchemaXml = XmlObject.Factory.parse(SoapUI.class
059: .getResource("/soapEnvelope12.xsd"));
060: soapSchema = XmlBeans
061: .loadXsd(new XmlObject[] { soapSchemaXml });
062: soapEncodingXml = XmlObject.Factory.parse(SoapUI.class
063: .getResource("/soapEncoding12.xsd"));
064: } catch (Exception e) {
065: SoapUI.logError(e);
066: } finally {
067: Thread.currentThread().setContextClassLoader(
068: contextClassLoader);
069: }
070: }
071:
072: public String getEncodingNamespace() {
073: return "http://www.w3.org/2003/05/soap-encoding";
074: }
075:
076: public XmlObject getSoapEncodingSchema() throws XmlException,
077: IOException {
078: return soapEncodingXml;
079: }
080:
081: public XmlObject getSoapEnvelopeSchema() throws XmlException,
082: IOException {
083: return soapSchemaXml;
084: }
085:
086: public String getEnvelopeNamespace() {
087: return Constants.SOAP12_ENVELOPE_NS;
088: }
089:
090: public SchemaType getEnvelopeType() {
091: return EnvelopeDocument.type;
092: }
093:
094: public String toString() {
095: return "SOAP 1.2";
096: }
097:
098: public String getContentTypeHttpHeader(String encoding) {
099: if (encoding == null || encoding.trim().length() == 0)
100: return getContentType();
101: else
102: return getContentType() + ";charset=" + encoding;
103: }
104:
105: public String getContentType() {
106: return "application/soap+xml";
107: }
108:
109: public QName getBodyQName() {
110: return bodyQName;
111: }
112:
113: public QName getEnvelopeQName() {
114: return envelopeQName;
115: }
116:
117: public QName getHeaderQName() {
118: return headerQName;
119: }
120:
121: protected SchemaTypeLoader getSoapEnvelopeSchemaLoader() {
122: return soapSchema;
123: }
124:
125: public static QName getFaultQName() {
126: return faultQName;
127: }
128:
129: public SchemaType getFaultType() {
130: return FaultDocument.type;
131: }
132:
133: public String getName() {
134: return "SOAP 1.2";
135: }
136: }
|