You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/03/21 10:11:39 UTC
svn commit: r158421 - in webservices/axis/trunk/java/modules:
core/src/java/org/apache/axis/handlers/addressing/
core/src/test/org/apache/axis/handlers/
core/src/test/org/apache/axis/handlers/addressing/
core/src/test/org/apache/axis/handlers/util/
om/src/java/org/apache/axis/om/impl/llom/builder/
om/src/java/org/apache/axis/om/impl/llom/exception/
om/src/java/org/apache/axis/om/impl/llom/util/
om/src/test/org/apache/axis/om/util/
Author: chinthaka
Date: Mon Mar 21 01:11:36 2005
New Revision: 158421
URL: http://svn.apache.org/viewcvs?view=rev&rev=158421
Log:
Adding Addressing Handlers, tests.
Adding a basic element comparator with OM.
Added:
webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/
webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingInHandler.java
webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingOutHandler.java
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingInHandlerTest.java
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingOutHandlerTest.java
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/
webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/TestUtil.java
webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/exception/XMLComparisonException.java
webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/
webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/XMLComparator.java
Modified:
webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/StAXSOAPModelBuilder.java
webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
Added: webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingInHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingInHandler.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingInHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingInHandler.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,109 @@
+package org.apache.axis.handlers.addressing;
+
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.addressing.miheaders.RelatesTo;
+import org.apache.axis.addressing.om.MessageInformationHeadersCollection;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.handlers.AbstractHandler;
+import org.apache.axis.om.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class AddressingInHandler extends AbstractHandler {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org) Date : 03-04-2005 Time : 14:42
+ */
+ private Log logger = LogFactory.getLog(getClass());
+
+
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ logger.debug("Starting Addressing IN Handler .........");
+ SOAPHeader header = msgContext.getEnvelope().getHeader();
+ OMNamespace addressingNamespace = header.findInScopeNamespace(AddressingConstants.WSA_NAMESPACE, "");
+ if (addressingNamespace != null) {
+ extractAddressingInformationFromHeaders(header, msgContext.getMessageInformationHeaders());
+ } else {
+ // no addressing headers present
+ logger.debug("No Addressing Headers present in the IN message. Addressing In Handler does nothing.");
+ }
+ }
+
+ protected MessageInformationHeadersCollection extractAddressingInformationFromHeaders(SOAPHeader header, MessageInformationHeadersCollection messageInformationHeadersCollection) {
+ if(messageInformationHeadersCollection == null){
+ messageInformationHeadersCollection = new MessageInformationHeadersCollection();
+ }
+
+ Iterator addressingHeaders = header.getChildrenWithName(new QName(AddressingConstants.WSA_NAMESPACE, ""));
+ while (addressingHeaders.hasNext()) {
+ SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) addressingHeaders.next();
+ EndpointReference epr = null;
+ if (AddressingConstants.WSA_TO.equals(soapHeaderBlock.getLocalName())) {
+ if(messageInformationHeadersCollection.getTo() == null){
+ epr = new EndpointReference(AddressingConstants.WSA_TO, "");
+ messageInformationHeadersCollection.setTo(epr);
+ }
+ extractEPRInformation(soapHeaderBlock, epr);
+ } else if (AddressingConstants.WSA_FROM.equals(soapHeaderBlock.getLocalName())) {
+ if(messageInformationHeadersCollection.getFrom() == null){
+ epr = new EndpointReference(AddressingConstants.WSA_FROM, "");
+ messageInformationHeadersCollection.setFrom(epr);
+ }
+ extractEPRInformation(soapHeaderBlock, epr);
+ } else if (AddressingConstants.WSA_REPLY_TO.equals(soapHeaderBlock.getLocalName())) {
+ if(messageInformationHeadersCollection.getReplyTo() == null){
+ epr = new EndpointReference(AddressingConstants.WSA_REPLY_TO, "");
+ messageInformationHeadersCollection.setReplyTo(epr);
+ }
+ extractEPRInformation(soapHeaderBlock, epr);
+ } else if (AddressingConstants.WSA_FAULT_TO.equals(soapHeaderBlock.getLocalName())) {
+ if(messageInformationHeadersCollection.getFaultTo() == null){
+ epr = new EndpointReference(AddressingConstants.WSA_FAULT_TO, "");
+ messageInformationHeadersCollection.setTo(epr);
+ }
+ extractEPRInformation(soapHeaderBlock, epr);
+ } else if (AddressingConstants.WSA_MESSAGE_ID.equals(soapHeaderBlock.getLocalName())) {
+ messageInformationHeadersCollection.setMessageId(soapHeaderBlock.getText());
+ } else if (AddressingConstants.WSA_ACTION.equals(soapHeaderBlock.getLocalName())) {
+ messageInformationHeadersCollection.setAction(soapHeaderBlock.getText());
+ } else if (AddressingConstants.WSA_RELATES_TO.equals(soapHeaderBlock.getLocalName())) {
+ String address = soapHeaderBlock.getText();
+ OMAttribute relationshipType = soapHeaderBlock.getAttributeWithQName(new QName(AddressingConstants.WSA_NAMESPACE, AddressingConstants.WSA_RELATES_TO_RELATIONSHIP_TYPE));
+ RelatesTo relatesTo = new RelatesTo(address, relationshipType == null ? "wsa:Reply" : relationshipType.getValue());
+ messageInformationHeadersCollection.setRelatesTo(relatesTo);
+ }
+ }
+
+ return messageInformationHeadersCollection;
+ }
+
+
+ private void extractEPRInformation(SOAPHeaderBlock headerBlock, EndpointReference epr) {
+ OMElement address = (OMElement) headerBlock.getChildWithName(new QName(AddressingConstants.WSA_NAMESPACE, AddressingConstants.EPR_ADDRESS));
+ if (address != null) {
+ epr.setAddress(address.getText());
+ }
+
+
+ }
+}
Added: webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingOutHandler.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingOutHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/handlers/addressing/AddressingOutHandler.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,121 @@
+package org.apache.axis.handlers.addressing;
+
+import org.apache.axis.handlers.AbstractHandler;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.addressing.om.MessageInformationHeadersCollection;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.ServiceName;
+import org.apache.axis.addressing.AnyContentType;
+import org.apache.axis.addressing.miheaders.RelatesTo;
+import org.apache.axis.om.*;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class AddressingOutHandler extends AbstractHandler implements AddressingConstants{
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+ OMNamespace addressingNamespace = OMFactory.newInstance().createOMNamespace(WSA_NAMESPACE, "wsa");
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ MessageInformationHeadersCollection messageInformationHeaders = msgContext.getMessageInformationHeaders();
+ SOAPHeader soapHeader = msgContext.getEnvelope().getHeader();
+
+ EndpointReference epr = messageInformationHeaders.getTo();
+ addToSOAPHeader(epr, AddressingConstants.WSA_TO, soapHeader);
+ epr = messageInformationHeaders.getReplyTo();
+ addToSOAPHeader(epr, AddressingConstants.WSA_REPLY_TO, soapHeader);
+ epr = messageInformationHeaders.getFrom();
+ addToSOAPHeader(epr, AddressingConstants.WSA_FROM, soapHeader);
+ epr = messageInformationHeaders.getFaultTo();
+ addToSOAPHeader(epr, AddressingConstants.WSA_FAULT_TO, soapHeader);
+
+ String messageID = messageInformationHeaders.getMessageId();
+ processStringInfo(messageID, WSA_MESSAGE_ID, soapHeader);
+
+ String action = messageInformationHeaders.getAction();
+ processStringInfo(action, WSA_ACTION, soapHeader);
+
+ RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
+ OMElement relatesToHeader = processStringInfo(relatesTo.getAddress(), WSA_RELATES_TO, soapHeader);
+ if(relatesToHeader != null && !"".equals(relatesTo.getRelationshipType())){
+ relatesToHeader.insertAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE, relatesTo.getRelationshipType(), addressingNamespace);
+ }
+ soapHeader.addChild(relatesToHeader);
+
+ }
+
+ private OMElement processStringInfo(String value, String type, SOAPHeader soapHeader) {
+ if(!"".equals(value) && value != null){
+ SOAPHeaderBlock soapHeaderBlock = soapHeader.addHeaderBlock(type, addressingNamespace);
+ soapHeaderBlock.addChild(OMFactory.newInstance().createText(value));
+ return soapHeaderBlock;
+ }
+ return null;
+ }
+
+ protected void addToSOAPHeader(EndpointReference epr, String type, SOAPHeader soapHeader) {
+ if(epr == null){
+ return;
+ }
+ String address = epr.getAddress();
+ if(!"".equals(address) && address != null){
+ SOAPHeaderBlock soapHeaderBlock = soapHeader.addHeaderBlock(type, addressingNamespace);
+ OMElement addressElement = OMFactory.newInstance().createOMElement(EPR_ADDRESS, addressingNamespace);
+ soapHeaderBlock.addChild(addressElement);
+ addressElement.setValue(address);
+
+ }
+
+ QName portType = epr.getPortType();
+ if(portType != null){
+ SOAPHeaderBlock soapHeaderBlock = soapHeader.addHeaderBlock(EPR_PORT_TYPE, addressingNamespace);
+ soapHeaderBlock.addChild(OMFactory.newInstance().createText(portType.getPrefix() + ":" + portType.getLocalPart()));
+ }
+
+ ServiceName serviceName = epr.getServiceName();
+ if(serviceName != null){
+ SOAPHeaderBlock soapHeaderBlock = soapHeader.addHeaderBlock(EPR_SERVICE_NAME, addressingNamespace);
+ soapHeaderBlock.insertAttribute(EPR_SERVICE_NAME_PORT_NAME, serviceName.getPortName(), addressingNamespace);
+ soapHeaderBlock.addChild(OMFactory.newInstance().createText(serviceName.getName().getPrefix() + ":" + serviceName.getName().getLocalPart()));
+ }
+
+ AnyContentType referenceParameters = epr.getReferenceParameters();
+ processAnyContentType(referenceParameters, soapHeader);
+
+ AnyContentType referenceProperties = epr.getReferenceProperties();
+ processAnyContentType(referenceProperties, soapHeader);
+
+ }
+
+ private void processAnyContentType(AnyContentType referenceParameters, SOAPHeader soapHeader) {
+ if(referenceParameters != null ){
+ Iterator iterator = referenceParameters.getKeys();
+ while (iterator.hasNext()) {
+ QName key = (QName) iterator.next();
+ String value = referenceParameters.getReferenceValue(key);
+ OMElement omElement = OMFactory.newInstance().createOMElement(key, soapHeader);
+ soapHeader.addChild(omElement);
+ omElement.addChild(OMFactory.newInstance().createText(value));
+ }
+ }
+ }
+}
Added: webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingInHandlerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingInHandlerTest.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingInHandlerTest.java (added)
+++ webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingInHandlerTest.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,79 @@
+package org.apache.axis.handlers.addressing;
+
+import org.apache.axis.AbstractTestCase;
+import org.apache.axis.addressing.om.MessageInformationHeadersCollection;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.handlers.util.TestUtil;
+import org.apache.axis.om.SOAPEnvelope;
+import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class AddressingInHandlerTest extends AbstractTestCase {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+
+ AddressingInHandler inHandler;
+ TestUtil testUtil = new TestUtil();
+ private static final String testFileName = "soapmessage.xml";
+
+ private String action = "http://ws.apache.org/tests/action";
+ private String messageID = "uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5";
+ private String fromAddress = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous";
+
+ /**
+ * @param testName
+ */
+ public AddressingInHandlerTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ inHandler = new AddressingInHandler();
+ }
+
+
+ public void testExtractAddressingInformationFromHeaders() {
+ try {
+ StAXSOAPModelBuilder omBuilder = testUtil.getOMBuilder(testFileName);
+ MessageInformationHeadersCollection messageInformationHeadersCollection =
+ inHandler.extractAddressingInformationFromHeaders(((SOAPEnvelope) omBuilder.getDocumentElement()).getHeader(), null);
+
+ if(messageInformationHeadersCollection == null){
+ fail("Addressing Information Headers have not been retrieved properly");
+ }
+ assertEquals("action header is not correct", messageInformationHeadersCollection.getAction(), action);
+ assertEquals("action header is not correct", messageInformationHeadersCollection.getMessageId(), messageID);
+
+ assertFromEPR(messageInformationHeadersCollection.getFrom());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(" An Exception has occured " + e.getMessage());
+ }
+ }
+
+ private void assertFromEPR(EndpointReference fromEPR){
+ assertEquals("Address in EPR is not valid", fromEPR.getAddress(), fromAddress);
+ }
+
+
+
+
+}
Added: webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingOutHandlerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingOutHandlerTest.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingOutHandlerTest.java (added)
+++ webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/addressing/AddressingOutHandlerTest.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,122 @@
+package org.apache.axis.handlers.addressing;
+
+import org.apache.axis.AbstractTestCase;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.handlers.util.TestUtil;
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.AnyContentType;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.addressing.ServiceName;
+import org.apache.axis.addressing.miheaders.RelatesTo;
+import org.apache.axis.addressing.om.MessageInformationHeadersCollection;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.SOAPEnvelope;
+import org.apache.axis.om.impl.llom.util.XMLComparator;
+import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis.om.impl.llom.util.XMLComparator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class AddressingOutHandlerTest extends AbstractTestCase implements AddressingConstants {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+ private AddressingOutHandler outHandler;
+ private MessageContext msgCtxt;
+ private TestUtil testUtil;
+
+ public AddressingOutHandlerTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ outHandler = new AddressingOutHandler();
+ testUtil = new TestUtil();
+ msgCtxt = new MessageContext(null, null, null, null);
+ }
+
+ public void testAddToSOAPHeader() throws Exception {
+ EndpointReference epr = new EndpointReference(WSA_FROM, "http://www.from.org/service/");
+ epr.setPortType(new QName("http://www.from.org/service/port/", "Port", "portNS"));
+ epr.setServiceName(new ServiceName(new QName("http://www.from.org/service/", "Service", "serviceNS"), "port"));
+
+ AnyContentType anyContentType = new AnyContentType();
+ for (int i = 0; i < 5; i++) {
+ anyContentType.addReferenceValue(new QName("Reference" + i), "Value " + i * 100);
+
+ }
+
+ epr.setReferenceParameters(anyContentType);
+ SOAPEnvelope defaultEnvelope = OMFactory.newInstance().getDefaultEnvelope();
+
+ defaultEnvelope.getHeader().declareNamespace(WSA_NAMESPACE, "wsa");
+ outHandler.addToSOAPHeader(epr, WSA_FROM, defaultEnvelope.getHeader());
+
+ StAXSOAPModelBuilder omBuilder = testUtil.getOMBuilder("eprTest.xml");
+ XMLComparator xmlComparator = new XMLComparator();
+ assertTrue(xmlComparator.compare(omBuilder.getDocumentElement(), defaultEnvelope));
+ }
+
+// public void testHeaderCreationFromMsgCtxtInformation() throws Exception {
+// MessageInformationHeadersCollection mIHeaders = new MessageInformationHeadersCollection();
+//
+// AnyContentType referenceValues = new AnyContentType();
+//
+// EndpointReference epr = new EndpointReference(WSA_FROM, "http://www.from.org/service/");
+// referenceValues.addReferenceValue(new QName("Reference2"), "Value 200");
+// epr.setReferenceParameters(referenceValues);
+// mIHeaders.setFrom(epr);
+//
+// epr = new EndpointReference(WSA_TO, "http://www.to.org/service/");
+// referenceValues = new AnyContentType();
+// referenceValues.addReferenceValue(new QName("Reference1"), "Value 100");
+// epr.setReferenceProperties(referenceValues);
+// epr.setServiceName(new ServiceName(new QName("http://www.from.org/service/", "Service", "serviceNS"), "port"));
+// mIHeaders.setTo(epr);
+//
+// epr = new EndpointReference(WSA_REPLY_TO, "http://www.replyTo.org/service/");
+// referenceValues = new AnyContentType();
+// referenceValues.addReferenceValue(new QName("Reference3"), "Value 300");
+// epr.setPortType(new QName("http://www.from.org/service/port/", "Port", "portNS"));
+// epr.setReferenceProperties(referenceValues);
+//
+// referenceValues = new AnyContentType();
+// referenceValues.addReferenceValue(new QName("Reference4"), "Value 400");
+// epr.setReferenceParameters(referenceValues);
+// mIHeaders.setTo(epr);
+//
+// mIHeaders.setMessageId("123456-7890");
+// mIHeaders.setAction("http://www.actions.org/action");
+//
+// RelatesTo relatesTo = new RelatesTo("http://www.relatesTo.org/service/", "TestRelation");
+// mIHeaders.setRelatesTo(relatesTo);
+//
+// msgCtxt.setMessageInformationHeaders(mIHeaders);
+// msgCtxt.setEnvelope(OMFactory.newInstance().getDefaultEnvelope());
+// outHandler.invoke(msgCtxt);
+//
+// XMLComparator xmlComparator = new XMLComparator();
+// assertTrue(xmlComparator.compare(msgCtxt.getEnvelope(), testUtil.getOMBuilder("OutHandlerTest.xml").getDocumentElement()));
+// }
+}
Added: webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/TestUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/TestUtil.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/TestUtil.java (added)
+++ webservices/axis/trunk/java/modules/core/src/test/org/apache/axis/handlers/util/TestUtil.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,50 @@
+package org.apache.axis.handlers.util;
+
+import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis.om.OMFactory;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.FileReader;
+import java.io.File;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class TestUtil{
+
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+
+ protected static final String IN_FILE_NAME = "soapmessage.xml";
+ protected StAXSOAPModelBuilder builder;
+ protected String testResourceDir = "src" + File.separator + "test-resources";
+
+
+ public StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {
+ if (fileName == "" || fileName == null) {
+ fileName = IN_FILE_NAME;
+ }
+ XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader(getTestResourceFile(fileName)));
+ builder = new StAXSOAPModelBuilder(OMFactory.newInstance(), parser);
+ return builder;
+ }
+
+ protected File getTestResourceFile(String relativePath) {
+ return new File(testResourceDir, relativePath);
+ }
+}
Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/StAXSOAPModelBuilder.java?view=diff&r1=158420&r2=158421
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/StAXSOAPModelBuilder.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/builder/StAXSOAPModelBuilder.java Mon Mar 21 01:11:36 2005
@@ -127,7 +127,7 @@
private OMElement constructNode(OMElement parent, String elementName,
boolean isEnvelope) {
OMElement element = null;
- if (isEnvelope) {
+ if (parent == null) {
if (!elementName.equalsIgnoreCase(OMConstants.SOAPENVELOPE_LOCAL_NAME)) {
throw new OMException("First Element must contain the local name, "
+ OMConstants.SOAPENVELOPE_LOCAL_NAME);
Added: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/exception/XMLComparisonException.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/exception/XMLComparisonException.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/exception/XMLComparisonException.java (added)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/exception/XMLComparisonException.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,35 @@
+package org.apache.axis.om.impl.llom.exception;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class XMLComparisonException extends Exception {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+
+ public XMLComparisonException(String message) {
+ super(message);
+ }
+
+ public XMLComparisonException(Throwable cause) {
+ super(cause);
+ }
+
+ public XMLComparisonException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/XMLComparator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/XMLComparator.java?view=auto&rev=158421
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/XMLComparator.java (added)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/util/XMLComparator.java Mon Mar 21 01:11:36 2005
@@ -0,0 +1,142 @@
+package org.apache.axis.om.impl.llom.util;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.impl.llom.exception.XMLComparisonException;
+import org.apache.axis.om.impl.llom.exception.XMLComparisonException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class XMLComparator {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+ private Log log = LogFactory.getLog(getClass());
+
+
+ public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ if(elementOne == null && elementTwo == null){
+ log.info("Both Elements are null.");
+ return true;
+ }
+ if(elementOne == null && elementTwo != null){
+ throw new XMLComparisonException("Element One is null and Element Two is not null");
+ }
+ if(elementOne != null && elementTwo == null){
+ throw new XMLComparisonException("Element Two is null and Element One is not null");
+ }
+
+ log.info("Now Checking "+ elementOne.getLocalName() + " and " + elementTwo.getLocalName() + "=============================");
+
+ log.info("Comparing Element Names .......");
+ compare("Elements names are not equal. ", elementOne.getLocalName(), elementTwo.getLocalName());
+
+ log.info("Comparing Namespaces .........");
+ compare("Element namespaces are not equal", elementOne.getNamespace(), elementTwo.getNamespace());
+
+ log.info("Comparing attributes .....");
+ compareAllAttributes(elementOne, elementTwo);
+
+ log.info("Comparing texts .....");
+ compare("Elements texts are not equal ", elementOne.getText(), elementTwo.getText());
+
+ log.info("Comparing Children ......");
+ compareAllChildren(elementOne, elementTwo);
+
+
+ return true;
+ }
+
+ private void compareAllAttributes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ compareAttibutes(elementOne, elementTwo);
+ compareAttibutes(elementTwo, elementOne);
+ }
+
+ private void compareAllChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ compareChildren(elementOne, elementTwo);
+ compareChildren(elementTwo, elementOne);
+ }
+
+ private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ Iterator elementOneChildren = elementOne.getChildren();
+ while (elementOneChildren.hasNext()) {
+ OMNode omNode = (OMNode) elementOneChildren.next();
+ if(omNode instanceof OMElement){
+ OMElement elementOneChild = (OMElement) omNode;
+ OMNode elementTwoChild = elementTwo.getChildWithName(elementOneChild.getQName());
+ if(elementTwoChild == null){
+ throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName() + " element under " + elementTwo.getLocalName());
+ }
+ compare(elementOneChild, (OMElement) elementTwoChild);
+ }
+ }
+ }
+
+
+ private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ int elementOneAtribCount = 0;
+ int elementTwoAtribCount = 0;
+ Iterator attributes = elementOne.getAttributes();
+ while (attributes.hasNext()) {
+ OMAttribute omAttribute = (OMAttribute) attributes.next();
+ OMAttribute attr = elementTwo.getAttributeWithQName(omAttribute.getQName());
+ if(attr == null){
+ throw new XMLComparisonException("Attributes are not the same in two elements. Attribute "+ omAttribute.getLocalName() + " != ");
+ }
+ elementOneAtribCount++;
+ }
+
+ Iterator elementTwoIter = elementTwo.getAttributes();
+ while (elementTwoIter.hasNext()) {
+ elementTwoIter.next();
+ elementTwoAtribCount++;
+
+ }
+
+ if(elementOneAtribCount != elementTwoAtribCount){
+ throw new XMLComparisonException("Attributes are not the same in two elements.");
+ }
+ }
+
+ private void compare(String failureNotice, String one, String two) throws XMLComparisonException {
+ if(!one.equals(two)){
+ throw new XMLComparisonException(failureNotice+ one + " != " + two);
+ }
+ }
+
+ private void compare(String failureNotice, OMNamespace one, OMNamespace two) throws XMLComparisonException {
+ if(one == null && two == null){
+ return;
+ }else if(one != null && two == null){
+ throw new XMLComparisonException("First Namespace is NOT null. But the second is null");
+ }else if(one == null && two != null){
+ throw new XMLComparisonException("First Namespace is null. But the second is NOT null");
+ }
+
+ if(!one.getName().equals(two.getName())){
+ throw new XMLComparisonException(failureNotice + one + " != " + two);
+ }
+
+ // Do we need to compare prefixes as well
+ }
+}
Modified: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java?view=diff&r1=158420&r2=158421
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java (original)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java Mon Mar 21 01:11:36 2005
@@ -3,6 +3,7 @@
import org.apache.axis.om.AbstractTestCase;
import org.apache.axis.om.OMTestCase;
import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis.om.impl.llom.util.XMLComparator;
/**
* Copyright 2001-2004 The Apache Software Foundation.