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.apache.xmlbeans.XmlOptions;
025: import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
026:
027: import com.eviware.soapui.SoapUI;
028: import com.eviware.soapui.impl.wsdl.support.Constants;
029:
030: /**
031: * SoapVersion for SOAP 1.1
032: *
033: * @author ole.matzura
034: */
035:
036: public class SoapVersion11 extends AbstractSoapVersion {
037: private final static QName envelopeQName = new QName(
038: Constants.SOAP11_ENVELOPE_NS, "Envelope");
039: private final static QName bodyQName = new QName(
040: Constants.SOAP11_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.SOAP11_ENVELOPE_NS, "Header");
045:
046: SchemaTypeLoader soapSchema;
047: SchemaType soapEnvelopeType;
048: private XmlObject soapSchemaXml;
049: private XmlObject soapEncodingXml;
050: private SchemaType soapFaultType;
051:
052: public final static SoapVersion11 instance = new SoapVersion11();
053:
054: private SoapVersion11() {
055: ClassLoader contextClassLoader = Thread.currentThread()
056: .getContextClassLoader();
057: Thread.currentThread().setContextClassLoader(
058: SoapUI.class.getClassLoader());
059:
060: try {
061: XmlOptions options = new XmlOptions();
062: options.setCompileNoValidation();
063: options.setCompileNoPvrRule();
064: options.setCompileDownloadUrls();
065: options.setCompileNoUpaRule();
066: options.setValidateTreatLaxAsSkip();
067:
068: soapSchemaXml = XmlObject.Factory.parse(SoapUI.class
069: .getResource("/soapEnvelope.xsd"), options);
070: soapSchema = XmlBeans
071: .loadXsd(new XmlObject[] { soapSchemaXml });
072:
073: soapEnvelopeType = soapSchema
074: .findDocumentType(envelopeQName);
075: soapFaultType = soapSchema.findDocumentType(faultQName);
076:
077: soapEncodingXml = XmlObject.Factory.parse(SoapUI.class
078: .getResource("/soapEncoding.xsd"), options);
079: } catch (Exception e) {
080: SoapUI.logError(e);
081: } finally {
082: Thread.currentThread().setContextClassLoader(
083: contextClassLoader);
084: }
085: }
086:
087: public SchemaType getEnvelopeType() {
088: return EnvelopeDocument.type;
089: }
090:
091: public String getEnvelopeNamespace() {
092: return Constants.SOAP11_ENVELOPE_NS;
093: }
094:
095: public String getEncodingNamespace() {
096: return Constants.SOAP_ENCODING_NS;
097: }
098:
099: public XmlObject getSoapEncodingSchema() throws XmlException,
100: IOException {
101: return soapEncodingXml;
102: }
103:
104: public XmlObject getSoapEnvelopeSchema() throws XmlException,
105: IOException {
106: return soapSchemaXml;
107: }
108:
109: public String toString() {
110: return "SOAP 1.1";
111: }
112:
113: public String getContentTypeHttpHeader(String encoding) {
114: if (encoding == null || encoding.trim().length() == 0)
115: return getContentType();
116: else
117: return getContentType() + ";charset=" + encoding;
118: }
119:
120: public String getContentType() {
121: return "text/xml";
122: }
123:
124: public QName getBodyQName() {
125: return bodyQName;
126: }
127:
128: public QName getEnvelopeQName() {
129: return envelopeQName;
130: }
131:
132: public QName getHeaderQName() {
133: return headerQName;
134: }
135:
136: protected SchemaTypeLoader getSoapEnvelopeSchemaLoader() {
137: return soapSchema;
138: }
139:
140: public SchemaType getFaultType() {
141: return soapFaultType;
142: }
143:
144: public String getName() {
145: return "SOAP 1.1";
146: }
147: }
|