Author: mageshbk(a)jboss.com
Date: 2010-03-22 02:02:27 -0400 (Mon, 22 Mar 2010)
New Revision: 11830
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPMessageImpl.java
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
Log:
[JBPAPP-3943] - Wrong namespace on SOAP operation when a method with header parameter
having a new namespace is invoked, "second" after a method that does not have
this namespace'd parameter
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPMessageImpl.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPMessageImpl.java 2010-03-21
20:34:42 UTC (rev 11829)
+++
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPMessageImpl.java 2010-03-22
06:02:27 UTC (rev 11830)
@@ -34,11 +34,13 @@
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MimeHeader;
import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
@@ -47,6 +49,7 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.SOAPMessageAbstraction;
+import org.jboss.ws.core.soap.SOAPContent.State;
import org.jboss.ws.core.soap.attachment.AttachmentPartImpl;
import org.jboss.ws.core.soap.attachment.CIDGenerator;
import org.jboss.ws.core.soap.attachment.MimeConstants;
@@ -56,6 +59,8 @@
import org.jboss.ws.extensions.xop.XOPContext;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* The root class for all SOAP messages. As transmitted on the "wire", a SOAP
message is an XML document or a
@@ -523,7 +528,7 @@
if (attachment == null)
{
- // autogenerated CID based on part name
+ // auto-generated CID based on part name
attachment = getAttachmentByPartName(ref);
}
@@ -557,4 +562,41 @@
while (attachmentItr.next() != null)
attachmentItr.remove();
}
+
+ public void prepareForDOMAccess() throws SOAPException
+ {
+ prepareForSpecificAccess(State.DOM_VALID);
+ }
+
+ private void prepareForSpecificAccess(State state) throws SOAPException
+ {
+ List<SOAPContentElement> contentElements = new
LinkedList<SOAPContentElement>();
+ SOAPBody soapBody = this.getSOAPBody();
+ NodeList nodes = soapBody.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node current = nodes.item(i);
+ if (current instanceof SOAPContentElement)
+ {
+ contentElements.add((SOAPContentElement)current);
+ break;
+ }
+ }
+ SOAPHeader soapHeader = this.getSOAPHeader();
+ nodes = soapHeader.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ Node current = nodes.item(i);
+ if (current instanceof SOAPContentElement)
+ {
+ contentElements.add((SOAPContentElement)current);
+ break;
+ }
+ }
+ for (SOAPContentElement sce : contentElements)
+ {
+ sce.transitionTo(state);
+ }
+ }
+
}
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/XMLContent.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/XMLContent.java 2010-03-21
20:34:42 UTC (rev 11829)
+++
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/core/soap/XMLContent.java 2010-03-22
06:02:27 UTC (rev 11830)
@@ -39,8 +39,8 @@
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.binding.AbstractDeserializerFactory;
import org.jboss.ws.core.binding.BindingException;
-import org.jboss.ws.core.binding.AbstractDeserializerFactory;
import org.jboss.ws.core.binding.DeserializerSupport;
import org.jboss.ws.core.binding.SerializationContext;
import org.jboss.ws.core.binding.TypeMappingImpl;
@@ -309,18 +309,28 @@
// Remove all child nodes
container.removeContents();
- // In case of dispatch and provider we use artifical element names
+ // In case of dispatch and provider we use artificial element names
// These need to be replaced (costly!)
if (artificalElement)
{
container.setElementQNameInternal(contentRootName);
}
- Document ownerDoc = container.getOwnerDocument();
+ // Process attributes: we copy from the fragment element to the previous container
element, after having cleaned the latter
+ // to prevent useless / redundant namespace declarations with multiple prefixes. We
also update the prefix of the container
+ // element to ensure proper namespace is configured for it
+ String oldPrefix = container.getPrefix();
+ if (oldPrefix != null)
+ {
+ container.removeNamespaceDeclaration(oldPrefix);
+ }
DOMUtils.copyAttributes(container, domElement);
+ container.setPrefix(domElement.getPrefix());
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
+ // Add new child nodes
+ Document ownerDoc = container.getOwnerDocument();
NodeList nlist = domElement.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2010-03-21
20:34:42 UTC (rev 11829)
+++
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/core/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2010-03-22
06:02:27 UTC (rev 11830)
@@ -214,6 +214,11 @@
SecurityStore securityStore = new SecurityStore(configuration.getKeyStoreURL(),
configuration.getKeyStoreType(), configuration.getKeyStorePassword(),
configuration.getKeyPasswords(), configuration.getTrustStoreURL(),
configuration.getTrustStoreType(), configuration.getTrustStorePassword());
SecurityEncoder encoder = new SecurityEncoder(operations, securityStore);
+
+ if ((sign != null || encrypt != null) && message instanceof
SOAPMessageImpl)
+ {
+ ((SOAPMessageImpl)message).prepareForDOMAccess();
+ }
encoder.encode(message.getSOAPPart());
}
catch (WSSecurityException e)
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2010-03-21
20:34:42 UTC (rev 11829)
+++
stack/native/branches/jbossws-native-3.1.2.SP3_JBPAPP-3943/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2010-03-22
06:02:27 UTC (rev 11830)
@@ -32,10 +32,16 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.Text;
+import org.jboss.ws.core.soap.MessageFactoryImpl;
import org.jboss.ws.core.soap.NameImpl;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.SOAPElementImpl;
+import org.jboss.ws.core.soap.Style;
import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.wsf.test.JBossWSTest;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* Test the SOAPContentElement
@@ -187,4 +193,53 @@
String expEnv = "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:...
xmlns:ns1='http://handlerservice1.org/wsdl'><String_1>wo... header
was added</String_1></ns1:hello></env:Body></env:Envelope>";
assertEquals(expEnv, baos.toString());
}
+
+
+ //JBWS-2940: JAXB marshalling of object model can lead to a slightly different yet
equivalent XMLFragment
+ //The new fragment can have different namespace prefix declarations, which can cause
major issues in unlucky situations like below
+ public void testAttributesHandlingOnModelTransition() throws Exception
+ {
+ String envStr =
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
+ "<env:Body>" +
+ "<ns2:Foo xmlns:ns2='firstNS'/>" +
+ "</env:Body>" +
+ "</env:Envelope>";
+
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ factory.setStyle(Style.DOCUMENT);
+ SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
+
+ SOAPContentElement sce = getSOAPContentElement(soapMessage);
+
+ //force transition to XML_VALID and set an equivalent XMLFragment (but having a new
ns declaration that would overwrite the one in the original fragment)
+ sce.setXMLFragment(new XMLFragment("<Foo xmlns='firstNS'
xmlns:ns2='secondNs'/>"));
+
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+ //force transition to DOM_VALID
+ soapBody.getFirstChild().getChildNodes();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMessage.writeTo(baos);
+
+ soapMessage = factory.createMessage(null, new
ByteArrayInputStream(baos.toByteArray()));
+ Node foo = soapMessage.getSOAPBody().getFirstChild();
+ assertEquals("firstNS", foo.getNamespaceURI());
+ }
+
+ private SOAPContentElement getSOAPContentElement(final SOAPMessage soapMessage) throws
Exception
+ {
+ SOAPBodyImpl soapBody = (SOAPBodyImpl)soapMessage.getSOAPBody();
+ SOAPElementImpl bodyElement = null;
+ NodeList nodes = soapBody.getChildNodes();
+ for (int i = 0; i < nodes.getLength() && bodyElement == null; i++)
+ {
+ Node current = nodes.item(i);
+ if (current instanceof SOAPElementImpl)
+ {
+ bodyElement = (SOAPElementImpl)current;
+ }
+ }
+ return (SOAPContentElement)bodyElement;
+ }
}