use commons-httpclient by default

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@359551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2005-12-28 15:38:10 +00:00
parent 81a9575424
commit 0684e20bf6
3 changed files with 24 additions and 18 deletions

View File

@ -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];
}
}
}
}

View File

@ -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;

View File

@ -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;
}