Hi,
Please apply the attached patch for SAAJ, to the axis2 codebase. The
dependency of saaj on the security module and the two SAAJ unit tests
that were failing have been fixed and added to the test suite.
--
Thanks
Afkham Azeez
Index: modules/core/src/org/apache/axis2/client/MEPClient.java
===================================================================
--- modules/core/src/org/apache/axis2/client/MEPClient.java (revision 365816)
+++ modules/core/src/org/apache/axis2/client/MEPClient.java (working copy)
@@ -91,7 +91,7 @@
*/
public void addSOAPHeader(QName soapHeaderQName, String soapHeaderText) {
OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement(soapHeaderQName,
- null);
+ null);
omElement.setText(soapHeaderText);
@@ -104,7 +104,7 @@
protected void addUserAddedSOAPHeaders(MessageContext msgCtx, Options options) {
if ((soapHeaderList != null) && (soapHeaderList.size() > 0)
- && (msgCtx.getEnvelope() != null)) {
+ && (msgCtx.getEnvelope() != null)) {
SOAPFactory soapFactory;
SOAPHeader header = msgCtx.getEnvelope().getHeader();
@@ -145,7 +145,7 @@
configurationContext.getAxisConfiguration().addService(axisService);
serviceContext = new ServiceGroupContext(configurationContext,
- axisService.getParent()).getServiceContext(axisService);
+ axisService.getParent()).getServiceContext(axisService);
}
/**
@@ -170,22 +170,23 @@
if (clientOptions == null) {
throw new AxisFault(
"Can not proceed without options being set for invocation. Set the"
- + "properties for this invocation via MEPClient.setOptions(Options) first.");
+ + "properties for this invocation via MEPClient.setOptions(Options) first.");
}
String soapVersionURI = clientOptions.getSoapVersionURI();
- String soapFactory = clientOptions.getSoapFactory();
+ String soapFactory =
+ (String) clientOptions.getProperty(OMAbstractFactory.SOAP_FACTORY_NAME_PROPERTY);
if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
String factory = (String) clientOptions.getProperty(OMAbstractFactory.SOAP12_FACTORY_NAME_PROPERTY);
- if(factory != null) {
+ if (factory != null) {
return OMAbstractFactory.getSOAPFactory(soapFactory).getDefaultEnvelope();
} else {
return OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
}
} else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
String factory = (String) clientOptions.getProperty(OMAbstractFactory.SOAP11_FACTORY_NAME_PROPERTY);
- if(factory != null) {
+ if (factory != null) {
return OMAbstractFactory.getSOAPFactory(soapFactory).getDefaultEnvelope();
} else {
return OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
@@ -263,10 +264,10 @@
// we have a deprecated method for user to set the transport
// protocol directly. Lets support that also
- String senderTransportProtocol = clientOptions.getSenderTransportProtocol();
+ String senderTrasportProtocol = clientOptions.getSenderTransportProtocol();
if (axisConfig != null) {
- if ((senderTransportProtocol == null) || "".equals(senderTransportProtocol)) {
+ if ((senderTrasportProtocol == null) || "".equals(senderTrasportProtocol)) {
// by this time we have passed all the information we
// collected via Options to the message context
@@ -276,13 +277,13 @@
// if he has not set the transport information, we gonna
// infer that from the to EPR
clientOptions.setSenderTransport(
- axisConfig.getTransportOut(new QName(senderTransportProtocol)));
+ axisConfig.getTransportOut(new QName(senderTrasportProtocol)));
}
}
if (this.clientOptions.getSenderTransport() == null) {
throw new AxisFault(Messages.getMessage("unknownTransport",
- senderTransportProtocol));
+ senderTrasportProtocol));
}
}
}
@@ -299,10 +300,10 @@
// I should check that is
// available either from the message context or from the options.
if (((msgCtx == null) || (msgCtx.getTo() == null))
- && ((clientOptions == null) || (clientOptions.getTo() == null))) {
+ && ((clientOptions == null) || (clientOptions.getTo() == null))) {
throw new AxisFault(
"Can not proceed without options being set for invocation. Set the"
- + "properties for this invocation via MEPClient.setOptions(Options) first.");
+ + "properties for this invocation via MEPClient.setOptions(Options) first.");
}
if (axisop == null) {
@@ -312,7 +313,7 @@
// make sure operation is type right MEP
if (mep.equals(axisop.getMessageExchangePattern())) {
throw new AxisFault(Messages.getMessage("mepClientSupportOnly", mep,
- axisop.getMessageExchangePattern()));
+ axisop.getMessageExchangePattern()));
}
// if operation not alrady added, add it
Index: modules/core/src/org/apache/axis2/client/Options.java
===================================================================
--- modules/core/src/org/apache/axis2/client/Options.java (revision 365816)
+++ modules/core/src/org/apache/axis2/client/Options.java (working copy)
@@ -236,14 +236,6 @@
: soapVersionURI;
}
- public String getSoapFactory() {
- if (soapFactory == null && parent != null) {
- soapFactory = parent.getSoapFactory();
- }
-
- return soapFactory == null ? "" : soapFactory;
- }
-
/**
* Gets the wait time after which a client times out in a blocking scenario.
* The default is Options#DEFAULT_TIMEOUT_MILLISECONDS
Index: modules/xml/src/org/apache/axis2/om/OMAbstractFactory.java
===================================================================
--- modules/xml/src/org/apache/axis2/om/OMAbstractFactory.java (revision 365816)
+++ modules/xml/src/org/apache/axis2/om/OMAbstractFactory.java (working copy)
@@ -23,6 +23,7 @@
public static final String OM_FACTORY_NAME_PROPERTY = "om.factory";
public static final String SOAP11_FACTORY_NAME_PROPERTY = "soap11.factory";
public static final String SOAP12_FACTORY_NAME_PROPERTY = "soap12.factory";
+ public static final String SOAP_FACTORY_NAME_PROPERTY = "soap.factory";
/**
* Eran Chinthaka ([EMAIL PROTECTED])
*/
Index: modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java
===================================================================
--- modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java (revision 365816)
+++ modules/saaj/test/org/apache/axis2/saaj/SOAPFaultDetailTest.java (working copy)
@@ -57,15 +57,4 @@
}
assertTrue(d != null);
}
-
- /**
- * Main
- */
- public static void main(String[] args)
- throws Exception
- {
- SOAPFaultDetailTest detailTest = new SOAPFaultDetailTest("faultdetails");
- detailTest.testDetails();
- }
-
}
Index: modules/saaj/test/org/apache/axis2/saaj/SOAPFaultsTest.java
===================================================================
--- modules/saaj/test/org/apache/axis2/saaj/SOAPFaultsTest.java (revision 365816)
+++ modules/saaj/test/org/apache/axis2/saaj/SOAPFaultsTest.java (working copy)
@@ -2,42 +2,62 @@
import junit.framework.TestCase;
-import javax.xml.soap.*;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
public class SOAPFaultsTest extends TestCase {
-
- public SOAPFaultsTest(String name){
- super(name);
- }
-
- //Create SOAPFault with additional detail elements
- public void testAdditionDetail() throws Exception{
- String xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:cwmp=\"http://cwmp.com\">\n" +
- " <soapenv:Header>\n" +
- " <cwmp:ID soapenv:mustUnderstand=\"1\">HEADERID-7867678</cwmp:ID>\n" +
- " </soapenv:Header>\n" +
- " <soapenv:Body>\n" +
- " <soapenv:Fault>\n" +
- " <faultcode>soapenv:Client</faultcode>\n" +
- " <faultstring>CWMP fault</faultstring>\n" +
- " <detail>\n" +
- " <cwmp:Fault>\n" +
- " <cwmp:FaultCode>This is the fault code</cwmp:FaultCode>\n" +
- " <cwmp:FaultString>Fault Message</cwmp:FaultString>\n" +
- " </cwmp:Fault>\n" +
- " </detail>\n" +
- " </soapenv:Fault>\n" +
- " </soapenv:Body>\n" +
- "</soapenv:Envelope>";
-
+
+ public SOAPFaultsTest(String name) {
+ super(name);
+ }
+
+ public void testSOAPFaultWithDetails() throws Exception {
+ /* We are trying to generate the following SOAPFault
+
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cwmp="http://cwmp.com">
+ <soapenv:Header>
+ <cwmp:ID soapenv:mustUnderstand="1">HEADERID-7867678</cwmp:ID>
+ </soapenv:Header>
+ <soapenv:Body>
+ <soapenv:Fault>
+ <faultcode>Client</faultcode>
+ <faultstring>CWMP fault</faultstring>
+ <faultactor>http://gizmos.com/order</faultactor>
+ <detail>
+ <cwmp:Fault>
+ <cwmp:FaultCode>This is the fault code</cwmp:FaultCode>
+ <cwmp:FaultString>Fault Message</cwmp:FaultString>
+ <cwmp:Message>This is a test fault</cwmp:FaultString>
+ </cwmp:Fault>
+ </detail>
+ </soapenv:Fault>
+ </soapenv:Body>
+ </soapenv:Envelope>
+
+ */
+
MessageFactory fac = MessageFactory.newInstance();
- SOAPMessage faultMessage = fac.createMessage();
-
+
//Create the response to the message
- faultMessage = fac.createMessage();
- SOAPPart part = faultMessage.getSOAPPart();
- SOAPEnvelope envelope = part.getEnvelope();
+ SOAPMessage soapMessage = fac.createMessage();
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPHeader header = envelope.getHeader();
@@ -45,108 +65,138 @@
SOAPHeaderElement id = header.addHeaderElement(idName);
id.setMustUnderstand(true);
id.addTextNode("HEADERID-7867678");
-
+
//Create the SOAPFault object
SOAPFault fault = body.addFault();
fault.setFaultCode("Client");
fault.setFaultString("CWMP fault");
-
+ fault.setFaultActor("http://gizmos.com/order");
+
+ assertEquals("Client", fault.getFaultCode());
+ assertEquals("CWMP fault", fault.getFaultString());
+ assertEquals("http://gizmos.com/order", fault.getFaultActor());
+
//Add Fault Detail information
Detail faultDetail = fault.addDetail();
- Name cwmpFaultName = envelope.createName("Fault", "cwmp",
- "http://cwmp.com");
- DetailEntry cwmpFaultDetail =
- faultDetail.addDetailEntry(cwmpFaultName);
- SOAPElement e = cwmpFaultDetail.addChildElement("FaultCode");
-
+ Name cwmpFaultName = envelope.createName("Fault", "cwmp", "http://cwmp.com");
+ DetailEntry faultDetailEntry = faultDetail.addDetailEntry(cwmpFaultName);
+ SOAPElement e = faultDetailEntry.addChildElement("FaultCode");
+
e.addTextNode("This is the fault code");
- SOAPElement e2 = cwmpFaultDetail.addChildElement(envelope.createName("FaultString", "cwmp", "http://cwmp.com"));
+ SOAPElement e2 = faultDetailEntry.addChildElement(envelope.createName("FaultString",
+ "cwmp",
+ "http://cwmp.com"));
e2.addTextNode("Fault Message");
- faultMessage.saveChanges();
-
+
+ SOAPElement e3 = faultDetailEntry.addChildElement("Message");
+ e3.addTextNode("This is a test fault");
+
+ soapMessage.saveChanges();
+
+ // ------------------- Validate the contents -------------------------------------
+ final Detail detail = fault.getDetail();
+ final Iterator detailEntryIter = detail.getDetailEntries();
+ boolean foundFirst = false;
+ boolean foundSecond = false;
+ boolean foundThird = false;
+ while (detailEntryIter.hasNext()) {
+ final DetailEntry detailEntry = (DetailEntry) detailEntryIter.next();
+ final Iterator childElementsIter = detailEntry.getChildElements();
+ while (childElementsIter.hasNext()) {
+ final SOAPElement soapElement = (SOAPElement) childElementsIter.next();
+ if (soapElement.getTagName().equals("FaultCode") &&
+ soapElement.getValue().equals("This is the fault code")) {
+ foundFirst = true;
+ }
+ if (soapElement.getTagName().equals("FaultString") &&
+ soapElement.getValue().equals("Fault Message")) {
+ foundSecond = true;
+ }
+ if (soapElement.getTagName().equals("Message") &&
+ soapElement.getValue().equals("This is a test fault")) {
+ foundThird = true;
+ }
+ }
+ }
+ assertTrue(foundFirst && foundSecond && foundThird);
+ // ------------------------------------------------------------------------------
+
+ // Test whether the fault is being serialized properly
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- faultMessage.writeTo(baos);
- String xml2 = new String(baos.toByteArray());
- faultMessage.writeTo(System.out);
- //assertXMLEqual(xml,xml2);
- }
-
- public void testQuick() throws Exception {
- MessageFactory msgfactory = MessageFactory.newInstance();
- SOAPFactory factory = SOAPFactory.newInstance();
- SOAPMessage outputmsg = msgfactory.createMessage();
- String valueCode = "faultcode";
- String valueString = "faultString";
- SOAPFault fault = outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
- fault.setFaultCode(valueCode);
- fault.setFaultString(valueString);
- Detail d;
- d = fault.addDetail();
- d.addDetailEntry(factory.createName("Hello"));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- if (outputmsg != null) {
- if (outputmsg.saveRequired()) {
- outputmsg.saveChanges();
- }
- outputmsg.writeTo(baos);
- }
- String xml = new String(baos.toByteArray());
- assertTrue(xml.indexOf("Hello")!=-1);
- }
-
- public void testSOAPFaultSaveChanges() throws Exception {
- MessageFactory msgFactory =
- MessageFactory.newInstance();
- SOAPMessage msg = msgFactory.createMessage();
- SOAPEnvelope envelope =
- msg.getSOAPPart().getEnvelope();
- SOAPBody body = envelope.getBody();
- SOAPFault fault = body.addFault();
-
- fault.setFaultCode("Client");
- fault.setFaultString(
- "Message does not have necessary info");
- fault.setFaultActor("http://gizmos.com/order");
-
- Detail detail = fault.addDetail();
-
- Name entryName = envelope.createName("order", "PO",
- "http://gizmos.com/orders/");
- DetailEntry entry = detail.addDetailEntry(entryName);
- entry.addTextNode("quantity element does not have a value");
-
- Name entryName2 = envelope.createName("confirmation",
- "PO", "http://gizmos.com/confirm");
- DetailEntry entry2 = detail.addDetailEntry(entryName2);
- entry2.addTextNode("Incomplete address: no zip code");
-
- msg.saveChanges();
-
+ soapMessage.writeTo(baos);
+ String xml = new String(baos.toByteArray());
+
+ System.out.println(xml);
+ assertTrue(xml.indexOf("<faultcode>Client</faultcode>") != -1);
+ assertTrue(xml.indexOf("<faultstring>CWMP fault</faultstring>") != -1);
+ assertTrue(xml.indexOf("<faultactor>http://gizmos.com/order</faultactor>") != -1);
+ }
+
+ public void testQuick() throws Exception {
+ MessageFactory msgfactory = MessageFactory.newInstance();
+ SOAPFactory factory = SOAPFactory.newInstance();
+ SOAPMessage outputmsg = msgfactory.createMessage();
+ String valueCode = "faultcode";
+ String valueString = "faultString";
+ SOAPFault fault = outputmsg.getSOAPPart().getEnvelope().getBody().addFault();
+ fault.setFaultCode(valueCode);
+ fault.setFaultString(valueString);
+ Detail detail = fault.addDetail();
+ detail.addDetailEntry(factory.createName("Hello"));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ if (outputmsg.saveRequired()) {
+ outputmsg.saveChanges();
+ }
+ outputmsg.writeTo(baos);
+ String xml = new String(baos.toByteArray());
+ assertTrue(xml.indexOf("Hello") != -1);
+ }
+
+ public void testSOAPFaultSaveChanges() throws Exception {
+ MessageFactory msgFactory = MessageFactory.newInstance();
+ SOAPMessage msg = msgFactory.createMessage();
+ SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+ SOAPBody body = envelope.getBody();
+ SOAPFault fault = body.addFault();
+
+ fault.setFaultCode("Client");
+ fault.setFaultString("Message does not have necessary info");
+ fault.setFaultActor("http://gizmos.com/order");
+
+ Detail detail = fault.addDetail();
+
+ Name entryName = envelope.createName("order", "PO", "http://gizmos.com/orders/");
+ DetailEntry entry = detail.addDetailEntry(entryName);
+ entry.addTextNode("quantity element does not have a value");
+
+ Name entryName2 = envelope.createName("confirmation", "PO", "http://gizmos.com/confirm");
+ DetailEntry entry2 = detail.addDetailEntry(entryName2);
+ entry2.addTextNode("Incomplete address: no zip code");
+
+ msg.saveChanges();
+
// Now retrieve the SOAPFault object and its contents
//after checking to see that there is one
- if (body.hasFault()) {
- fault = body.getFault();
- String code = fault.getFaultCode();
- String string = fault.getFaultString();
- String actor = fault.getFaultActor();
+ assertTrue(body.hasFault());
+ fault = body.getFault();
+ String code = fault.getFaultCode();
+ String string = fault.getFaultString();
+ String actor = fault.getFaultActor();
- detail = fault.getDetail();
- if (detail != null) {
- java.util.Iterator it = detail.getDetailEntries();
- while (it.hasNext()) {
- entry = (DetailEntry) it.next();
- String value = entry.getValue();
- }
+ assertEquals("Client", code);
+ assertEquals("Message does not have necessary info", string);
+ assertEquals("http://gizmos.com/order", actor);
+
+
+ detail = fault.getDetail();
+ if (detail != null) {
+ java.util.Iterator it = detail.getDetailEntries();
+ while (it.hasNext()) {
+ entry = (DetailEntry) it.next();
+ String value = entry.getValue();
}
}
- }
-
- public static void main(String[] args) throws Exception {
- SOAPFaultsTest detailTest = new SOAPFaultsTest("TestSOAPFaults");
- detailTest.testQuick();
- detailTest.testAdditionDetail();
- detailTest.testSOAPFaultSaveChanges();
}
}
Index: modules/saaj/test/org/apache/axis2/saaj/integration/EchoService.java
===================================================================
--- modules/saaj/test/org/apache/axis2/saaj/integration/EchoService.java (revision 0)
+++ modules/saaj/test/org/apache/axis2/saaj/integration/EchoService.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.saaj.integration;
+
+import org.apache.axis2.om.OMElement;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ *
+ */
+public class EchoService {
+ public OMElement echo(OMElement element) throws XMLStreamException {
+ //Praparing the OMElement so that it can be attached to another OM Tree.
+ //First the OMElement should be completely build in case it is not fully built and still
+ //some of the xml is in the stream.
+ element.build();
+ //Secondly the OMElement should be detached from the current OMTree so that it can be attached
+ //some other OM Tree. Once detached the OmTree will remove its connections to this OMElement.
+ element.detach();
+ return element;
+ }
+}