dims 2003/01/16 15:47:29 Modified: java/src/org/apache/axis AxisFault.java Constants.java java/src/org/apache/axis/encoding DeserializationContextImpl.java java/src/org/apache/axis/i18n resource.properties java/src/org/apache/axis/message BodyBuilder.java EnvelopeBuilder.java HeaderBuilder.java MessageElement.java RPCElement.java SOAPFaultBuilder.java SOAPFaultDetailsBuilder.java SOAPHandler.java java/src/org/apache/axis/providers/java JavaProvider.java java/test/soap12 PackageTests.java TestHrefs.java Added: java/test/soap12 TestEncodingStyle.java Log: SOAP 1.2 Fixes from Andras (He still does not have sufficient Karma :-) Revision Changes Path 1.68 +5 -1 xml-axis/java/src/org/apache/axis/AxisFault.java Index: AxisFault.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisFault.java,v retrieving revision 1.67 retrieving revision 1.68 diff -u -r1.67 -r1.68 --- AxisFault.java 15 Jan 2003 23:30:40 -0000 1.67 +++ AxisFault.java 16 Jan 2003 23:47:27 -0000 1.68 @@ -661,7 +661,11 @@ */ public void output(SerializationContext context) throws Exception { - SOAPEnvelope envelope = new SOAPEnvelope(); + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + SOAPEnvelope envelope = new SOAPEnvelope(soapConstants); SOAPFault fault = new SOAPFault(this); envelope.addBodyElement(fault); 1.108 +1 -1 xml-axis/java/src/org/apache/axis/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Constants.java,v retrieving revision 1.107 retrieving revision 1.108 diff -u -r1.107 -r1.108 --- Constants.java 10 Jan 2003 16:35:27 -0000 1.107 +++ Constants.java 16 Jan 2003 23:47:27 -0000 1.108 @@ -492,7 +492,7 @@ public static final QName FAULT_SOAP12_VERSIONMISMATCH = new QName(URI_SOAP12_ENV, "VersionMismatch"); - public static final QName FAULT_SOAP12_DATAENCODINGUNKNOW = + public static final QName FAULT_SOAP12_DATAENCODINGUNKNOWN = new QName(URI_SOAP12_ENV, "DataEncodingUnknow"); public static final QName FAULT_SOAP12_SENDER = 1.73 +15 -3 xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java Index: DeserializationContextImpl.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- DeserializationContextImpl.java 11 Dec 2002 23:25:15 -0000 1.72 +++ DeserializationContextImpl.java 16 Jan 2003 23:47:28 -0000 1.73 @@ -184,11 +184,9 @@ * returns the soap constants. */ private SOAPConstants getSOAPConstants(){ - SOAPConstants constants = null; + SOAPConstants constants = Constants.DEFAULT_SOAP_VERSION; if(msgContext != null) constants = msgContext.getSOAPConstants(); - if(constants == null) - constants = SOAPConstants.SOAP11_CONSTANTS; return constants; } @@ -895,6 +893,20 @@ attributes = NullAttributes.singleton; } else { attributes = new AttributesImpl(attributes); + + SOAPConstants soapConstants = getSOAPConstants(); + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { + if (attributes.getValue(soapConstants.getAttrHref()) != null && + attributes.getValue(Constants.ATTR_ID) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noIDandHREFonSameElement"), null, null, null); + + throw new SAXException(fault); + + } + } + } SOAPHandler nextHandler = null; 1.47 +3 -0 xml-axis/java/src/org/apache/axis/i18n/resource.properties Index: resource.properties =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/resource.properties,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- resource.properties 15 Jan 2003 14:06:09 -0000 1.46 +++ resource.properties 16 Jan 2003 23:47:28 -0000 1.47 @@ -996,6 +996,9 @@ onlyOneBodyFor12=Only one body allowed for SOAP 1.2 RPC noElemAfterBody12=No element allowed after SOAP 1.2 body +noEncodingStyleAttrAppear=encodigstyle attribute must not appear in element {0} in SOAP 1.2 +noIDandHREFonSameElement=A ref attribute information item and an id attribute information item MUST NOT appear on the same element information item in SOAP 1.2 +invalidEncodingStyle=Encoding style is invalid noSparseArray=Partially transmitted and sparse arrays is not supported in SOAP 1.2 differentTypes00=Error: The input and output parameter have the same name, ''{0}'', but are defined with type ''{1}'' and also with type ''{2}''. 1.55 +23 -1 xml-axis/java/src/org/apache/axis/message/BodyBuilder.java Index: BodyBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/BodyBuilder.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- BodyBuilder.java 11 Dec 2002 22:38:20 -0000 1.54 +++ BodyBuilder.java 16 Jan 2003 23:47:28 -0000 1.55 @@ -60,6 +60,7 @@ * @author Glen Daniels ([EMAIL PROTECTED]) */ +import org.apache.axis.AxisFault; import org.apache.axis.Constants; import org.apache.axis.MessageContext; import org.apache.axis.components.logger.LogFactory; @@ -93,12 +94,33 @@ DeserializationContext context) throws SAXException { - super.startElement(namespace, localName, prefix, attributes, context); + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && + attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noEncodingStyleAttrAppear", "Body"), null, null, null); + + throw new SAXException(fault); + } + + // make a new body element if (!context.isDoneParsing()) { + if (!context.isProcessingRef()) { + if (myElement == null) { + myElement = new SOAPBody(namespace, localName, prefix, + attributes, context, envelope.getSOAPConstants()); + } + context.pushNewElement(myElement); + } envelope.setBody((SOAPBody)myElement); } } + // FIX: do we need this method ? public MessageElement makeNewElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context) { 1.32 +9 -0 xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java Index: EnvelopeBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- EnvelopeBuilder.java 7 Jan 2003 19:41:58 -0000 1.31 +++ EnvelopeBuilder.java 16 Jan 2003 23:47:28 -0000 1.32 @@ -147,6 +147,15 @@ if(context.getMessageContext() != null) context.getMessageContext().setSOAPConstants(soapConstants); + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && + attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noEncodingStyleAttrAppear", "Envelope"), null, null, null); + + throw new SAXException(fault); + } + envelope.setPrefix(prefix); envelope.setNamespaceURI(namespace); envelope.setNSMappings(context.getCurrentNSMappings()); 1.22 +17 -0 xml-axis/java/src/org/apache/axis/message/HeaderBuilder.java Index: HeaderBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/HeaderBuilder.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- HeaderBuilder.java 11 Dec 2002 22:38:20 -0000 1.21 +++ HeaderBuilder.java 16 Jan 2003 23:47:28 -0000 1.22 @@ -62,6 +62,10 @@ import org.apache.axis.components.logger.LogFactory; import org.apache.axis.encoding.DeserializationContext; +import org.apache.axis.Constants; +import org.apache.axis.utils.Messages; +import org.apache.axis.AxisFault; +import org.apache.axis.soap.SOAPConstants; import org.apache.commons.logging.Log; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -84,6 +88,19 @@ DeserializationContext context) throws SAXException { + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && + attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noEncodingStyleAttrAppear", "Header"), null, null, null); + + throw new SAXException(fault); + } + if (!context.isDoneParsing()) { if (myElement == null) { myElement = new SOAPHeader(namespace, localName, prefix, 1.142 +5 -3 xml-axis/java/src/org/apache/axis/message/MessageElement.java Index: MessageElement.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v retrieving revision 1.141 retrieving revision 1.142 diff -u -r1.141 -r1.142 --- MessageElement.java 10 Jan 2003 02:19:57 -0000 1.141 +++ MessageElement.java 16 Jan 2003 23:47:28 -0000 1.142 @@ -254,6 +254,11 @@ encodingStyle = attributes.getValue(sc.getEncodingURI(), Constants.ATTR_ENCODING_STYLE); + + // if no-encoding style was defined, we don't define as well + if (Constants.URI_SOAP12_NOENC.equals(encodingStyle)) + encodingStyle = null; + } } @@ -378,9 +383,6 @@ if (encodingStyle == null) { encodingStyle = ""; } - - if(!encodingStyle.equals("") && !Constants.isSOAP_ENC(encodingStyle)) - throw new IllegalArgumentException(Messages.getMessage("illegalArgumentException01",encodingStyle)); this.encodingStyle = encodingStyle; 1.81 +11 -2 xml-axis/java/src/org/apache/axis/message/RPCElement.java Index: RPCElement.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCElement.java,v retrieving revision 1.80 retrieving revision 1.81 diff -u -r1.80 -r1.81 --- RPCElement.java 11 Dec 2002 22:38:20 -0000 1.80 +++ RPCElement.java 16 Jan 2003 23:47:28 -0000 1.81 @@ -56,6 +56,7 @@ package org.apache.axis.message; import org.apache.axis.AxisFault; +import org.apache.axis.Constants; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.description.OperationDesc; @@ -68,6 +69,7 @@ import org.apache.axis.handlers.soap.SOAPService; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.Messages; +import org.apache.axis.soap.SOAPConstants; import org.apache.axis.wsdl.toJava.Utils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -158,6 +160,8 @@ // Figure out if we should be looking for out params or in params // (i.e. is this message a response?) Message msg = msgContext.getCurrentMessage(); + SOAPConstants soapConstants = msgContext.getSOAPConstants(); + boolean isResponse = ((msg != null) && Message.RESPONSE.equals(msg.getMessageType())); @@ -275,8 +279,13 @@ if (savedException != null) { throw savedException; } else if (!msgContext.isClient()) { - throw new SAXException( - Messages.getMessage("noSuchOperation", name)); + QName faultCode = new QName(Constants.FAULT_SERVER_USER); + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) + faultCode = Constants.FAULT_SOAP12_SENDER; + AxisFault fault = new AxisFault(faultCode, + null, Messages.getMessage("noSuchOperation", name), null, null, null); + + throw new SAXException(fault); } } 1.27 +22 -0 xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java Index: SOAPFaultBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFaultBuilder.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- SOAPFaultBuilder.java 11 Dec 2002 22:38:20 -0000 1.26 +++ SOAPFaultBuilder.java 16 Jan 2003 23:47:28 -0000 1.27 @@ -61,6 +61,7 @@ import org.apache.axis.encoding.DeserializationContext; import org.apache.axis.encoding.Deserializer; import org.apache.axis.soap.SOAPConstants; +import org.apache.axis.utils.Messages; import org.w3c.dom.Element; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -121,6 +122,27 @@ this.context = context; } + public void startElement(String namespace, String localName, + String prefix, Attributes attributes, + DeserializationContext context) + throws SAXException + { + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && + attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noEncodingStyleAttrAppear", "Fault"), null, null, null); + + throw new SAXException(fault); + } + + super.startElement(namespace, localName, prefix, attributes, context); + } + void setFaultData(Object data) { faultData = data; if (waiting && passedEnd) { 1.8 +24 -0 xml-axis/java/src/org/apache/axis/message/SOAPFaultDetailsBuilder.java Index: SOAPFaultDetailsBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPFaultDetailsBuilder.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SOAPFaultDetailsBuilder.java 20 Dec 2002 17:28:22 -0000 1.7 +++ SOAPFaultDetailsBuilder.java 16 Jan 2003 23:47:28 -0000 1.8 @@ -54,6 +54,7 @@ */ package org.apache.axis.message; +import org.apache.axis.AxisFault; import org.apache.axis.Constants; import org.apache.axis.MessageContext; import org.apache.axis.description.FaultDesc; @@ -64,6 +65,7 @@ import org.apache.axis.encoding.Deserializer; import org.apache.axis.encoding.DeserializerImpl; import org.apache.axis.utils.ClassUtils; +import org.apache.axis.utils.Messages; import org.apache.axis.soap.SOAPConstants; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -82,6 +84,28 @@ public SOAPFaultDetailsBuilder(SOAPFaultBuilder builder) { this.builder = builder; + } + + + public void startElement(String namespace, String localName, + String prefix, Attributes attributes, + DeserializationContext context) + throws SAXException + { + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && + attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { + + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, + null, Messages.getMessage("noEncodingStyleAttrAppear", "Detail"), null, null, null); + + throw new SAXException(fault); + } + + super.startElement(namespace, localName, prefix, attributes, context); } public SOAPHandler onStartChild(String namespace, 1.12 +29 -0 xml-axis/java/src/org/apache/axis/message/SOAPHandler.java Index: SOAPHandler.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPHandler.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SOAPHandler.java 4 Dec 2002 20:06:58 -0000 1.11 +++ SOAPHandler.java 16 Jan 2003 23:47:28 -0000 1.12 @@ -59,7 +59,12 @@ * @author Glen Daniels ([EMAIL PROTECTED]) */ +import org.apache.axis.AxisFault; +import org.apache.axis.Constants; import org.apache.axis.encoding.DeserializationContext; +import org.apache.axis.encoding.TypeMappingRegistry; +import org.apache.axis.soap.SOAPConstants; +import org.apache.axis.utils.Messages; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -88,6 +93,30 @@ DeserializationContext context) throws SAXException { + SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; + if (context.getMessageContext() != null) + soapConstants = context.getMessageContext().getSOAPConstants(); + + + if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { + String encodingStyle = attributes.getValue(Constants.URI_SOAP12_ENV, + Constants.ATTR_ENCODING_STYLE); + + if (encodingStyle != null && !encodingStyle.equals("") + && !encodingStyle.equals(Constants.URI_SOAP12_NOENC) + && !Constants.isSOAP_ENC(encodingStyle)) { + TypeMappingRegistry tmr = context.getTypeMappingRegistry(); + // TODO: both soap encoding style is registered ? + if (tmr.getTypeMapping(encodingStyle) == tmr.getDefaultTypeMapping()) { + AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_DATAENCODINGUNKNOWN, + null, Messages.getMessage("invalidEncodingStyle"), null, null, null); + + throw new SAXException(fault); + } + } + } + + // By default, make a new element if (!context.isDoneParsing() && !context.isProcessingRef()) { if (myElement == null) { 1.97 +9 -2 xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java Index: JavaProvider.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java,v retrieving revision 1.96 retrieving revision 1.97 diff -u -r1.96 -r1.97 --- JavaProvider.java 6 Jan 2003 18:30:07 -0000 1.96 +++ JavaProvider.java 16 Jan 2003 23:47:29 -0000 1.97 @@ -79,6 +79,8 @@ import javax.xml.rpc.holders.IntHolder; import javax.xml.rpc.server.ServiceLifecycle; +import org.xml.sax.SAXException; + import java.util.ArrayList; import java.util.StringTokenizer; @@ -326,8 +328,13 @@ SOAPEnvelope reqEnv = reqMsg.getSOAPEnvelope(); processMessage(msgContext, reqEnv, resEnv, serviceObject); - } - catch( Exception exp ) { + } catch( SAXException exp ) { + entLog.debug( Messages.getMessage("toAxisFault00"), exp); + Exception real = exp.getException(); + if (real == null) + real = exp; + throw AxisFault.makeFault(real); + } catch( Exception exp ) { entLog.debug( Messages.getMessage("toAxisFault00"), exp); throw AxisFault.makeFault(exp); } finally { 1.4 +1 -0 xml-axis/java/test/soap12/PackageTests.java Index: PackageTests.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/soap12/PackageTests.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PackageTests.java 7 Jan 2003 21:29:07 -0000 1.3 +++ PackageTests.java 16 Jan 2003 23:47:29 -0000 1.4 @@ -76,6 +76,7 @@ suite.addTestSuite(TestHrefs.class); suite.addTestSuite(TestRPC.class); suite.addTestSuite(TestVersionMismatch.class); + suite.addTestSuite(TestEncodingStyle.class); return suite; } } 1.2 +19 -0 xml-axis/java/test/soap12/TestHrefs.java Index: TestHrefs.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/soap12/TestHrefs.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestHrefs.java 20 Dec 2002 17:28:21 -0000 1.1 +++ TestHrefs.java 16 Jan 2003 23:47:29 -0000 1.2 @@ -1,6 +1,7 @@ package test.soap12; import junit.framework.TestCase; +import org.apache.axis.AxisFault; import org.apache.axis.Constants; import org.apache.axis.Message; import org.apache.axis.MessageContext; @@ -8,6 +9,7 @@ import org.apache.axis.message.RPCParam; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.server.AxisServer; +import org.apache.axis.utils.Messages; import java.util.Vector; @@ -94,5 +96,22 @@ BODYT; deserialize(result, "abc", 0); } + + public void testIDANDHREF() throws Exception { + String result = HEAD + + HEADERT + + "<result root=\"0\" ref=\"#1\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" + + BODYT; + try { + deserialize(result, "abc", 0); + } catch (AxisFault af) { + assertTrue(af.getFaultString().indexOf(Messages.getMessage("noIDandHREFonSameElement")) != -1 && + Constants.FAULT_SOAP12_SENDER.equals(af.getFaultCode())); + return; + } + fail("Didn't got the expected fault"); + + } + } 1.1 xml-axis/java/test/soap12/TestEncodingStyle.java Index: TestEncodingStyle.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ /** * @author Andras Avar ([EMAIL PROTECTED]) */ package test.soap12; import junit.framework.TestCase; import org.apache.axis.AxisFault; import org.apache.axis.Constants; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.encoding.TypeMapping; import org.apache.axis.encoding.TypeMappingRegistry; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.server.AxisServer; import org.apache.axis.soap.SOAPConstants; import org.apache.axis.utils.Messages; import javax.xml.namespace.QName; /** * Test encodingstyle attribute appearance */ public class TestEncodingStyle extends TestCase { private AxisServer server = null; public TestEncodingStyle(String name) { super(name); server = new AxisServer(); } private final String ENVELOPE = "<?xml version=\"1.0\"?>\n" + "<soap:Envelope " + "xmlns:soap=\"" + Constants.URI_SOAP12_ENV + "\" " + "xmlns:xsi=\"" + Constants.URI_DEFAULT_SCHEMA_XSI + "\" " + "xmlns:xsd=\"" + Constants.URI_DEFAULT_SCHEMA_XSD + "\" "; private final String HEADER = ">\n" + "<soap:Header "; private final String BODY = "/>\n" + "<soap:Body "; private final String FAULT_HEAD = ">\n" + "<soap:Fault "; private final String FAULT_DETAIL = ">\n" + "<soap:Code>" + "<soap:Value>soap:Sender</soap:Value>" + "</soap:Code>" + "<soap:Detail "; private final String FAULT_TAIL = ">\n" + "<hello/>" + "</soap:Detail>" + "</soap:Fault>"; private final String TAIL = "</soap:Body>\n" + "</soap:Envelope>\n"; private final String ENCSTYLE_DEF = "soap:encodingStyle=\"" + Constants.URI_SOAP12_ENC + "\""; private final String MESSAGE_HEAD = ">\n" + "<methodResult xmlns=\"http://tempuri.org/\" "; private final String MESSAGE = ">\n"; private final String MESSAGE_TAIL = "</methodResult>\n"; private final String ITEM = "<item xsi:type=\"xsd:string\">abc</item>\n"; private final String INVALID_ENCSTYLE = "http://invalidencodingstyle.org"; private final String NO_ENCSTYLE = Constants.URI_SOAP12_NOENC; private final String INVALID_ENCSTYLE_DEF = "soap:encodingStyle=\"" + INVALID_ENCSTYLE + "\""; private final String NO_ENCSTYLE_DEF = "soap:encodingStyle=\"" + NO_ENCSTYLE + "\""; public boolean deserialize(String req, QName expected_code, String expected_str) throws Exception { Message message = new Message(req); MessageContext context = new MessageContext(server); context.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS); message.setMessageContext(context); boolean expectedFault = false; try { SOAPEnvelope envelope = message.getSOAPEnvelope(); } catch (AxisFault af) { expectedFault = true; return af.getFaultString().indexOf(expected_str) != -1 && expected_code.equals(af.getFaultCode()); } return expectedFault; } public void testEncStyleInEnvelope() throws Exception { String req = ENVELOPE + ENCSTYLE_DEF + HEADER + BODY + FAULT_HEAD + FAULT_DETAIL + FAULT_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_SENDER, Messages.getMessage("noEncodingStyleAttrAppear", "Envelope"))); } public void testEncStyleInHeader() throws Exception { String req = ENVELOPE + HEADER + ENCSTYLE_DEF + BODY + FAULT_HEAD + FAULT_DETAIL + FAULT_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_SENDER, Messages.getMessage("noEncodingStyleAttrAppear", "Header"))); } public void testEncStyleInBody() throws Exception { String req = ENVELOPE + HEADER + BODY + ENCSTYLE_DEF + FAULT_HEAD + FAULT_DETAIL + FAULT_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_SENDER, Messages.getMessage("noEncodingStyleAttrAppear", "Body"))); } public void testEncStyleInFault() throws Exception { String req = ENVELOPE + HEADER + BODY + FAULT_HEAD + ENCSTYLE_DEF + FAULT_DETAIL + FAULT_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_SENDER, Messages.getMessage("noEncodingStyleAttrAppear", "Fault"))); } public void testEncStyleInDetail() throws Exception { String req = ENVELOPE + HEADER + BODY + FAULT_HEAD + FAULT_DETAIL + ENCSTYLE_DEF + FAULT_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_SENDER, Messages.getMessage("noEncodingStyleAttrAppear", "Detail"))); } public void testInvalidEncodingStyle() throws Exception { String req = ENVELOPE + HEADER + BODY + MESSAGE_HEAD + INVALID_ENCSTYLE_DEF + MESSAGE + ITEM + MESSAGE_TAIL + TAIL; assertTrue(deserialize(req, Constants.FAULT_SOAP12_DATAENCODINGUNKNOWN, Messages.getMessage("invalidEncodingStyle"))); } public void testAcceptUserEncodingStyle() throws Exception { String req = ENVELOPE + HEADER + BODY + MESSAGE_HEAD + INVALID_ENCSTYLE_DEF + MESSAGE + ITEM + MESSAGE_TAIL + TAIL; Message message = new Message(req); MessageContext context = new MessageContext(server); // Set the "invalid" encoding style TypeMappingRegistry reg = context.getTypeMappingRegistry(); TypeMapping tm = (TypeMapping) reg.createTypeMapping(); tm.setSupportedEncodings(new String[] { INVALID_ENCSTYLE }); reg.register(INVALID_ENCSTYLE, tm); context.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS); message.setMessageContext(context); SOAPEnvelope envelope = message.getSOAPEnvelope(); assertTrue(envelope != null); } public void testNoEncodingStyle() throws Exception { String req = ENVELOPE + HEADER + BODY + MESSAGE_HEAD + NO_ENCSTYLE_DEF + MESSAGE + ITEM + MESSAGE_TAIL + TAIL; assertTrue(deserialize(req, null, null) == false); } }