activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r386272 - in /incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http: HttpTransport.java HttpTunnelServlet.java
Date Thu, 16 Mar 2006 06:11:39 GMT
Author: chirino
Date: Wed Mar 15 22:11:37 2006
New Revision: 386272

URL: http://svn.apache.org/viewcvs?rev=386272&view=rev
Log:
- server should set a error code if no clientID was specified.
- client should avoid doing a GET until the clientID is specified.

Modified:
    incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java
    incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java

Modified: incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java?rev=386272&r1=386271&r2=386272&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java
(original)
+++ incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransport.java
Wed Mar 15 22:11:37 2006
@@ -52,8 +52,17 @@
 
     public void oneway(Command command) throws IOException {
         try {
-            if (command.getDataStructureType()==ConnectionInfo.DATA_STRUCTURE_TYPE)
+            if (command.getDataStructureType()==ConnectionInfo.DATA_STRUCTURE_TYPE) {
+                boolean startGetThread = clientID==null;
                 clientID=((ConnectionInfo)command).getClientId();
+                if( startGetThread && isStarted() ) {
+                    try {
+                        super.doStart();
+                    } catch (Exception e) {
+                        throw IOExceptionSupport.create(e);
+                    }
+                }
+            }
             
             HttpURLConnection connection = getSendConnection();
             String text = getTextWireFormat().toString(command);
@@ -98,13 +107,16 @@
                     }
                 }
             }
-            catch (Exception e) {
+            catch (Throwable e) {
                 if (!isStopped()) {
                     log.error("Failed to perform GET on: " + remoteUrl + " due to: " + e,
e);
                 }
                 else {
                     log.trace("Caught error after closed: " + e, e);
                 }
+            } finally {
+                safeClose(receiveConnection);
+                receiveConnection=null;
             }
         }
     }
@@ -167,35 +179,43 @@
     }
 
     protected void setSendConnection(HttpURLConnection conn) {
-        if (sendConnection != null) {
-            sendConnection.disconnect();
-        }
+        safeClose(sendConnection);
         sendConnection = conn;
     }
 
     protected void setReceiveConnection(HttpURLConnection conn) {
-        if (receiveConnection != null) {
-            receiveConnection.disconnect();
-        }
+        safeClose(receiveConnection);
         receiveConnection = conn;
     }
 
-    protected void doStop(ServiceStopper stopper) throws Exception {
-        if (sendConnection != null) {
-            stopper.run(new Callback() {
-                public void execute() throws Exception {
-                    sendConnection.disconnect();
-                }
-            });
-            sendConnection = null;
+    protected void doStart() throws Exception {
+        // Don't start the background thread until the clientId has been established.
+        if( clientID != null ) {
+            super.doStart();
         }
-        if (receiveConnection != null) {
-            stopper.run(new Callback() {
-                public void execute() throws Exception {
-                    receiveConnection.disconnect();
-                }
-            });
-            receiveConnection = null;
+    }
+    
+    protected void doStop(ServiceStopper stopper) throws Exception {
+        stopper.run(new Callback() {
+            public void execute() throws Exception {
+                safeClose(sendConnection);
+            }
+        });
+        sendConnection = null;
+        stopper.run(new Callback() {
+            public void execute() {
+                safeClose(receiveConnection);
+            }
+        });
+    }
+    
+    /**
+     * @param connection TODO
+     * 
+     */
+    private void safeClose(HttpURLConnection connection) {
+        if( connection!=null ) {
+            connection.disconnect();
         }
     }
 

Modified: incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java?rev=386272&r1=386271&r2=386272&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
(original)
+++ incubator/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
Wed Mar 15 22:11:37 2006
@@ -16,12 +16,20 @@
  */
 package org.apache.activemq.transport.http;
 
-import edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue;
-import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 
 import org.apache.activemq.command.Command;
 import org.apache.activemq.command.ConnectionInfo;
-import org.apache.activemq.command.KeepAliveInfo;
 import org.apache.activemq.command.WireFormatInfo;
 import org.apache.activemq.transport.TransportAcceptListener;
 import org.apache.activemq.transport.util.TextWireFormat;
@@ -29,17 +37,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 
 /**
  * A servlet which handles server side HTTP transport, delegating to the
@@ -56,7 +55,6 @@
     private TextWireFormat wireFormat;
     private Map clients = new HashMap();
     private long requestTimeout = 30000L;
-    private KeepAliveInfo ping = new KeepAliveInfo();
 
     public void init() throws ServletException {
         super.init();
@@ -76,6 +74,7 @@
         try {
             BlockingQueueTransport transportChannel = getTransportChannel(request);
             if (transportChannel == null) {
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "clientID not specified.");
                 log("No transport available! ");
                 return;
             }



Mime
View raw message