Commit in servicemix/base/src/main/java/org/servicemix/components/http on MAIN
HttpBindingSupport.java+68added 1.1
HttpInOnlyBinding.java+62added 1.1
HttpInOutBinding.java+671.3 -> 1.4
BindingServlet.java+21-121.1 -> 1.2
HttpBinding.java+11-721.2 -> 1.3
HttpConnector.java+2-31.3 -> 1.4
+231-87
2 added + 4 modified, total 6 files
refactor of the HTTP bindings to make them more reusable

servicemix/base/src/main/java/org/servicemix/components/http
HttpBindingSupport.java added at 1.1
diff -N HttpBindingSupport.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HttpBindingSupport.java	18 Aug 2005 18:28:25 -0000	1.1
@@ -0,0 +1,68 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix.components.http;
+
+import org.servicemix.components.util.ComponentSupport;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public abstract class HttpBindingSupport extends ComponentSupport implements HttpBinding {
+    // TODO is the correct?
+    protected static final int BAD_REQUEST_STATUS_CODE = HttpServletResponse.SC_BAD_GATEWAY;
+    private HttpMarshaler marshaler;
+
+    public HttpMarshaler getMarshaler() {
+        if (marshaler == null) {
+            marshaler = createMarshaler();
+        }
+        return marshaler;
+    }
+
+    public void setMarshaler(HttpMarshaler marshaler) {
+        this.marshaler = marshaler;
+    }
+
+    public abstract void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+            JBIException;
+
+    /**
+     * A factory method used to create the default [EMAIL PROTECTED] HttpMarshaler} to be used to turn the request into a
+     * [EMAIL PROTECTED] NormalizedMessage} and to turn a normalized message into a response.
+     *
+     * @return the newly created marshaler
+     */
+    protected HttpMarshaler createMarshaler() {
+      return new HttpMarshaler();
+    }
+
+    protected void outputException(HttpServletResponse response, Exception e) throws IOException {
+        response.setStatus(BAD_REQUEST_STATUS_CODE);
+        PrintWriter writer = response.getWriter();
+        writer.println("Request failed with error: " + e);
+        e.printStackTrace(writer);
+    }
+}

servicemix/base/src/main/java/org/servicemix/components/http
HttpInOnlyBinding.java added at 1.1
diff -N HttpInOnlyBinding.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HttpInOnlyBinding.java	18 Aug 2005 18:28:25 -0000	1.1
@@ -0,0 +1,62 @@
+/** 
+ * 
+ * Copyright 2005 Protique Ltd
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+
+package org.servicemix.components.http;
+
+import org.servicemix.components.util.ComponentSupport;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.InOnly;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerException;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * A HTTP Binding Component which performs an [EMAIL PROTECTED] InOnly} exchange with JBI and returns the response.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class HttpInOnlyBinding extends HttpBindingSupport {
+
+    public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+            JBIException {
+        //response.setContentType("application/soap+xml");
+        MessageExchangeFactory factory = getExchangeFactory();
+        InOnly messageExchange = factory.createInOnlyExchange();
+        NormalizedMessage inMessage = messageExchange.createMessage();
+        try {
+            HttpMarshaler marshaler = getMarshaler();
+            marshaler.toNMS(inMessage, request);
+            messageExchange.setInMessage(inMessage);
+            done(messageExchange);
+            response.setStatus(HttpServletResponse.SC_OK);
+        }
+        catch (IOException e) {
+            fail(messageExchange, e);
+            outputException(response, e);
+        }
+    }
+}

servicemix/base/src/main/java/org/servicemix/components/http
HttpInOutBinding.java 1.3 -> 1.4
diff -N HttpInOutBinding.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HttpInOutBinding.java	18 Aug 2005 18:28:25 -0000	1.4
@@ -0,0 +1,67 @@
+/** 
+ * 
+ * Copyright 2005 Protique Ltd
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+
+package org.servicemix.components.http;
+
+import org.servicemix.components.util.ComponentSupport;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerException;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * A HTTP Binding Component which performs an [EMAIL PROTECTED] InOut} exchange with JBI and returns the response.
+ *
+ * @version $Revision: 1.4 $
+ */
+public class HttpInOutBinding extends HttpBindingSupport {
+
+    public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+            JBIException {
+        //response.setContentType("application/soap+xml");
+        MessageExchangeFactory factory = getExchangeFactory();
+        InOut messageExchange = factory.createInOutExchange();
+        NormalizedMessage inMessage = messageExchange.createMessage();
+        try {
+            getMarshaler().toNMS(inMessage, request);
+            messageExchange.setInMessage(inMessage);
+            boolean result = getDeliveryChannel().sendSync(messageExchange);
+            if (result) {
+                getMarshaler().toResponse(messageExchange.getOutMessage(), response);
+            }
+        }
+        catch (IOException e) {
+            fail(messageExchange, e);
+            outputException(response, e);
+        }
+        catch (TransformerException e) {
+            fail(messageExchange, e);
+            outputException(response, e);
+        }
+    }
+
+}

servicemix/base/src/main/java/org/servicemix/components/http
BindingServlet.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- BindingServlet.java	12 Jul 2005 17:55:35 -0000	1.1
+++ BindingServlet.java	18 Aug 2005 18:28:25 -0000	1.2
@@ -28,17 +28,34 @@
 /**
  * A Servlet which dispatches requests into the JBI container and returns the result.
  *
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
  */
 public class BindingServlet extends HttpServlet {
 
     private HttpBinding binding;
 
+    /**
+     * get da binding
+     *
+     * @return the binding
+     */
+    public HttpBinding getBinding() {
+        return binding;
+    }
+
+    public void setBinding(HttpBinding binding) {
+        this.binding = binding;
+    }
+
+
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
         if (binding == null) {
             binding = (HttpBinding) getServletContext().getAttribute("binding");
             if (binding == null) {
+                binding = createHttpBinding(config);
+            }
+                if (binding == null) {
                 throw new ServletException("No binding property available on the servlet context");
             }
         }
@@ -53,17 +70,9 @@
         }
     }
 
-    /**
-     * get da binding
-     *
-     * @return the binding
-     */
-    public HttpBinding getBinding() {
-        return binding;
-    }
-
-    public void setBinding(HttpBinding binding) {
-        this.binding = binding;
+    protected HttpBinding createHttpBinding(ServletConfig config) {
+        // lets default to in/out
+        return new HttpInOutBinding();
     }
 
 }

servicemix/base/src/main/java/org/servicemix/components/http
HttpBinding.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HttpBinding.java	17 Aug 2005 10:34:25 -0000	1.2
+++ HttpBinding.java	18 Aug 2005 18:28:25 -0000	1.3
@@ -1,6 +1,6 @@
-/** 
+/**
  * 
- * Copyright 2005 Protique Ltd
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
  * 
  * Licensed under the Apache License, Version 2.0 (the "License"); 
  * you may not use this file except in compliance with the License. 
@@ -15,92 +15,31 @@
  * limitations under the License. 
  * 
  **/
-
 package org.servicemix.components.http;
 
-import org.servicemix.components.util.ComponentSupport;
-import org.servicemix.jbi.jaxp.SourceTransformer;
-
-import javax.jbi.JBIException;
-import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchangeFactory;
-import javax.jbi.messaging.NormalizedMessage;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.TransformerException;
+import javax.jbi.JBIException;
 import java.io.IOException;
-import java.io.PrintWriter;
 
 /**
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  */
-public class HttpBinding extends ComponentSupport {
-    // TODO is the correct?
-    protected static final int BAD_REQUEST_STATUS_CODE = HttpServletResponse.SC_BAD_GATEWAY;
-
-    private HttpMarshaler marshaler;
+public interface HttpBinding {
+    HttpMarshaler getMarshaler();
 
-    public HttpMarshaler getMarshaler() {
-        if (marshaler == null) {
-            marshaler = createMarshaler();
-        }
-        return marshaler;
-    }
-
-    public void setMarshaler(HttpMarshaler marshaler) {
-        this.marshaler = marshaler;
-    }
+    void setMarshaler(HttpMarshaler marshaler);
 
     /**
+     * Invokes the HTTP request from a servlet
+     * 
      * @param request
      * @param response
      * @throws ServletException
      * @throws IOException
      * @throws JBIException
      */
-    public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
-            JBIException {
-        //response.setContentType("application/soap+xml");
-        MessageExchangeFactory factory = getExchangeFactory();
-        InOut messageExchange = factory.createInOutExchange();
-        NormalizedMessage inMessage = messageExchange.createMessage();
-        try {
-            getMarshaler().toNMS(inMessage, request);
-            messageExchange.setInMessage(inMessage);
-            boolean result = getDeliveryChannel().sendSync(messageExchange);
-            if (result) {
-                getMarshaler().toResponse(messageExchange.getOutMessage(), response);
-            }
-        }
-        catch (IOException e) {
-            fail(messageExchange, e);
-            outputException(response, e);
-        }
-        catch (TransformerException e) {
-            fail(messageExchange, e);
-            outputException(response, e);
-        }
-    }
-
-    // Implementation methods
-    //-------------------------------------------------------------------------
-
-    /**
-     * A factory method used to create the default [EMAIL PROTECTED] HttpMarshaler} to be used to turn the request into a
-     * [EMAIL PROTECTED] NormalizedMessage} and to turn a normalized message into a response.
-     *
-     * @return the newly created marshaler
-     */
-    protected HttpMarshaler createMarshaler() {
-      return new HttpMarshaler();
-    }
-
-    protected void outputException(HttpServletResponse response, Exception e) throws IOException {
-        response.setStatus(BAD_REQUEST_STATUS_CODE);
-        PrintWriter writer = response.getWriter();
-        writer.println("Request failed with error: " + e);
-        e.printStackTrace(writer);
-    }
+    void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+            JBIException;
 }

servicemix/base/src/main/java/org/servicemix/components/http
HttpConnector.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- HttpConnector.java	12 Jul 2005 17:55:35 -0000	1.3
+++ HttpConnector.java	18 Aug 2005 18:28:25 -0000	1.4
@@ -22,7 +22,6 @@
 import org.mortbay.http.SocketListener;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.ServletHandler;
-import org.servicemix.components.util.ComponentSupport;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
@@ -31,9 +30,9 @@
 /**
  * An embedded Servlet engine to implement a HTTP connector
  *
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
-public class HttpConnector extends HttpBinding {
+public class HttpConnector extends HttpInOutBinding {
     private SocketListener listener = new SocketListener();
     private Server server;
     private String host;
CVSspam 0.2.8



Reply via email to