[portal-commits] JBoss Portal SVN: r12278 - in branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal: wsrp/handler and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Nov 10 08:37:50 EST 2008


Author: chris.laprun at jboss.com
Date: 2008-11-10 08:37:50 -0500 (Mon, 10 Nov 2008)
New Revision: 12278

Added:
   branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPBody.java
   branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/WSRPExtensionHandlerTestCase.java
Modified:
   branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java
   branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/WSRPExtensionHandler.java
Log:
- JBPORTAL-2233:
  + Re-wrote traversal logic of WSRPExtensionHandler to traverse the whole tree.
  + Added test case.
  + Removed dependency on DOMUtils.

Added: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPBody.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPBody.java	                        (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPBody.java	2008-11-10 13:37:50 UTC (rev 12278)
@@ -0,0 +1,57 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.portal.test.wsrp.handler;
+
+import org.jboss.util.xml.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.xml.soap.SOAPBody;
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class MockSOAPBody implements InvocationHandler
+{
+   Element body;
+
+   public MockSOAPBody(Element body)
+   {
+      this.body = body;
+   }
+
+   public static SOAPBody newInstance(String body) throws IOException
+   {
+      return (SOAPBody)Proxy.newProxyInstance(MockSOAPBody.class.getClassLoader(), new Class[]{SOAPBody.class},
+         new MockSOAPBody(DOMUtils.parse(body)));
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      return method.invoke(body, args);
+   }
+}

Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java	2008-11-10 13:37:35 UTC (rev 12277)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java	2008-11-10 13:37:50 UTC (rev 12278)
@@ -25,6 +25,7 @@
 
 import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
@@ -42,8 +43,8 @@
 public class MockSOAPMessage extends SOAPMessage
 {
    MimeHeaders headers;
+   String messageBody;
 
-
    public MockSOAPMessage()
    {
       headers = new MimeHeaders();
@@ -54,6 +55,24 @@
       this.headers = headers;
    }
 
+   public void setMessageBody(String messageBody)
+   {
+      this.messageBody = messageBody;
+   }
+
+   @Override
+   public SOAPBody getSOAPBody() throws SOAPException
+   {
+      try
+      {
+         return MockSOAPBody.newInstance(messageBody);
+      }
+      catch (IOException e)
+      {
+         throw new SOAPException(e);
+      }
+   }
+
    public MimeHeaders getMimeHeaders()
    {
       return headers;

Added: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/WSRPExtensionHandlerTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/WSRPExtensionHandlerTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/handler/WSRPExtensionHandlerTestCase.java	2008-11-10 13:37:50 UTC (rev 12278)
@@ -0,0 +1,239 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.portal.test.wsrp.handler;
+
+import junit.framework.TestCase;
+import org.jboss.portal.wsrp.handler.WSRPExtensionHandler;
+
+import javax.xml.rpc.handler.HandlerInfo;
+import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPExtensionHandlerTestCase extends TestCase
+{
+   private WSRPExtensionHandler handler;
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      handler = new WSRPExtensionHandler();
+
+      HandlerInfo info = new HandlerInfo();
+      Map<String, String> config = new HashMap<String, String>();
+      config.put("debug", "false");
+      config.put("removeExtensions", "true");
+      info.setHandlerConfig(config);
+      handler.init(info);
+   }
+
+   public void testRemoveExtensions() throws SOAPException
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      message.setMessageBody("<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'\n" +
+         "\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'\n" +
+         "\txmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+         "\txmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
+         "\t<env:Body>\n" +
+         "\t\t<ns0:getMarkup xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t<ns0:registrationContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:registrationHandle\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t17\n" +
+         "\t\t\t\t</ns0:registrationHandle>\n" +
+         "\t\t\t\t<ns0:registrationState\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:registrationContext>\n" +
+         "\t\t\t<ns0:portletContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:portletHandle\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t_18\n" +
+         "\t\t\t\t</ns0:portletHandle>\n" +
+         "\t\t\t\t<ns0:portletState\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:portletContext>\n" +
+         "\t\t\t<ns0:runtimeContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:userAuthentication xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\twsrp:none\n" +
+         "\t\t\t\t</ns0:userAuthentication>\n" +
+         "\t\t\t\t<ns0:portletInstanceKey\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t949994222\n" +
+         "\t\t\t\t</ns0:portletInstanceKey>\n" +
+         "\t\t\t\t<ns0:namespacePrefix\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t__ns949994222_\n" +
+         "\t\t\t\t</ns0:namespacePrefix>\n" +
+         "\t\t\t</ns0:runtimeContext>\n" +
+         "\t\t\t<ns0:userContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:userContextKey\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\twsrp:minimal\n" +
+         "\t\t\t\t</ns0:userContextKey>\n" +
+         "\t\t\t\t<ns0:profile\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:userContext>\n" +
+         "\t\t\t<ns0:markupParams\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:secureClientCommunication xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\tfalse\n" +
+         "\t\t\t\t\t</ns0:secureClientCommunication>\n" +
+         "\t\t\t\t\t<ns0:locales\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ten-US\n" +
+         "\t\t\t\t\t</ns0:locales>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/html\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/xml\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/vnd.oracle.mobilexml\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t*\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mode\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:view\n" +
+         "\t\t\t\t\t</ns0:mode>\n" +
+         "\t\t\t\t\t<ns0:windowState\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:normal\n" +
+         "\t\t\t\t\t</ns0:windowState>\n" +
+         "\t\t\t\t\t<ns0:clientData\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t<ns0:userAgent\n" +
+         "\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\tMozilla/5.0 (Windows; U; Windows NT 5.1;\n" +
+         "\t\t\t\t\t\t\ten-US; rv:1.9.0.3) Gecko/2008092417\n" +
+         "\t\t\t\t\t\t\tFirefox/3.0.3\n" +
+         "\t\t\t\t\t\t</ns0:userAgent>\n" +
+         "\t\t\t\t\t\t<ns0:extensions\n" +
+         "\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t<ns1:GenericExtension\n" +
+         "\t\t\t\t\t\t\t\txmlns:ns1='http://xmlns.oracle.com/portal/wsrp/v1'>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='CONNECTION'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value\n" +
+         "\t\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\tkeep-alive\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='ACCEPT-ENCODING'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\tgzip,deflate\n" +
+         "\t\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='KEEP-ALIVE'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\t300\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='HOST'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\t127.0.0.1:8988\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t</ns1:GenericExtension>\n" +
+         "\t\t\t\t\t\t</ns0:extensions>\n" +
+         "\t\t\t\t\t</ns0:clientData>\n" +
+         "\t\t\t\t\t<ns0:markupCharacterSets\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\tUTF-8\n" +
+         "\t\t\t\t\t</ns0:markupCharacterSets>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:view\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:edit_defaults\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:edit\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:help\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:about\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:print\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:config\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:normal\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:maximized\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:minimized\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t</ns0:markupParams>\n" +
+         "\t\t</ns0:getMarkup>\n" +
+         "\t</env:Body>\n" +
+         "</env:Envelope>");
+
+
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+
+      handler.handleRequest(msgContext);
+
+      SOAPBody body = msgContext.getMessage().getSOAPBody();
+      String asString = body.toString();
+      assertFalse(asString.contains("ns0:extensions"));
+      assertFalse(asString.contains("ns1:GenericExtensions"));
+      assertFalse(asString.contains("ACCEPT-ENCODING"));
+   }
+}

Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/WSRPExtensionHandler.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/WSRPExtensionHandler.java	2008-11-10 13:37:35 UTC (rev 12277)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/handler/WSRPExtensionHandler.java	2008-11-10 13:37:50 UTC (rev 12278)
@@ -23,23 +23,18 @@
 package org.jboss.portal.wsrp.handler;
 
 import org.jboss.logging.Logger;
-import org.jboss.util.xml.DOMUtils;
-import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import javax.xml.namespace.QName;
 import javax.xml.rpc.handler.GenericHandler;
 import javax.xml.rpc.handler.HandlerInfo;
 import javax.xml.rpc.handler.MessageContext;
 import javax.xml.rpc.handler.soap.SOAPMessageContext;
-import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPMessage;
-import java.util.Iterator;
 
-//$Id$
-
 /**
- * JAX-RPC Handler that strips the SOAP Message of any WSRP extensions. Right now, only operates on response messages.
+ * JAX-RPC Handler that strips the SOAP Message of any WSRP extensions.
  *
  * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
@@ -93,31 +88,7 @@
          if (removeExtensions)
          {
             SOAPBody soapBody = soapMessage.getSOAPBody();
-            Element firstEl = DOMUtils.getFirstChildElement(soapBody);
-            Iterator iter = DOMUtils.getChildElements(firstEl);
-            while (iter.hasNext())
-            {
-               Element elt = (Element)iter.next();
-               String nodeName = elt.getNodeName();
-               if (EXTENSIONS.equals(nodeName))
-               {
-                  removeChildrenOf(elt);
-               }
-               else
-               {
-                  Iterator extensions = DOMUtils.getChildElements(elt, EXTENSIONS);
-                  if (extensions.hasNext())
-                  {
-                     log.debug("extensions exist on " + nodeName);
-                     Element exts = (Element)extensions.next();
-                     removeChildrenOf(exts);
-                     if (debug)
-                     {
-                        soapMessage.writeTo(System.out);
-                     }
-                  }
-               }
-            }
+            traverseAndRemoveExtensions(soapBody);
          }
       }
       catch (Exception e)
@@ -126,27 +97,39 @@
       }
    }
 
-   private void removeChildrenOf(Element element)
+   /**
+    * Remove extensions nodes recursively, depth-first.
+    *
+    * @param node
+    */
+   private void traverseAndRemoveExtensions(org.w3c.dom.Node node)
    {
-      Iterator children = DOMUtils.getChildElements(element);
-      while (children.hasNext())
+      NodeList children = node.getChildNodes();
+      int childrenNb = children.getLength();
+      for (int i = 0; i < childrenNb; i++)
       {
-         Node node = (Node)children.next();
-         element.removeChild(node);
-      }
-   }
+         org.w3c.dom.Node child = children.item(i);
 
-   /*private boolean shouldRemoveWSRPExtensions(SOAPHeader soapHeader)
-   {
-      boolean result = false;
-      if (soapHeader != null)
-      {
-         Iterator iter = DOMUtils.getChildElements(soapHeader, "jboss_wsrp_remove_extension");
-         if (iter.hasNext())
+         // only process elements
+         if (org.w3c.dom.Node.ELEMENT_NODE == child.getNodeType())
          {
-            result = true;
+            String name = child.getLocalName();
+
+            // if we found an extension, remove it or continue
+            if (EXTENSIONS.equals(name))
+            {
+               if (debug)
+               {
+                  log.debug("Extensions removed on " + name);
+               }
+               node.removeChild(child);
+               break;
+            }
+            else
+            {
+               traverseAndRemoveExtensions(child);
+            }
          }
       }
-      return result;
-   }*/
+   }
 }




More information about the portal-commits mailing list