mirror of
https://github.com/apache/activemq.git
synced 2025-03-02 14:19:10 +00:00
- 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 {
|
public void oneway(Command command) throws IOException {
|
||||||
try {
|
try {
|
||||||
if (command.getDataStructureType()==ConnectionInfo.DATA_STRUCTURE_TYPE)
|
if (command.getDataStructureType()==ConnectionInfo.DATA_STRUCTURE_TYPE) {
|
||||||
|
boolean startGetThread = clientID==null;
|
||||||
clientID=((ConnectionInfo)command).getClientId();
|
clientID=((ConnectionInfo)command).getClientId();
|
||||||
|
if( startGetThread && isStarted() ) {
|
||||||
|
try {
|
||||||
|
super.doStart();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw IOExceptionSupport.create(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HttpURLConnection connection = getSendConnection();
|
HttpURLConnection connection = getSendConnection();
|
||||||
String text = getTextWireFormat().toString(command);
|
String text = getTextWireFormat().toString(command);
|
||||||
@ -98,13 +107,16 @@ public class HttpTransport extends HttpTransportSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Throwable e) {
|
||||||
if (!isStopped()) {
|
if (!isStopped()) {
|
||||||
log.error("Failed to perform GET on: " + remoteUrl + " due to: " + e, e);
|
log.error("Failed to perform GET on: " + remoteUrl + " due to: " + e, e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.trace("Caught error after closed: " + e, e);
|
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) {
|
protected void setSendConnection(HttpURLConnection conn) {
|
||||||
if (sendConnection != null) {
|
safeClose(sendConnection);
|
||||||
sendConnection.disconnect();
|
|
||||||
}
|
|
||||||
sendConnection = conn;
|
sendConnection = conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setReceiveConnection(HttpURLConnection conn) {
|
protected void setReceiveConnection(HttpURLConnection conn) {
|
||||||
if (receiveConnection != null) {
|
safeClose(receiveConnection);
|
||||||
receiveConnection.disconnect();
|
|
||||||
}
|
|
||||||
receiveConnection = conn;
|
receiveConnection = conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doStop(ServiceStopper stopper) throws Exception {
|
protected void doStart() throws Exception {
|
||||||
if (sendConnection != null) {
|
// Don't start the background thread until the clientId has been established.
|
||||||
stopper.run(new Callback() {
|
if( clientID != null ) {
|
||||||
public void execute() throws Exception {
|
super.doStart();
|
||||||
sendConnection.disconnect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sendConnection = null;
|
|
||||||
}
|
}
|
||||||
if (receiveConnection != null) {
|
}
|
||||||
stopper.run(new Callback() {
|
|
||||||
public void execute() throws Exception {
|
protected void doStop(ServiceStopper stopper) throws Exception {
|
||||||
receiveConnection.disconnect();
|
stopper.run(new Callback() {
|
||||||
}
|
public void execute() throws Exception {
|
||||||
});
|
safeClose(sendConnection);
|
||||||
receiveConnection = null;
|
}
|
||||||
|
});
|
||||||
|
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;
|
package org.apache.activemq.transport.http;
|
||||||
|
|
||||||
import edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue;
|
import java.io.BufferedReader;
|
||||||
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import org.apache.activemq.command.Command;
|
import java.util.HashMap;
|
||||||
import org.apache.activemq.command.ConnectionInfo;
|
import java.util.Map;
|
||||||
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 javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
@ -35,11 +28,17 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import org.apache.activemq.command.Command;
|
||||||
import java.io.DataOutputStream;
|
import org.apache.activemq.command.ConnectionInfo;
|
||||||
import java.io.IOException;
|
import org.apache.activemq.command.WireFormatInfo;
|
||||||
import java.util.HashMap;
|
import org.apache.activemq.transport.TransportAcceptListener;
|
||||||
import java.util.Map;
|
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
|
* A servlet which handles server side HTTP transport, delegating to the
|
||||||
@ -56,7 +55,6 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||||||
private TextWireFormat wireFormat;
|
private TextWireFormat wireFormat;
|
||||||
private Map clients = new HashMap();
|
private Map clients = new HashMap();
|
||||||
private long requestTimeout = 30000L;
|
private long requestTimeout = 30000L;
|
||||||
private KeepAliveInfo ping = new KeepAliveInfo();
|
|
||||||
|
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
@ -76,6 +74,7 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||||||
try {
|
try {
|
||||||
BlockingQueueTransport transportChannel = getTransportChannel(request);
|
BlockingQueueTransport transportChannel = getTransportChannel(request);
|
||||||
if (transportChannel == null) {
|
if (transportChannel == null) {
|
||||||
|
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "clientID not specified.");
|
||||||
log("No transport available! ");
|
log("No transport available! ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user