mirror of https://github.com/apache/activemq.git
- server should set a error code if no clientID was specified.
- client should avoid doing a GET until the clientID is specified. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@386272 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2133fb7c91
commit
ea94429a2f
|
@ -52,8 +52,17 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
|
||||
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 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
}
|
||||
}
|
||||
}
|
||||
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 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,18 +16,11 @@
|
|||
*/
|
||||
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 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;
|
||||
import org.apache.activemq.transport.xstream.XStreamWireFormat;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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;
|
||||
|
@ -35,11 +28,17 @@ 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 org.apache.activemq.command.Command;
|
||||
import org.apache.activemq.command.ConnectionInfo;
|
||||
import org.apache.activemq.command.WireFormatInfo;
|
||||
import org.apache.activemq.transport.TransportAcceptListener;
|
||||
import org.apache.activemq.transport.util.TextWireFormat;
|
||||
import org.apache.activemq.transport.xstream.XStreamWireFormat;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||
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 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||
try {
|
||||
BlockingQueueTransport transportChannel = getTransportChannel(request);
|
||||
if (transportChannel == null) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "clientID not specified.");
|
||||
log("No transport available! ");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue