[jboss-svn-commits] JBL Code SVN: r18554 - in labs/jbossesb/workspace/sandbox: jetty and 15 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 21 12:01:50 EST 2008


Author: tfennelly
Date: 2008-02-21 12:01:50 -0500 (Thu, 21 Feb 2008)
New Revision: 18554

Added:
   labs/jbossesb/workspace/sandbox/jetty/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/build.xml
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-6.1.6rc0.jar
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-util-6.1.6rc0.jar
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/readme.txt
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/server-12345.xml
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/http/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/http/HttpInvocation.java
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/JettyGateway.java
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/RequestHandler.java
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/scripts/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/scripts/JettyGateway.groovy
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/MyAction.java
   labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/test/
Log:
Added jetty gateway sample

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/build.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/build.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/build.xml	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,13 @@
+<project name="jetty_http_gateway_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"/>
+
+</project>


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

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/jboss-esb.xml	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,24 @@
+<?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">
+
+    <services>                 
+
+        <service category="MyServiceCategory" name="MyHTTPService" description="HTTP Gateway example">
+
+            <listeners>
+                <groovy-listener name="Http-12345" script="JettyGateway">
+                    <property name="jettyConfig" value="/server-12345.xml" />
+                    <!-- property name="port" value="12345" / -->
+                </groovy-listener>
+            </listeners>
+            <actions>
+                <action name="myaction" class="org.jboss.soa.esb.samples.quickstart.httptest.MyAction"/>
+            </actions>
+
+        </service>
+
+    </services>
+
+</jbossesb>


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

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-6.1.6rc0.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-6.1.6rc0.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-util-6.1.6rc0.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/sandbox/jetty/quickstart1/lib/jetty-util-6.1.6rc0.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/readme.txt
===================================================================

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/server-12345.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/server-12345.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/server-12345.xml	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,16 @@
+<?xml version="1.0"  encoding="ISO-8859-1"?>
+<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
+<Configure id="Server" class="org.mortbay.jetty.Server">
+
+    <Call name="addConnector">
+        <Arg>
+            <New class="org.mortbay.jetty.nio.SelectChannelConnector">
+                <Set name="port">12345</Set>
+            </New>
+        </Arg>
+    </Call>
+
+    <!-- Confige a HTTPS connector ala
+         http://docs.codehaus.org/display/JETTY/Ssl+Connector+Guide -->
+
+</Configure>
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/jetty/quickstart1/server-12345.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/http/HttpInvocation.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/http/HttpInvocation.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/http/HttpInvocation.java	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,56 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class HttpInvocation implements Serializable {
+
+    public static final String METHOD_KEY = HttpInvocation.class.getName() + "#method";
+    public static final String TARGET_KEY = HttpInvocation.class.getName() + "#target";
+    public static final String INVOCATION_KEY = HttpInvocation.class.getName() + "#invocation";
+
+    private String target;
+    private HttpServletRequest httpRequest;
+    private HttpServletResponse httpResponse;
+
+    public HttpInvocation(String target, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
+        this.target = target;
+        this.httpRequest = httpRequest;
+        this.httpResponse = httpResponse;
+    }
+
+    public String getTarget() {
+        return target;
+    }
+
+    public HttpServletRequest getHttpRequest() {
+        return httpRequest;
+    }
+
+    public HttpServletResponse getHttpResponse() {
+        return httpResponse;
+    }
+}


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

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/JettyGateway.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/JettyGateway.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/JettyGateway.java	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,92 @@
+/*
+ * 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.jetty;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.xml.XmlConfiguration;
+
+import java.io.InputStream;
+
+/**
+ * Jetty Gateway.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JettyGateway {
+
+    private Server server;
+    private String jettyConfig;
+    private ConfigTree config;
+
+    public JettyGateway(ConfigTree config) throws ConfigurationException {
+        AssertArgument.isNotNull(config, "config");
+        this.config = config;
+
+        jettyConfig = config.getAttribute("jettyConfig");
+    }
+
+    public void start() throws Exception {
+        server = new Server();
+
+        if(jettyConfig != null) {
+            InputStream jettyConfigStream = getClass().getResourceAsStream(jettyConfig);
+
+            if(jettyConfigStream == null) {
+                throw new ConfigurationException("Failed to locate Jetty Server configuration '" + jettyConfig + "' on the classpath.");
+            }
+            XmlConfiguration xmlConfig = new XmlConfiguration(jettyConfigStream);
+            xmlConfig.configure(server);
+
+            Connector[] connectors = server.getConnectors();
+            if(connectors == null || connectors.length == 0) {
+                configureConnector();
+            }
+        } else {
+            configureConnector();
+        }
+
+        server.setHandler(new RequestHandler(config));
+        server.start();
+    }
+
+    private void configureConnector() throws ConfigurationException {
+        try {
+            Connector connector = new SocketConnector();
+            int port = Integer.parseInt(config.getRequiredAttribute("port"));
+            
+            connector.setPort(port);
+            server.setConnectors(new Connector[]{connector});
+        } catch(NumberFormatException e) {
+            throw new ConfigurationException("Config property 'port' must be a valid integer.");
+        }
+    }
+
+    public void stop() throws Exception {
+        server.stop();
+        while(!server.isStopped()) {
+            Thread.sleep(100);
+        }
+    }
+}


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

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/RequestHandler.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/RequestHandler.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/jetty/RequestHandler.java	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,128 @@
+/*
+ * 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.jetty;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.http.HttpInvocation;
+import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.Request;
+import org.mortbay.jetty.handler.AbstractHandler;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class RequestHandler extends AbstractHandler {
+
+    private static Logger logger = Logger.getLogger(RequestHandler.class);
+
+    private ActionProcessingPipeline pipeline;
+    private ConfigTree config;
+    private boolean postAsStream;
+
+    public RequestHandler(ConfigTree config) {
+        this.config = config;
+        postAsStream = config.getBooleanAttribute("postAsStream", false);
+    }
+
+    protected void doStart() throws Exception {
+        pipeline = new ActionProcessingPipeline(config);
+        pipeline.initialise();
+        super.doStart();
+        logger.info("Jetty Gateway '" + config.getName() + "' Started.");
+    }
+
+    public void handle(String target, HttpServletRequest httpServletRequest,
+                       HttpServletResponse httpServletResponse,
+                       int dispatch) throws IOException, ServletException {
+
+        Request base_request = (httpServletRequest instanceof Request) ? (Request)httpServletRequest: HttpConnection.getCurrentConnection().getRequest();
+        Message message = MessageFactory.getInstance().getMessage();
+        HttpInvocation invocation = new HttpInvocation(target, httpServletRequest, httpServletResponse);
+
+        base_request.setHandled(true);
+
+        String method = httpServletRequest.getMethod();
+        if(method.equals("POST")) {
+            ServletInputStream payloadStream = httpServletRequest.getInputStream();
+            if(postAsStream) {
+                message.getBody().add(payloadStream);
+            } else {
+                try {
+                    String payload = StreamUtils.readStreamString(payloadStream, httpServletRequest.getCharacterEncoding());
+                    message.getBody().add(payload);
+                } finally {
+                    payloadStream.close();
+                }
+            }
+        } else {
+            String query = httpServletRequest.getQueryString();
+            if(query != null) {
+                message.getBody().add(target + "?" + query);
+            } else {
+                message.getBody().add(target);
+            }
+        }
+        message.getProperties().setProperty(HttpInvocation.METHOD_KEY, method);
+        message.getProperties().setProperty(HttpInvocation.TARGET_KEY, target);
+        message.getBody().add(HttpInvocation.INVOCATION_KEY, invocation); // Setting this on the body because we don't have a proper execution context for the pipeline :-(
+
+        boolean success = false;
+        try {
+            success = pipeline.process(message);
+        } finally {
+            if(!httpServletResponse.isCommitted()) {
+                if(httpServletResponse.getContentType() == null) {
+                    httpServletResponse.setContentType("text/xml");
+                }
+                if(success) {
+                    // Can't get the "last" message from the pipeline because it assumes
+                    // async/reply-tos etc
+                    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
+                    httpServletResponse.getWriter().write(message.getBody().get().toString());
+                } else {
+                    httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    httpServletResponse.getWriter().write(message.getFault().getReason());
+                }
+            }
+        }
+    }
+
+    protected void doStop() throws Exception {
+        try {
+            if(pipeline != null) {
+                pipeline.destroy() ;
+            }
+        } finally {
+            super.doStop();
+            logger.info("Jetty Gateway '" + config.getName() + "' Stopped.");
+        }
+    }
+}


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

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/scripts/JettyGateway.groovy
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/scripts/JettyGateway.groovy	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/listeners/gateway/scripts/JettyGateway.groovy	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,15 @@
+import org.jboss.soa.esb.jetty.JettyGateway;
+
+JettyGateway jettyGateway = new JettyGateway(config);
+
+// Start the JettyGateway...
+jettyGateway.start();
+
+// Wait until the Groovy Gateway is signaled to stop...
+def stopped = false;
+while(!stopped) {
+    stopped = gateway.waitUntilStopping(200);
+}
+
+// Now stop the JettyGateway...
+jettyGateway.stop();
\ No newline at end of file

Added: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/MyAction.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/MyAction.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/MyAction.java	2008-02-21 17:01:50 UTC (rev 18554)
@@ -0,0 +1,49 @@
+package org.jboss.soa.esb.samples.quickstart.httptest;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.http.HttpInvocation;
+import org.jboss.soa.esb.message.Message;
+
+public class MyAction extends AbstractActionLifecycle {
+
+    protected ConfigTree _config;
+
+    public MyAction(ConfigTree config) {
+        _config = config;
+    }
+
+
+    public Message process(Message message) throws Exception {
+
+        StringBuffer response = new StringBuffer();
+        HttpInvocation invocation = (HttpInvocation) message.getBody().get(HttpInvocation.INVOCATION_KEY);
+
+        response.append("<pre>\n");
+
+        response.append("Message Payload:\n");
+        response.append("\t" + message.getBody().get());
+
+        response.append("\n\nTarget:\n");
+        response.append("\t" + invocation.getTarget());
+
+        response.append("\n\nRequest:\n");
+        response.append("\tPathInfo: " + invocation.getHttpRequest().getPathInfo() + "\n");
+        response.append("\tQuery String: " + invocation.getHttpRequest().getQueryString() + "\n");
+        response.append("\tQuery Params: " + invocation.getHttpRequest().getParameterMap() + "\n");
+
+        response.append("\n\nResponse:\n");
+        response.append("\tClass: " + invocation.getHttpResponse().getClass().getName() + "\n");
+        response.append("\tIsCommited: " + invocation.getHttpResponse().isCommitted() + "\n");
+
+        response.append("</pre>");
+
+        message.getBody().add(response.toString());
+
+        invocation.getHttpResponse().setContentType("text/html");
+
+        return message;
+    }
+
+
+}
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/jetty/quickstart1/src/org/jboss/soa/esb/samples/quickstart/httptest/MyAction.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list