mirror of https://github.com/apache/activemq.git
- Temporarily disabled using session cookies to store clientID. Does not seem to work in https.
- Modified HttpsTransportServer to use the doStart format. - Added test cases for https. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@385699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f471303cc5
commit
7531e3ea4a
|
@ -52,7 +52,7 @@ public class HttpClientTransport extends HttpTransportSupport {
|
|||
private HttpClient sendHttpClient;
|
||||
private HttpClient receiveHttpClient;
|
||||
private String clientID;
|
||||
private String sessionID;
|
||||
// private String sessionID;
|
||||
|
||||
public HttpClientTransport(TextWireFormat wireFormat, URI remoteUrl) {
|
||||
super(wireFormat, remoteUrl);
|
||||
|
@ -76,9 +76,8 @@ public class HttpClientTransport extends HttpTransportSupport {
|
|||
if (answer != HttpStatus.SC_OK) {
|
||||
throw new IOException("Failed to post command: " + command + " as response was: " + answer);
|
||||
}
|
||||
checkSession(httpMethod);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// checkSession(httpMethod);
|
||||
} catch (IOException e) {
|
||||
throw IOExceptionSupport.create("Could not post command: " + command + " due to: " + e, e);
|
||||
} finally {
|
||||
httpMethod.getResponseBody();
|
||||
|
@ -110,7 +109,7 @@ public class HttpClientTransport extends HttpTransportSupport {
|
|||
}
|
||||
}
|
||||
else {
|
||||
checkSession(httpMethod);
|
||||
// checkSession(httpMethod);
|
||||
Command command = getTextWireFormat().readCommand(new DataInputStream(httpMethod.getResponseBodyAsStream()));
|
||||
if (command == null) {
|
||||
log.warn("Received null command from url: " + remoteUrl);
|
||||
|
@ -164,24 +163,25 @@ public class HttpClientTransport extends HttpTransportSupport {
|
|||
}
|
||||
|
||||
protected void configureMethod(HttpMethod method) {
|
||||
if (sessionID != null) {
|
||||
method.addRequestHeader("Cookie", "JSESSIONID=" + sessionID);
|
||||
}
|
||||
else if (clientID != null) {
|
||||
// if (sessionID != null) {
|
||||
// method.addRequestHeader("Cookie", "JSESSIONID=" + sessionID);
|
||||
// }
|
||||
// else
|
||||
if (clientID != null) {
|
||||
method.setRequestHeader("clientID", clientID);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkSession(HttpMethod client) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
// protected void checkSession(HttpMethod client) {
|
||||
// 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];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
private HttpURLConnection receiveConnection;
|
||||
private URL url;
|
||||
private String clientID;
|
||||
private String sessionID;
|
||||
// private String sessionID;
|
||||
|
||||
public HttpTransport(TextWireFormat wireFormat, URI remoteUrl) throws MalformedURLException {
|
||||
super(wireFormat, remoteUrl);
|
||||
|
@ -64,8 +64,7 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
if (answer != HttpURLConnection.HTTP_OK) {
|
||||
throw new IOException("Failed to post command: " + command + " as response was: " + answer);
|
||||
}
|
||||
checkSession(connection);
|
||||
|
||||
// checkSession(connection);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw IOExceptionSupport.create("Could not post command: " + command + " due to: " + e, e);
|
||||
|
@ -88,7 +87,7 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
}
|
||||
}
|
||||
else {
|
||||
checkSession(connection);
|
||||
// checkSession(connection);
|
||||
Command command = getTextWireFormat().readCommand(new DataInputStream(connection.getInputStream()));
|
||||
|
||||
if (command == null) {
|
||||
|
@ -133,21 +132,22 @@ public class HttpTransport extends HttpTransportSupport {
|
|||
return conn;
|
||||
}
|
||||
|
||||
protected void checkSession(HttpURLConnection connection)
|
||||
{
|
||||
String set_cookie=connection.getHeaderField("Set-Cookie");
|
||||
if (set_cookie!=null && set_cookie.startsWith("JSESSIONID="))
|
||||
{
|
||||
String[] bits=set_cookie.split("[=;]");
|
||||
sessionID=bits[1];
|
||||
}
|
||||
}
|
||||
// protected void checkSession(HttpURLConnection connection)
|
||||
// {
|
||||
// String set_cookie=connection.getHeaderField("Set-Cookie");
|
||||
// if (set_cookie!=null && set_cookie.startsWith("JSESSIONID="))
|
||||
// {
|
||||
// String[] bits=set_cookie.split("[=;]");
|
||||
// sessionID=bits[1];
|
||||
// }
|
||||
// }
|
||||
|
||||
protected void configureConnection(HttpURLConnection connection) {
|
||||
if (sessionID !=null) {
|
||||
connection.addRequestProperty("Cookie", "JSESSIONID="+sessionID);
|
||||
}
|
||||
else if (clientID != null) {
|
||||
// if (sessionID !=null) {
|
||||
// connection.addRequestProperty("Cookie", "JSESSIONID="+sessionID);
|
||||
// }
|
||||
// else
|
||||
if (clientID != null) {
|
||||
connection.setRequestProperty("clientID", clientID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class HttpsTransportServer extends HttpTransportServer {
|
|||
super( uri );
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
public void doStart() throws Exception {
|
||||
SslSocketConnector sslConnector = new SslSocketConnector();
|
||||
sslConnector.setKeystore( keyStore );
|
||||
sslConnector.setPassword( keyStorePassword );
|
||||
|
@ -55,7 +55,7 @@ public class HttpsTransportServer extends HttpTransportServer {
|
|||
|
||||
setConnector(sslConnector);
|
||||
|
||||
super.start();
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
// Properties
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.transport.https;
|
||||
|
||||
import org.apache.activemq.transport.http.HttpJmsSendAndReceiveTest;
|
||||
|
||||
/**
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class HttpsJmsSendAndReceiveTest extends HttpJmsSendAndReceiveTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("javax.net.ssl.trustStore", "src/test/resources/client.keystore");
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", "password");
|
||||
System.setProperty("javax.net.ssl.trustStoreType", "jks");
|
||||
System.setProperty("javax.net.ssl.keyStore", "src/test/resources/server.keystore");
|
||||
System.setProperty("javax.net.ssl.keyStorePassword", "password");
|
||||
System.setProperty("javax.net.ssl.keyStoreType", "jks");
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected String getBrokerURL() {
|
||||
return "https://localhost:8161";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.transport.https;
|
||||
|
||||
import org.apache.activemq.transport.http.HttpTransportBrokerTest;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
public class HttpsTransportBrokerTest extends HttpTransportBrokerTest {
|
||||
|
||||
protected String getBindLocation() {
|
||||
return "https://localhost:8161";
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("javax.net.ssl.trustStore", "src/test/resources/client.keystore");
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", "password");
|
||||
System.setProperty("javax.net.ssl.trustStoreType", "jks");
|
||||
System.setProperty("javax.net.ssl.keyStore", "src/test/resources/server.keystore");
|
||||
System.setProperty("javax.net.ssl.keyStorePassword", "password");
|
||||
System.setProperty("javax.net.ssl.keyStoreType", "jks");
|
||||
//System.setProperty("javax.net.debug", "ssl,handshake,data,trustmanager");
|
||||
super.setUp();
|
||||
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return suite(HttpsTransportBrokerTest.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue