[jboss-svn-commits] JBL Code SVN: r18564 - in labs/jbossesb/workspace/sandbox: HttpRouter and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Feb 22 13:41:49 EST 2008


Author: tfennelly
Date: 2008-02-22 13:41:49 -0500 (Fri, 22 Feb 2008)
New Revision: 18564

Added:
   labs/jbossesb/workspace/sandbox/HttpRouter/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/build.xml
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/deployment.xml
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbm-queue-service.xml
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbmq-queue-service.xml
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jboss-esb.xml
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jndi.properties
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/commons-ssl-0.3.4.jar
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/test-util.jar
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/readme.txt
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/GETHttpMethodFactory.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpHeader.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpMethodFactory.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpResponse.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpRouter.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/POSTHttpMethodFactory.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/ResponseType.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/HttpResponsePrinter.java
   labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/SendJMSMessage.java
Modified:
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml
Log:
Added the HttpRouter

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/build.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/build.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/build.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,20 @@
+<project name="http-router-sample1" default="deploy" basedir=".">
+	
+	<description> 
+		${ant.project.name}
+		${line.separator}
+	</description>
+
+    <property name="additional.deploys" value="server-12345.xml" />
+
+    <!-- Import the base Ant build script... -->
+	<import file="../conf/base-build.xml"/>
+
+    <target name="runtest" depends="compile" description="runs Test JMS Sender">
+        <echo>Runs Test JMS Sender</echo>
+        <java fork="yes" classname="runtest.SendJMSMessage" failonerror="true">
+            <classpath refid="exec-classpath" />
+        </java>
+    </target>
+
+</project>


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/build.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/deployment.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/deployment.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/deployment.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,4 @@
+<jbossesb-deployment>
+  <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_gw</depends>
+  <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_esb</depends>
+</jbossesb-deployment>


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/deployment.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbm-queue-service.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbm-queue-service.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbm-queue-service.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+    <mbean code="org.jboss.jms.server.destination.QueueService"
+           name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_gw"
+           xmbean-dd="xmdesc/Queue-xmbean.xml">
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+    <mbean code="org.jboss.jms.server.destination.QueueService"
+           name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_esb"
+           xmbean-dd="xmdesc/Queue-xmbean.xml">
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbm-queue-service.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbmq-queue-service.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbmq-queue-service.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbmq-queue-service.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+  <mbean code="org.jboss.mq.server.jmx.Queue"
+    name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_gw">
+    <depends optional-attribute-name="DestinationManager">
+      jboss.mq:service=DestinationManager
+    </depends>
+  </mbean>
+  <mbean code="org.jboss.mq.server.jmx.Queue"
+    name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_httprouter_esb">
+    <depends optional-attribute-name="DestinationManager">
+      jboss.mq:service=DestinationManager
+    </depends>
+  </mbean>
+</server>


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jbmq-queue-service.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jboss-esb.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jboss-esb.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,46 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb
+        xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
+        parameterReloadSecs="5">
+
+    <providers>
+        <jms-provider name="JBossMQ"
+            connection-factory="ConnectionFactory"
+            jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+            jndi-URL="localhost">
+
+            <jms-bus busid="quickstartGwChannel">
+                <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_httprouter_gw" />
+            </jms-bus>
+            <jms-bus busid="quickstartEsbChannel">
+                <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_httprouter_esb" />
+            </jms-bus>
+
+        </jms-provider>
+    </providers>
+
+    <services>                 
+
+        <service category="MyServiceCategory" name="MyHTTPService" description="HTTP Gateway example">
+            <listeners>
+                <jms-listener name="JMS-Gateway" busidref="quickstartGwChannel" maxThreads="1" is-gateway="true"/>
+                <jms-listener name="quickstart" busidref="quickstartEsbChannel" maxThreads="1" />
+            </listeners>
+            <actions>
+                <action name="httprouter" class="org.jboss.soa.esb.http.HttpRouter">
+                    <property name="endpointUrl" value="http://localhost:12345/blah"/>
+                    <property name="method" value="GET" /> <!-- Currently only supports GET or POST - easy to add more! -->
+                    <property name="responseType" value="STRING" /> <!-- Response should be set back on message as STRING or BYTE - default STRING -->
+                    <property name="headers">
+                        <header name="blah" value="blahval" />
+                    </property>
+                </action>
+
+                <action name="print" class="runtest.HttpResponsePrinter"/>
+            </actions>
+
+        </service>
+
+    </services>
+
+</jbossesb>


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jboss-esb.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jndi.properties
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jndi.properties	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jndi.properties	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,5 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming
+java.naming.factory.url.pkgs=org.jnp.interfaces
+


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/jndi.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/commons-ssl-0.3.4.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/commons-ssl-0.3.4.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/test-util.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/lib/test-util.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/readme.txt
===================================================================

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/GETHttpMethodFactory.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/GETHttpMethodFactory.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/GETHttpMethodFactory.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * HTTP GET Factory.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class GETHttpMethodFactory implements HttpMethodFactory {
+
+    private URL url;
+
+    public void setEndpoint(URL url) {
+        this.url = url;
+    }
+
+    public void setConfiguration(ConfigTree config) throws ConfigurationException {
+    }
+
+    public HttpMethodBase getInstance(Message message) throws IOException {
+        return new GetMethod(url.toString());
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/GETHttpMethodFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpHeader.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpHeader.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpHeader.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class HttpHeader implements Serializable {
+    
+    private String name;
+    private String value;
+
+    public HttpHeader(String name, String value) {
+        AssertArgument.isNotNullAndNotEmpty(name, "name");
+        AssertArgument.isNotNullAndNotEmpty(value, "value");
+        this.name = name;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpHeader.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpMethodFactory.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpMethodFactory.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpMethodFactory.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.soa.esb.Configurable;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.apache.commons.httpclient.HttpMethodBase;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Http method executor.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface HttpMethodFactory extends Configurable {
+
+    public void setEndpoint(URL url);
+
+    public HttpMethodBase getInstance(Message message) throws IOException;
+
+    /**
+     * Uitility factory class for reflective {@link HttpMethodFactory} construction.
+     */
+    public static class Factory {
+
+        public static HttpMethodFactory getInstance(String method, ConfigTree config, URL endpointUrl) throws ConfigurationException {
+            AssertArgument.isNotNullAndNotEmpty(method, "method");
+            AssertArgument.isNotNull(config, "config");
+            AssertArgument.isNotNull(endpointUrl, "endpointUrl");
+
+            String className = HttpMethodFactory.class.getPackage().getName() + "." + method + HttpMethodFactory.class.getSimpleName();
+
+            try {
+                HttpMethodFactory factory = (HttpMethodFactory) ClassUtil.forName(className, HttpMethodFactory.class).newInstance();
+                factory.setEndpoint(endpointUrl);
+                factory.setConfiguration(config);
+                return factory;
+            } catch (ClassCastException e) {
+                throw new ConfigurationException("Class '" + className + "' must implement '" + HttpMethodFactory.class.getName() + "'.");
+            } catch (ClassNotFoundException e) {
+                throw new ConfigurationException("Class '" + className + "' not found on classpath.");
+            } catch (IllegalAccessException e) {
+                throw new ConfigurationException("Class '" + className + "' cannot be instantiated.", e);
+            } catch (InstantiationException e) {
+                throw new ConfigurationException("Class '" + className + "' cannot be instantiated.", e);
+            }
+        }
+
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpMethodFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpResponse.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpResponse.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpResponse.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class HttpResponse implements Serializable {
+
+    public static final String RESPONSE_KEY = HttpResponse.class.getName() + "#response";
+
+    private int responseCode;
+    private long length;
+    private String encoding;
+    private List<HttpHeader> headers = new ArrayList<HttpHeader>();
+
+    public HttpResponse(int responseCode) {
+        this.responseCode = responseCode;
+    }
+
+    public int getResponseCode() {
+        return responseCode;
+    }
+
+    public long getLength() {
+        return length;
+    }
+
+    public void setLength(long length) {
+        this.length = length;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public List<HttpHeader> getHeaders() {
+        return headers;
+    }
+
+    public void addHeader(HttpHeader header) {
+        AssertArgument.isNotNull(header, "header");
+        headers.add(header);
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpResponse.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpRouter.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpRouter.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpRouter.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.Header;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionLifecycleException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.routing.AbstractRouter;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class HttpRouter extends AbstractRouter {
+
+    private static Logger logger = Logger.getLogger(HttpRouter.class);
+
+    private ConfigTree config;
+    private Properties httpClientProps = new Properties();
+    private HttpClient httpclient;
+    private URL endpointUrl;
+    private String method;
+    private HttpMethodFactory methodFactory;
+    private ResponseType responseType;
+    private String contentType;
+    private ConfigTree[] requestHeaders;
+
+    public HttpRouter(ConfigTree config) throws ConfigurationException {
+        super(config);
+        this.config = config;
+        try {
+            endpointUrl = new URL(config.getRequiredAttribute("endpointUrl"));
+        } catch (MalformedURLException e) {
+            throw new ConfigurationException("Invalid endpoint URL '" + config.getRequiredAttribute("endpointUrl") + "'.", e);
+        }
+
+        // Extract the HttpClient creation properties from the ConfigTree.  These are passed
+        // to the HttpClientFacatory...
+        extractHttpClientProps(config);
+        httpclient = HttpClientFactory.createHttpClient(httpClientProps);
+        method = config.getRequiredAttribute("method");
+        responseType = ResponseType.valueOf(config.getAttribute("responseType", ResponseType.STRING.toString()));
+        methodFactory = HttpMethodFactory.Factory.getInstance(method, config, endpointUrl);
+        contentType = config.getAttribute("Content-Type", "text/xml;charset=UTF-8");
+        requestHeaders = config.getChildren("header");
+    }
+
+    public Message process(Message message) throws ActionProcessingException {
+        HttpMethodBase method = null;
+        try {
+            method = methodFactory.getInstance(message);
+
+            try {
+                setRequestHeaders(method);
+                
+                int responseCode = httpclient.executeMethod(method);
+                if(responseCode != HttpStatus.SC_OK) {
+                    logger.warn("Received status code '" + responseCode + "' on HTTP " + method + " request to '" + endpointUrl + "'.");
+                }
+                attachResponseDetails(message, method, responseCode);
+
+                InputStream resultStream = method.getResponseBodyAsStream();
+                try {
+                    byte[] bytes = StreamUtils.readStream(resultStream);
+
+                    if(responseType == ResponseType.STRING) {
+                        getPayloadProxy().setPayload(message, new String(bytes, method.getResponseCharSet()));
+                    } else {
+                        getPayloadProxy().setPayload(message, bytes);
+                    }
+                } catch (MessageDeliverException e) {
+                    e.printStackTrace();
+                } finally {
+                    resultStream.close();
+                }
+            } finally {
+                method.releaseConnection();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return message;
+    }
+
+    private void attachResponseDetails(Message message, HttpMethodBase method, int responseCode) {
+        HttpResponse response = new HttpResponse(responseCode);
+
+        response.setEncoding(method.getResponseCharSet());
+        response.setLength(method.getResponseContentLength());
+
+        Header[] responseHeaders = method.getRequestHeaders();
+        for(Header responseHeader : responseHeaders) {
+            response.addHeader(new HttpHeader(responseHeader.getName(), responseHeader.getValue()));
+        }
+        
+        message.getBody().add(HttpResponse.RESPONSE_KEY, response);
+    }
+
+    private void setRequestHeaders(HttpMethodBase method) {
+        method.setRequestHeader("Content-Type", contentType);
+
+        for (int i = 0; i < requestHeaders.length; i++) {
+            ConfigTree header = requestHeaders[i];
+            String name = header.getAttribute("name");
+            String value = header.getAttribute("value");
+
+            if(name != null && value != null) {
+                method.setRequestHeader(name, value);
+            } else {
+                logger.error("null Http request header name/value: '" + name + "':'" + value + "'.");
+            }
+        }
+    }
+
+    public void route(Object object) throws ActionProcessingException {
+        // Not used!
+    }
+
+    public void destroy() throws ActionLifecycleException {
+        if (httpclient != null) {
+            HttpClientFactory.shutdown(httpclient);
+        }
+        super.destroy();
+    }
+
+    private void extractHttpClientProps(ConfigTree config) {
+        ConfigTree[] httpClientConfigTrees = config.getChildren("http-client-property");
+
+        httpClientProps.setProperty(HttpClientFactory.TARGET_HOST_URL, endpointUrl.toString());
+        final ConfigTree parent = config.getParent() ;
+        if (parent != null) {
+            final String maxThreads = config.getParent().getAttribute(ListenerTagNames.MAX_THREADS_TAG) ;
+            if (maxThreads != null) {
+                httpClientProps.setProperty(HttpClientFactory.MAX_TOTAL_CONNECTIONS, maxThreads) ;
+            }
+        }
+
+        // The HttpClient properties are attached under the factory class/impl property as <http-client-property name="x" value="y" /> nodes
+        for(ConfigTree httpClientProp : httpClientConfigTrees) {
+            String propName = httpClientProp.getAttribute("name");
+            String propValue = httpClientProp.getAttribute("value");
+
+            if(propName != null && propValue != null) {
+                httpClientProps.setProperty(propName, propValue);
+            }
+        }
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/HttpRouter.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/POSTHttpMethodFactory.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/POSTHttpMethodFactory.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/POSTHttpMethodFactory.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.MessagePayloadProxy;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * HTTP POST Factory.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class POSTHttpMethodFactory implements HttpMethodFactory {
+
+    private URL url;
+    private MessagePayloadProxy payloadProxy;
+
+    public void setEndpoint(URL url) {
+        this.url = url;
+    }
+
+    public void setConfiguration(ConfigTree config) throws ConfigurationException {
+        payloadProxy = new MessagePayloadProxy(config);
+    }
+
+    public HttpMethodBase getInstance(Message message) throws IOException {
+        PostMethod method = new PostMethod(url.toString());
+        try {
+            method.setRequestEntity(new StringRequestEntity(payloadProxy.getPayload(message).toString()));
+        } catch (MessageDeliverException e) {
+            IOException ioe = new IOException("Failed to access message payload.");
+            ioe.initCause(e);
+            throw ioe;
+        }
+        return method;
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/POSTHttpMethodFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/ResponseType.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/ResponseType.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/ResponseType.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+/**
+ * Http Response type.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public enum ResponseType {
+    STRING,
+    BYTES
+}


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/org/jboss/soa/esb/http/ResponseType.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/HttpResponsePrinter.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/HttpResponsePrinter.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/HttpResponsePrinter.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,45 @@
+package runtest;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.http.HttpResponse;
+import org.jboss.soa.esb.http.HttpHeader;
+import org.jboss.soa.esb.message.Message;
+
+import java.util.List;
+
+public class HttpResponsePrinter extends AbstractActionLifecycle {
+
+    protected ConfigTree _config;
+
+    public HttpResponsePrinter(ConfigTree config) {
+        _config = config;
+    }
+
+
+    public Message process(Message message) throws Exception {
+
+        StringBuffer response = new StringBuffer();
+        HttpResponse httpResponse = (HttpResponse) message.getBody().get(HttpResponse.RESPONSE_KEY);
+
+        response.append("Message Payload:\n");
+        response.append("\t" + message.getBody().get());
+
+        response.append("\n\nHttp Response:\n");
+        response.append("\tCode: " + httpResponse.getResponseCode() + "\n");
+        response.append("\tLength: " + httpResponse.getLength() + "\n");
+        response.append("\tEncoding: " + httpResponse.getEncoding() + "\n");
+
+        response.append("\tHeaders: \n");
+        List<HttpHeader> headers = httpResponse.getHeaders();
+        for (HttpHeader header : headers) {
+            response.append("\t\t" + header.getName() + ": " + header.getValue() + "\n");            
+        }
+        
+        System.out.println(response);
+
+        return message;
+    }
+
+
+}
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/HttpResponsePrinter.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/SendJMSMessage.java
===================================================================
--- labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/SendJMSMessage.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/SendJMSMessage.java	2008-02-22 18:41:49 UTC (rev 18564)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package runtest;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.soa.esb.util.FileUtil;
+
+public class SendJMSMessage {
+    QueueConnection conn;
+    QueueSession session;
+    Queue que;
+    
+    
+    public void setupConnection() throws JMSException, NamingException
+    {
+    	InitialContext iniCtx = new InitialContext();
+    	Object tmp = iniCtx.lookup("ConnectionFactory");
+    	QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+    	conn = qcf.createQueueConnection();
+    	que = (Queue) iniCtx.lookup("queue/quickstart_httprouter_gw");
+    	session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+    	conn.start();
+    	System.out.println("Connection Started");
+    }
+    
+    public void stop() throws JMSException 
+    { 
+        conn.stop();
+        session.close();
+        conn.close();
+    }
+    
+    public void sendAMessage() throws JMSException, FileNotFoundException, IOException {
+    	
+        QueueSender send = session.createSender(que);
+        ObjectMessage tm;
+        String message = "Hi there!";
+        
+        tm = session.createObjectMessage(message);
+        tm.setStringProperty("jbesbfilename", "httprouter.log");
+        send.send(tm);        
+        send.close();
+    }       
+    
+    public static void main(String args[]) throws Exception
+    {        	    	
+    	SendJMSMessage sm = new SendJMSMessage();
+    	sm.setupConnection();
+    	sm.sendAMessage(); 
+    	sm.stop();
+    }
+    
+}
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/HttpRouter/sample1/src/runtest/SendJMSMessage.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml	2008-02-22 16:37:38 UTC (rev 18563)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml	2008-02-22 18:41:49 UTC (rev 18564)
@@ -14,7 +14,7 @@
                 </groovy-listener>
             </listeners>
             <actions>
-                <action name="myaction" class="org.jboss.soa.esb.samples.quickstart.httptest.MyAction"/>
+                <action name="myaction" class="org.jboss.soa.esb.samples.quickstart.httptest.HttpRequestPrinter"/>
             </actions>
 
         </service>




More information about the jboss-svn-commits mailing list