[jboss-svn-commits] JBL Code SVN: r35450 - in labs/jbossesb/branches/JBESB_4_9_CP: qa/junit and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 7 04:56:06 EDT 2010


Author: mageshbk at jboss.com
Date: 2010-10-07 04:56:06 -0400 (Thu, 07 Oct 2010)
New Revision: 35450

Added:
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/WEB-INF/
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/WEB-INF/web.xml
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/EchoServlet.java
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/HttpRouterUnitTest.java
Modified:
   labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/build.xml
Log:
[JBESB-1914] - Added support for wrap switch in HttpRouter.

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java	2010-10-07 06:35:36 UTC (rev 35449)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -37,4 +37,10 @@
     	initialiseRetryHandler(method);
     	return method;
     }
+
+    public HttpMethodBase getMethod(String message, String contentType, String charset) throws IOException {
+    	GetMethod method = new GetMethod( getEndpointPathAndQuery() );
+    	initialiseRetryHandler(method);
+    	return method;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java	2010-10-07 06:35:36 UTC (rev 35449)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -41,6 +41,8 @@
 
     public HttpMethodBase getInstance(Message message) throws IOException;
 
+    public HttpMethodBase getMethod(String message, String contentType, String charset) throws IOException;
+
     /**
      * Uitility factory class for reflective {@link HttpMethodFactory} construction.
      */

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2010-10-07 06:35:36 UTC (rev 35449)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -23,18 +23,23 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.Encoding;
 import org.jboss.internal.soa.esb.util.StreamUtils;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.ActionLifecycleException;
@@ -53,7 +58,9 @@
 import org.jboss.soa.esb.message.ResponseHeader;
 import org.jboss.soa.esb.message.ResponseStatus;
 import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
 import org.jboss.soa.esb.util.FileUtil;
+import org.jboss.soa.esb.util.Util;
 
 /**
  * Http router.
@@ -98,6 +105,9 @@
             throw new ConfigurationException("Invalid endpoint URL '" + config.getRequiredAttribute("endpointUrl") + "'.", e);
         }
 
+        //Overriding to set true by default
+        unwrap = config.getAttribute("unwrap", "true").equals("true");
+
         // Extract the HttpClient creation properties from the ConfigTree.  These are passed
         // to the HttpClientFacatory...
         extractHttpClientProps(config);
@@ -124,7 +134,21 @@
     public Message process(Message message) throws ActionProcessingException {
         HttpMethodBase method = null;
         try {
-            method = methodFactory.getInstance(message);
+            if (unwrap) {
+                    method = methodFactory.getInstance(message);
+            } else {
+                try {
+                    Serializable payload = Util.serialize(message);
+                    if (message.getType().equals(MessageType.JAVA_SERIALIZED)) {
+                        String payloadStr = Encoding.encodeObject(payload);
+                        method = methodFactory.getMethod(payloadStr, "application/x-java-serialized-object", Charset.defaultCharset().toString());
+                    } else {
+                        method = methodFactory.getMethod(payload.toString(), "text/xml", "UTF-8");
+                    }
+                } catch (ParserConfigurationException e) {
+                    throw new ActionProcessingException(e);
+                }
+            }
 
             try {
                 setRequestHeaders(method, message);

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2010-10-07 06:35:36 UTC (rev 35449)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -87,4 +87,22 @@
         initialiseRetryHandler(method);
         return method;
     }
+
+    /**
+     * Given the serialized input message get the PostMethod.
+     * 
+     * @param messsage The serialized message.
+     * @param contentType The content type for the message.
+     * @param charset The charcter encoding for the message.
+     * @return The PostMethod wrapping the serialized message.
+     */
+    public HttpMethodBase getMethod(String message, String contentType, String charset) throws IOException {
+        PostMethod method = new PostMethod( getEndpointPathAndQuery() );
+
+        final RequestEntity entity = new StringRequestEntity(message, contentType, charset);
+
+        method.setRequestEntity(entity);
+        initialiseRetryHandler(method);
+        return method;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/build.xml	2010-10-07 06:35:36 UTC (rev 35449)
+++ labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/build.xml	2010-10-07 08:56:06 UTC (rev 35450)
@@ -212,6 +212,11 @@
             <include name="org/jboss/soa/esb/server/http_proxy_ws/*.class"/>
          </classes>
       </war>
+      <war jarfile="${qa.build.lib}/esb-echo.war" webxml="${qa.junit.resources}/server/routing/WEB-INF/web.xml">
+         <classes dir="${qa.junit.classes}">
+            <include name="org/jboss/soa/esb/server/routing/EchoServlet.class"/>
+         </classes>
+      </war>
    </target>
 
    <target name="one-test" if="test" depends="jars"

Added: labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/WEB-INF/web.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/WEB-INF/web.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/resources/server/routing/WEB-INF/web.xml	2010-10-07 08:56:06 UTC (rev 35450)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+  <display-name>Echo Servlet</display-name>
+  <description>
+     Servlet that responds with the same body as the request stripping newlines.
+  </description>
+  <servlet>
+    <servlet-name>EchoServlet</servlet-name>
+    <servlet-class>org.jboss.soa.esb.server.routing.EchoServlet</servlet-class>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>EchoServlet</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+</web-app>

Added: labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/EchoServlet.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/EchoServlet.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/EchoServlet.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.esb.server.routing;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.log4j.Logger;
+
+/**
+ * A Servlet that echos the input request's body.
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class EchoServlet extends HttpServlet
+{
+    private Logger log = Logger.getLogger(EchoServlet.class);
+
+    public void init(ServletConfig config) throws ServletException
+    {
+        super.init(config);
+        log.info("EchoServlet initialized!");
+    }
+
+    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+        PrintWriter pw = new PrintWriter (response.getOutputStream());
+        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
+        String line = reader.readLine();
+        while (line != null)
+        {
+            pw.println(line);
+            line = reader.readLine();
+        }
+        reader.close();
+        pw.flush();
+        pw.close();
+    }
+}

Added: labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/HttpRouterUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/HttpRouterUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/qa/junit/src/org/jboss/soa/esb/server/routing/HttpRouterUnitTest.java	2010-10-07 08:56:06 UTC (rev 35450)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+package org.jboss.soa.esb.server.routing;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.internal.soa.esb.util.Encoding;
+import org.jboss.internal.soa.esb.util.XMLHelper;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.routing.http.HttpRouter;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+
+/**
+ * Test for HttpRouter.
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class HttpRouterUnitTest extends JBossTestCase
+{
+
+    public HttpRouterUnitTest(String name)
+    {
+        super(name);
+    }
+
+    public void testRouter_JavaSerialized() throws Exception
+    {
+        final String expected = "message: [ JAVA_SERIALIZED ]\n" +
+                            "header: [  ]\n" +
+                            "context: {}\n" +
+                            "body: [ objects: {org.jboss.soa.esb.message.defaultEntry=bar} ]\n" +
+                            "fault: [  ]\n" +
+                            "attachments: [ Named:{}, Unnamed:[] ]\n" +
+                            "properties: [ {} ]";
+
+        String response = postSerializedMessage(MessageType.JAVA_SERIALIZED, expected, true);
+        assertEquals(expected, response);
+    }
+
+    public void testRouter_XMLSerialized() throws Exception
+    {
+        final String expected = "<Envelope>" +
+                                "<Header xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" />" +
+                                "<Context />" +
+                                "<Body>" +
+                                "<Content><Key>b3JnLmpib3NzLnNvYS5lc2IubWVzc2FnZS5kZWZhdWx0RW50cnk=</Key>" +
+                                "<Value>" +
+                                "<marshalunmarshal><plugin-type>urn:xml/marshalunmarshal/plugin/serialization</plugin-type>rO0ABXQAA2Jhcg==</marshalunmarshal>" +
+                                "</Value>" +
+                                "</Content>" +
+                                "</Body>" +
+                                "<Attachment />" +
+                                "<Properties />" +
+                                "</Envelope>";
+
+        String response = postSerializedMessage(MessageType.JBOSS_XML, expected, false);
+        assertTrue("Serialized Message XML does not match",
+                XMLHelper.compareXMLContent(new ByteArrayInputStream(expected.getBytes()), new ByteArrayInputStream(response.getBytes())));
+    }
+
+    private String postSerializedMessage(URI type, String expected, Boolean deserialize) throws Exception
+    {
+        final ConfigTree tree = new ConfigTree("WrappedMessage");
+        tree.setAttribute("endpointUrl", "http://127.0.0.1:8080/esb-echo");
+        tree.setAttribute("method", "post");
+        tree.setAttribute("unwrap", "false");
+        tree.setAttribute("MappedHeaderList", "SOAPAction, Content-Type, Accept, If-Modified-Since");
+        
+        HttpRouter router = new HttpRouter(tree);
+        Message message = MessageFactory.getInstance().getMessage(type);
+        message.getBody().add("bar");
+
+        Message response = router.process(message);
+        String responseBody = (String)response.getBody().get();
+        String responseStr = null;
+        if (deserialize)
+            responseStr = Encoding.decodeToObject(responseBody).toString();
+        else
+            responseStr = responseBody;
+
+        return responseStr;
+    }
+
+    public static Test suite() throws Exception
+    {
+        return getDeploySetup(HttpRouterUnitTest.class, "esb-echo.war");
+    }
+
+}



More information about the jboss-svn-commits mailing list