Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
public class HttpTransportBrokerTest extends TransportBrokerTestSupport {

protected String getBindLocation() {
return "http://localhost:8081";
return "http://localhost:0";
}

protected void setUp() throws Exception {
maxWait = 2000;
super.setUp();
WaitForJettyListener.waitForJettySocketToAccept(getBindLocation());
WaitForJettyListener.waitForJettySocketToAccept(connector.getPublishableConnectURI().toString());
}

protected BrokerService createBroker() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class HttpsTransportBrokerTest extends HttpTransportBrokerTest {

@Override
protected String getBindLocation() {
return "https://localhost:8161";
return "https://localhost:0";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MQTTWSSTransportTest(String testName, boolean partialFrames) {

@Override
protected String getWSConnectorURI() {
return "wss://localhost:61623";
return "wss://localhost:0";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void setUp() throws Exception {

SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setTrustAll(true);
sslContextFactory.setEndpointIdentificationAlgorithm(null);
ClientConnector clientConnector = new ClientConnector();
clientConnector.setSslContextFactory(sslContextFactory);

Expand All @@ -97,6 +98,9 @@ public void tearDown() throws Exception {
if (wsMQTTConnection != null) {
wsMQTTConnection.close();
wsMQTTConnection = null;
}
if (wsClient != null) {
wsClient.stop();
wsClient = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class StompWSSTransportTest extends StompWSTransportTest {

@Override
protected String getWSConnectorURI() {
return "wss://localhost:61623";
return "wss://localhost:0";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public WSTransportHttpTraceTest(final String enableTraceParam, final int expecte

@Override
protected String getWSConnectorURI() {
String uri = "ws://127.0.0.1:61623?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
String uri = "ws://127.0.0.1:0?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
uri = enableTraceParam != null ? uri + "&" + enableTraceParam : uri;
return uri;
}
Expand All @@ -54,7 +54,8 @@ protected String getWSConnectorURI() {
*/
@Test(timeout=10000)
public void testHttpTraceEnabled() throws Exception {
HttpTraceTestSupport.testHttpTraceEnabled("http://127.0.0.1:61623", expectedStatus, null);
HttpTraceTestSupport.testHttpTraceEnabled("http://127.0.0.1:" + wsConnectUri.getPort(),
expectedStatus, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URI;

import org.apache.activemq.broker.BrokerFactory;
Expand All @@ -37,7 +38,6 @@ public class WSTransportLinkStealingTest {
private static final Logger LOG = LoggerFactory.getLogger(WSTransportLinkStealingTest.class);

private BrokerService broker;

protected BrokerService createBroker(boolean deleteMessages) throws Exception {
BrokerService broker = BrokerFactory.createBroker(
new URI("broker:()/localhost?persistent=false&useJmx=false"));
Expand All @@ -59,7 +59,8 @@ protected BrokerService createBroker(boolean deleteMessages) throws Exception {
}

protected String getWSConnectorURI() {
return "ws://127.0.0.1:61623?allowLinkStealing=true&websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
return "ws://127.0.0.1:0" +
"?allowLinkStealing=true&websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
}

protected void stopBroker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ public class WSTransportTest extends WSTransportTestSupport {
private String stompUri;
private StompConnection stompConnection = new StompConnection();

protected final int port = 61623;

@Override
protected void addAdditionalConnectors(BrokerService service) throws Exception {
stompUri = service.addConnector("stomp://localhost:0").getPublishableConnectString();
}

@Override
protected String getWSConnectorURI() {
return "ws://127.0.0.1:" + port + "?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
return "ws://127.0.0.1:0?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
}

protected Server createWebServer() throws Exception {
Expand Down Expand Up @@ -138,7 +136,7 @@ public void testBrokerStart() throws Exception {

@Test(timeout=10000)
public void testGet() throws Exception {
testGet("http://127.0.0.1:" + port, null);
testGet("http://127.0.0.1:" + wsConnectUri.getPort(), null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package org.apache.activemq.transport.ws;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.URI;

import jakarta.jms.JMSException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.net.ServerSocketFactory;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
Expand Down Expand Up @@ -70,11 +70,14 @@ public void tearDown() throws Exception {
}

protected String getWSConnectionURI() {
if (wsConnectUri != null) {
return wsConnectUri.toString();
}
return "ws://127.0.0.1:" + getProxyPort();
}

protected String getWSConnectorURI() {
return "ws://127.0.0.1:" + getProxyPort() +
return "ws://127.0.0.1:0" +
"?allowLinkStealing=" + isAllowLinkStealing() +
"&websocket.maxTextMessageSize=99999" +
"&transport.idleTimeout=1001" +
Expand All @@ -101,7 +104,8 @@ protected BrokerService createBroker(boolean deleteMessages, boolean advisorySup
context.afterPropertiesSet();
broker.setSslContext(context);

wsConnectUri = broker.addConnector(getWSConnectorURI()).getPublishableConnectURI();
org.apache.activemq.broker.TransportConnector wsConnector =
broker.addConnector(getWSConnectorURI());

broker.setAdvisorySupport(advisorySupport);
broker.setUseJmx(true);
Expand All @@ -113,6 +117,8 @@ protected BrokerService createBroker(boolean deleteMessages, boolean advisorySup

addAdditionalConnectors(broker);

wsConnectUri = wsConnector.getPublishableConnectURI();

return broker;
}

Expand All @@ -126,18 +132,12 @@ protected String getTestName() {

protected int getProxyPort() {
if (proxyPort == 0) {
ServerSocket ss = null;
try {
ss = ServerSocketFactory.getDefault().createServerSocket(0);
try (ServerSocket ss = new ServerSocket()) {
ss.setReuseAddress(true);
ss.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0));
proxyPort = ss.getLocalPort();
} catch (IOException e) { // ignore
} finally {
try {
if (ss != null ) {
ss.close();
}
} catch (IOException e) { // ignore
}
} catch (IOException e) {
throw new IllegalStateException("Could not find a free TCP/IP port for WS tests", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public void testHttpTraceEnabled() throws Exception {
factory.setEndpointIdentificationAlgorithm(null); // service cert does not contain a SAN
factory.setSslContext(broker.getSslContext().getSSLContext());

HttpTraceTestSupport.testHttpTraceEnabled("https://127.0.0.1:61623", expectedStatus, factory);
HttpTraceTestSupport.testHttpTraceEnabled("https://localhost:" + wsConnectUri.getPort(),
expectedStatus, factory);
}

@Override
protected String getWSConnectorURI() {
String uri = "wss://127.0.0.1:61623?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
String uri = "wss://localhost:0?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001";
uri = enableTraceParam != null ? uri + "&" + enableTraceParam : uri;
return uri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public class WSSTransportLinkStealingTest extends WSTransportLinkStealingTest {

@Override
protected String getWSConnectorURI() {
return "wss://localhost:61623?allowLinkStealing=true";
return "wss://localhost:0?allowLinkStealing=true";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected Connector createJettyConnector(Server server) throws Exception {

@Override
protected String getWSConnectorURI() {
return "wss://localhost:" + port;
return "wss://localhost:0";
}

@Ignore
Expand All @@ -52,12 +52,12 @@ public void testGet() throws Exception {
factory.setEndpointIdentificationAlgorithm(null); // service cert does not contain a SAN
factory.setSslContext(broker.getSslContext().getSSLContext());

testGet("https://127.0.0.1:" + port, factory);
testGet("https://127.0.0.1:" + wsConnectUri.getPort(), factory);
}

@Override
protected String getTestURI() {
int proxyPort = getProxyPort();
return "https://localhost:" + proxyPort + "/websocket.html#wss://localhost:" + port;
return "https://localhost:" + proxyPort + "/websocket.html#" + wsConnectUri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected void setUp() throws Exception {
policyMap.setDefaultEntry(getDefaultPolicy());
broker.setDestinationPolicy(policyMap);
broker.start();
broker.waitUntilStarted();
}

protected PolicyEntry getDefaultPolicy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public abstract class TransportBrokerTestSupport extends BrokerTest {

protected TransportConnector connector;
private ArrayList<StubConnection> connections = new ArrayList<StubConnection>();
private URI bindURI;

@Override
protected void setUp() throws Exception {
super.setUp();
bindURI = connector.getPublishableConnectURI();
}

@Override
Expand Down Expand Up @@ -68,7 +70,7 @@ protected void tearDown() throws Exception {
}

protected URI getBindURI() throws URISyntaxException {
return new URI(getBindLocation());
return bindURI;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected String getBindLocation() {

@Override
protected URI getBindURI() throws URISyntaxException {
return new URI("auto+nio+ssl://localhost:0?soWriteTimeout=20000");
return new URI(super.getBindURI().toString() + "?soWriteTimeout=20000");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected String getBindLocation() {

@Override
protected URI getBindURI() throws URISyntaxException {
return new URI("auto+ssl://localhost:0?soWriteTimeout=20000");
return new URI(super.getBindURI().toString() + "?soWriteTimeout=20000");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected String getBindLocation() {

@Override
protected URI getBindURI() throws URISyntaxException {
return new URI("nio+ssl://localhost:0?soWriteTimeout=20000");
return new URI(super.getBindURI().toString() + "?soWriteTimeout=20000");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected String getBindLocation() {

@Override
protected URI getBindURI() throws URISyntaxException {
return new URI("ssl://localhost:0?soWriteTimeout=20000");
return new URI(super.getBindURI().toString() + "?soWriteTimeout=20000");
}

protected void setUp() throws Exception {
Expand Down