diff --git a/activemq-optional/src/main/java/org/activemq/transport/http/HttpClientTransport.java b/activemq-optional/src/main/java/org/activemq/transport/http/HttpClientTransport.java index a7b30678e5..639ffc6020 100755 --- a/activemq-optional/src/main/java/org/activemq/transport/http/HttpClientTransport.java +++ b/activemq-optional/src/main/java/org/activemq/transport/http/HttpClientTransport.java @@ -24,6 +24,7 @@ import org.activemq.transport.FutureResponse; import org.activemq.transport.util.TextWireFormat; import org.activemq.util.IOExceptionSupport; import org.activemq.util.ServiceStopper; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; @@ -52,7 +53,6 @@ public class HttpClientTransport extends HttpTransportSupport { private String clientID; private String sessionID; - public HttpClientTransport(TextWireFormat wireFormat, URI remoteUrl) { super(wireFormat, remoteUrl); } @@ -62,9 +62,9 @@ public class HttpClientTransport extends HttpTransportSupport { } public void oneway(Command command) throws IOException { - if (command.getDataStructureType()==ConnectionInfo.DATA_STRUCTURE_TYPE) - clientID=((ConnectionInfo)command).getClientId(); - + if (command.getDataStructureType() == ConnectionInfo.DATA_STRUCTURE_TYPE) + clientID = ((ConnectionInfo) command).getClientId(); + PostMethod httpMethod = new PostMethod(getRemoteUrl().toString()); configureMethod(httpMethod); httpMethod.setRequestBody(getTextWireFormat().toString(command)); @@ -90,10 +90,10 @@ public class HttpClientTransport extends HttpTransportSupport { HttpClient httpClient = getReceiveHttpClient(); URI remoteUrl = getRemoteUrl(); while (!isClosed()) { - + GetMethod httpMethod = new GetMethod(remoteUrl.toString()); configureMethod(httpMethod); - + try { int answer = httpClient.executeMethod(httpMethod); if (answer != HttpStatus.SC_OK) { @@ -121,7 +121,6 @@ public class HttpClientTransport extends HttpTransportSupport { } } - // Properties // ------------------------------------------------------------------------- public HttpClient getSendHttpClient() { @@ -157,8 +156,8 @@ public class HttpClientTransport extends HttpTransportSupport { } protected void configureMethod(HttpMethod method) { - if (sessionID!=null) { - method.addRequestHeader("Cookie", "JSESSIONID="+sessionID); + if (sessionID != null) { + method.addRequestHeader("Cookie", "JSESSIONID=" + sessionID); } else if (clientID != null) { method.setRequestHeader("clientID", clientID); @@ -166,12 +165,15 @@ public class HttpClientTransport extends HttpTransportSupport { } protected void checkSession(HttpMethod client) { - String set_cookie=client.getRequestHeader("Set-Cookie").getValue(); - - if (set_cookie!=null && set_cookie.startsWith("JSESSIONID=")) { - String[] bits=set_cookie.split("[=;]"); - sessionID=bits[1]; + Header header = client.getRequestHeader("Set-Cookie"); + if (header != null) { + String set_cookie = header.getValue(); + + if (set_cookie != null && set_cookie.startsWith("JSESSIONID=")) { + String[] bits = set_cookie.split("[=;]"); + sessionID = bits[1]; + } } } - + } diff --git a/activemq-optional/src/main/java/org/activemq/transport/http/HttpTransportFactory.java b/activemq-optional/src/main/java/org/activemq/transport/http/HttpTransportFactory.java index e578256fb3..90e2e266ef 100755 --- a/activemq-optional/src/main/java/org/activemq/transport/http/HttpTransportFactory.java +++ b/activemq-optional/src/main/java/org/activemq/transport/http/HttpTransportFactory.java @@ -55,7 +55,9 @@ public class HttpTransportFactory extends TransportFactory { } protected Transport createTransport(URI location, WireFormat wf) throws MalformedURLException { - Transport transport = new HttpTransport(asTextWireFormat(wf), location); + TextWireFormat textWireFormat = asTextWireFormat(wf); + Transport transport = new HttpClientTransport(textWireFormat, location); + //Transport transport = new HttpTransport(textWireFormat, location); transport = new MutexTransport(transport); transport = new ResponseCorrelator(transport); return transport; diff --git a/activemq-optional/src/main/java/org/activemq/transport/http/HttpTunnelServlet.java b/activemq-optional/src/main/java/org/activemq/transport/http/HttpTunnelServlet.java index e5bf086e33..2e8b22e512 100755 --- a/activemq-optional/src/main/java/org/activemq/transport/http/HttpTunnelServlet.java +++ b/activemq-optional/src/main/java/org/activemq/transport/http/HttpTunnelServlet.java @@ -109,7 +109,7 @@ public class HttpTunnelServlet extends HttpServlet { ConnectionInfo info = (ConnectionInfo) command; request.getSession(true).setAttribute("clientID", info.getClientId()); } - if (command instanceof WireFormatInfo) { + else if (command instanceof WireFormatInfo) { WireFormatInfo info = (WireFormatInfo) command; if (!canProcessWireFormatVersion(info.getVersion())) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot process wire format of version: " + info.getVersion()); @@ -173,12 +173,14 @@ public class HttpTunnelServlet extends HttpServlet { listener.onAccept(answer); } else { + /* try { - answer.asyncRequest(ping); + answer.oneway(ping); } catch (IOException e) { log.warn("Failed to ping transport: " + e, e); } + */ } return answer; }