[jboss-svn-commits] JBoss Portal SVN: r5115 - in trunk/wsrp/src/main/org/jboss/portal: test/wsrp test/wsrp/handler wsrp/handler

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 29 19:17:59 EDT 2006


Author: chris.laprun at jboss.com
Date: 2006-08-29 19:17:57 -0400 (Tue, 29 Aug 2006)
New Revision: 5115

Added:
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessageContext.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java
Modified:
   trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
Log:
- Added test cases for RequestHeaderClientHandler.
- Fixed bugs.



Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java	2006-08-29 23:08:02 UTC (rev 5114)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessage.java	2006-08-29 23:17:57 UTC (rev 5115)
@@ -0,0 +1,124 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., 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 javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.handler.MockSOAPMessage">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.4
+ */
+public class MockSOAPMessage extends SOAPMessage
+{
+   MimeHeaders headers;
+
+
+   public MockSOAPMessage()
+   {
+      headers = new MimeHeaders();
+   }
+
+   public MockSOAPMessage(MimeHeaders headers)
+   {
+      this.headers = headers;
+   }
+
+   public MimeHeaders getMimeHeaders()
+   {
+      return headers;
+   }
+
+   public void setMimeHeaders(MimeHeaders mimeHeaders)
+   {
+      this.headers = mimeHeaders;
+   }
+   
+   public void addAttachmentPart(AttachmentPart attachmentPart)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public AttachmentPart createAttachmentPart()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public String getContentDescription()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void setContentDescription(String string)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public SOAPPart getSOAPPart()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void removeAllAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public int countAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public Iterator getAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public Iterator getAttachments(MimeHeaders mimeHeaders)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void saveChanges() throws SOAPException
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public boolean saveRequired()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void writeTo(OutputStream outputStream) throws SOAPException, IOException
+   {
+      throw new UnsupportedOperationException();
+   }
+}

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessageContext.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessageContext.java	2006-08-29 23:08:02 UTC (rev 5114)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/MockSOAPMessageContext.java	2006-08-29 23:17:57 UTC (rev 5115)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., 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 javax.xml.rpc.handler.soap.SOAPMessageContext;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.handler.MockSOAPMessageContext">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.4
+ */
+public class MockSOAPMessageContext implements InvocationHandler
+{
+   MockSOAPMessage message;
+
+
+   public MockSOAPMessageContext(MockSOAPMessage message)
+   {
+      this.message = message;
+   }
+
+   public MockSOAPMessage getMessage()
+   {
+      return message;
+   }
+
+   public void setMessage(MockSOAPMessage message)
+   {
+      this.message = message;
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      String methodName = method.getName();
+
+      if ("getMessage".equals(methodName))
+      {
+         return getMessage();
+      }
+      else if ("getProperty".equals(methodName))
+      {
+         return "http://jboss.com"; // should only be called to get the endpoint address
+      }
+      else if ("toString".equals(methodName))
+      {
+         return this.toString();
+      }
+
+      throw new UnsupportedOperationException("MockSOAPMessageContext does not support " + methodName + " method");
+   }
+
+   public static SOAPMessageContext createMessageContext(MockSOAPMessage message, ClassLoader classLoader)
+   {
+      return (SOAPMessageContext)Proxy.newProxyInstance(classLoader, new Class[]{SOAPMessageContext.class},
+         new MockSOAPMessageContext(message));
+   }
+}

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java	2006-08-29 23:08:02 UTC (rev 5114)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/handler/RequestHeaderClientHandlerTestCase.java	2006-08-29 23:17:57 UTC (rev 5115)
@@ -0,0 +1,163 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., 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.apache.commons.httpclient.Cookie;
+import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
+import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
+
+import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.MimeHeaders;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.4
+ */
+public class RequestHeaderClientHandlerTestCase extends TestCase
+{
+   RequestHeaderClientHandler handler;
+
+
+   protected void setUp() throws Exception
+   {
+      handler = new RequestHeaderClientHandler();
+      RequestHeaderClientHandler.resetCurrentInfo();
+   }
+
+   public void testSimpleCookieHandleRequest()
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+
+      handler.handleRequest(msgContext);
+      MimeHeaders headers = message.getMimeHeaders();
+      assertNull(headers.getHeader("Cookie"));
+
+      ProducerSessionInformation sessionInformation = new ProducerSessionInformation();
+      sessionInformation.setUserCookie(new Cookie[]{createCookie("name", "value", 1)});
+      RequestHeaderClientHandler.setCurrentInfo(null, sessionInformation);
+      handler.handleRequest(msgContext);
+
+      headers = message.getMimeHeaders();
+      String[] cookie = headers.getHeader("Cookie");
+      assertEquals(1, cookie.length);
+      assertEquals("name=value", cookie[0]);
+   }
+
+   public void testGroupCookieHandleRequest()
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+
+      ProducerSessionInformation info = new ProducerSessionInformation();
+      info.setPerGroupCookies(true);
+      String groupId = "group";
+      info.setGroupCookieFor(groupId, new Cookie[] {createCookie("name", "value", 1)});
+      RequestHeaderClientHandler.setCurrentInfo(null, info);
+
+      try
+      {
+         handler.handleRequest(msgContext);
+         fail("group id hasn't been set so shouldn't be able to complete request");
+      }
+      catch (IllegalStateException e)
+      {
+         // expected
+      }
+
+      RequestHeaderClientHandler.setCurrentGroupId(groupId);
+
+      handler.handleRequest(msgContext);
+
+      MimeHeaders headers = message.getMimeHeaders();
+      String[] cookie = headers.getHeader("Cookie");
+      assertEquals(1, cookie.length);
+      assertEquals("name=value", cookie[0]);
+   }
+
+   public void testBothCookiesHandleRequest()
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+
+      ProducerSessionInformation info = new ProducerSessionInformation();
+      info.setPerGroupCookies(true);
+      String groupId = "group";
+      info.setGroupCookieFor(groupId, new Cookie[] {createCookie("name", "value", 1)});
+      info.setUserCookie(new Cookie[] {createCookie("usercookie", "uservalue", 1)});
+      RequestHeaderClientHandler.setCurrentInfo(groupId, info);
+
+
+      handler.handleRequest(msgContext);
+      MimeHeaders headers = message.getMimeHeaders();
+      String[] cookie = headers.getHeader("Cookie");
+      assertEquals(1, cookie.length);
+      assertEquals("name=value;usercookie=uservalue", cookie[0]);
+   }
+
+   public void testCookieWithoutInitHandleResponse()
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+      MimeHeaders headers = new MimeHeaders();
+      headers.setHeader("Set-Cookie", "name=value");
+      message.setMimeHeaders(headers);
+
+      handler.handleResponse(msgContext);
+      ProducerSessionInformation info = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+      assertEquals("name=value", info.getUserCookie());
+      assertFalse(info.isInitCookieDone());
+      assertFalse(info.isPerGroupCookies());
+   }
+
+   public void testCurrentInfo()
+   {
+      assertNull(RequestHeaderClientHandler.getCurrentProducerSessionInformation());
+      assertNull(RequestHeaderClientHandler.getCurrentGroupId());
+
+      try
+      {
+         RequestHeaderClientHandler.setCurrentGroupId("foo");
+         fail("Current info was not set, shouldn't have thrown an IllegalStateException");
+      }
+      catch (IllegalStateException e)
+      {
+         // expected
+      }
+
+      ProducerSessionInformation info = new ProducerSessionInformation();
+      String groupId = "group";
+      RequestHeaderClientHandler.setCurrentInfo(groupId, info);
+
+      assertSame(info, RequestHeaderClientHandler.getCurrentProducerSessionInformation());
+      assertEquals(groupId, RequestHeaderClientHandler.getCurrentGroupId());
+   }
+
+   private Cookie createCookie(String name, String value, int secondsBeforeExpiration)
+   {
+      return new Cookie("domain", name, value, "path", secondsBeforeExpiration, false);
+   }
+}

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java	2006-08-29 23:08:02 UTC (rev 5114)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/handler/RequestHeaderClientHandler.java	2006-08-29 23:17:57 UTC (rev 5115)
@@ -49,10 +49,6 @@
    private static final ThreadLocal local = new ThreadLocal();
    private static final RFC2109Spec cookieParser = new RFC2109Spec();
 
-   public void init(HandlerInfo info)
-   {
-   }
-
    public QName[] getHeaders()
    {
       return null;
@@ -86,13 +82,17 @@
          String groupCookie = sessionInfo.getGroupCookieFor(info.groupId);
          if (groupCookie != null)
          {
-            cookie.append(groupCookie).append(";");
+            cookie.append(groupCookie);
          }
       }
 
       String userCookie = sessionInfo.getUserCookie();
       if (userCookie != null)
       {
+         if (cookie.length() != 0)
+         {
+            cookie.append(";");
+         }
          cookie.append(userCookie);
       }
 
@@ -165,6 +165,10 @@
       {
          String host = hostURL.getHost();
          int port = hostURL.getPort();
+         if(port == -1)
+         {
+            port = 80; // if the port is not set in the endpoint address, assume it's 80.
+         }         
          String path = hostURL.getPath();
          boolean secure = hostURL.getProtocol().endsWith("s"); // todo: is that correct?
 
@@ -209,6 +213,16 @@
       return null;
    }
 
+   public static String getCurrentGroupId()
+   {
+      CurrentInfo info = getCurrentInfo(false);
+      if (info != null)
+      {
+         return info.groupId;
+      }
+      return null;
+   }
+
    public static void setCurrentGroupId(String groupId)
    {
       CurrentInfo currentInfo = (CurrentInfo)local.get();




More information about the jboss-svn-commits mailing list