Merge latest changes from trunk.
diff --git a/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java b/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
index 10430c7..b56b6ae 100644
--- a/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
+++ b/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
@@ -27,7 +27,7 @@
import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.axis2.testutils.PortAllocator;
+import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.transport.http.AxisServlet;
/**
@@ -73,7 +73,6 @@
private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
private final String repository;
- private final int port;
private final boolean secure;
private Server server;
private boolean systemPropertiesSet;
@@ -86,30 +85,23 @@
*
* @param repository
* The path to the Axis2 repository to use. Must not be null or empty.
- * @param port
- * The port to use. Set to <code>0</code> to enable dynamic port allocation.
* @param secure
* Whether to enable HTTPS.
*/
- public JettyServer(String repository, int port, boolean secure) {
+ public JettyServer(String repository, boolean secure) {
if (repository == null || repository.trim().length() == 0) {
throw new IllegalArgumentException("Axis2 repository must not be null or empty");
}
this.repository = repository;
- this.port = port;
this.secure = secure;
}
@Override
protected void before() throws Throwable {
- int port = this.port == 0 ? PortAllocator.allocatePort() : this.port;
-
server = new Server();
- logger.info("Starting server on port: " + port);
if (!secure) {
SelectChannelConnector connector = new SelectChannelConnector();
- connector.setPort(port);
server.addConnector(connector);
} else {
SslContextFactory sslContextFactory = new SslContextFactory();
@@ -121,7 +113,6 @@
sslContextFactory.setCertAlias(CERT_ALIAS);
SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
- sslConnector.setPort(port);
server.addConnector(sslConnector);
savedTrustStore = System.getProperty("javax.net.ssl.trustStore");
@@ -168,6 +159,8 @@
throw e;
}
}
+
+ logger.info("Server started on port " + getPort());
}
@Override
@@ -224,10 +217,18 @@
for (Connector connector : connectors) {
if (connector instanceof SelectChannelConnector) {
//must be the http connector
- return connector.getPort();
+ return connector.getLocalPort();
}
}
throw new IllegalStateException("Could not find Jetty http connector");
}
+
+ public String getEndpoint(String serviceName) {
+ return String.format("%s://localhost:%s/axis2/services/%s", secure ? "https" : "http", getPort(), serviceName);
+ }
+
+ public EndpointReference getEndpointReference(String serviceName) {
+ return new EndpointReference(getEndpoint(serviceName));
+ }
}
diff --git a/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java b/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
index 3b639af..e4f16ef 100644
--- a/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
+++ b/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
@@ -24,7 +24,6 @@
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
@@ -39,10 +38,8 @@
public abstract class TestClient {
- protected int port = 5555;
-
@Rule
- public final JettyServer server = new JettyServer(Constants.TESTING_PATH + getServiceRepo(), port, false);
+ public final JettyServer server = new JettyServer(Constants.TESTING_PATH + getServiceRepo(), false);
/**
*/
@@ -62,7 +59,7 @@
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("javax.net.ssl.trustStoreType","JKS");
- options.setTo(new EndpointReference("http://127.0.0.1:" + port + "/axis2/services/SecureService"));
+ options.setTo(server.getEndpointReference("SecureService"));
// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/axis2/services/UTSAMLHoK"));
// options.setTo(new EndpointReference("https://www-lk.wso2.com:8443/axis2/services/UTSAMLHoK"));
// options.setTo(new EndpointReference("https://192.18.49.133:2343/jaxws-s1-sts/sts"));
diff --git a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
index bcfba9e..8554871 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
@@ -65,7 +65,7 @@
public static final String KERBEROS_CONF_KDC_PORT_TOKEN = "KDC_PORT";
@Rule
- public final JettyServer server = new JettyServer("target/test-resources/rampart_service_repo", 0, true);
+ public final JettyServer server = new JettyServer("target/test-resources/rampart_service_repo", true);
/**
* Stores any original JAAS configuration set via {@link #JAAS_CONF_SYS_PROP} property to restore it after test execution.
@@ -80,7 +80,7 @@
@Test
public void testKerberosOverTransportKeytab() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosOverTransportKeytab";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getPort(), serviceName));
+ URL serviceUrl = new URL(server.getEndpoint(serviceName) + "?wsdl");
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
@@ -107,7 +107,7 @@
@Test
public void testKerberosOverTransportPWCB() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosOverTransportPWCB";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getPort(), serviceName));
+ URL serviceUrl = new URL(server.getEndpoint(serviceName) + "?wsdl");
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
@@ -136,7 +136,7 @@
@Test
public void testKerberosDelegation() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosDelegation";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getPort(), serviceName));
+ URL serviceUrl = new URL(server.getEndpoint(serviceName) + "?wsdl");
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
index 571beda..883bd70 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
@@ -27,7 +27,6 @@
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
@@ -47,10 +46,10 @@
private static ResourceBundle resources;
@Rule
- public final JettyServer server = new JettyServer(Constants.TESTING_PATH + "rampart_service_repo", 0, false);
+ public final JettyServer server = new JettyServer(Constants.TESTING_PATH + "rampart_service_repo", false);
@Rule
- public final JettyServer secureServer = new JettyServer(Constants.TESTING_PATH + "rampart_service_repo", 0, true);
+ public final JettyServer secureServer = new JettyServer(Constants.TESTING_PATH + "rampart_service_repo", true);
static {
try {
@@ -104,17 +103,13 @@
Options options = new Options();
if( i == 13 ) {
- options.setTo(new EndpointReference("https://localhost:" +
- secureServer.getPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
else {
- options.setTo(new EndpointReference("http://localhost:" +
- server.getPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(server.getEndpointReference("SecureService" + i));
}
System.out.println("Testing WS-Sec: custom scenario " + i);
@@ -180,17 +175,13 @@
Options options = new Options();
if (i == 13) {
- options.setTo(new EndpointReference("https://localhost:" +
- secureServer.getPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
else {
- options.setTo(new EndpointReference("http://localhost:" +
- server.getPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(server.getEndpointReference("SecureService" + i));
}
System.out.println("Testing WS-Sec: negative scenario " + i);
options.setAction("urn:returnError");
@@ -215,10 +206,10 @@
Options options = new Options();
if (i == 3 || i == 6) {
- options.setTo(new EndpointReference("https://localhost:" + secureServer.getPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(secureServer.getEndpointReference("SecureServiceSC" + i));
}
else {
- options.setTo(new EndpointReference("http://localhost:" + server.getPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(server.getEndpointReference("SecureServiceSC" + i));
}
System.out.println("Testing WS-SecConv: custom scenario " + i);