This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch 1_7
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit ea30133b0b5a050ff354a8abd10cca2f6ed4abf9
Author: Andreas Veithen <veit...@apache.org>
AuthorDate: Sun Jan 6 15:23:32 2019 +0000

    Merge r1779816 and r1780723 to the 1.7 branch.
---
 .../{Axis2Server.java => AbstractAxis2Server.java} | 43 ++++++++--------------
 .../org/apache/axis2/testutils/Axis2Server.java    | 34 +++++++----------
 .../org/apache/axis2/testutils/JettyServer.java    | 28 +++++++-------
 3 files changed, 44 insertions(+), 61 deletions(-)

diff --git 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
similarity index 63%
copy from 
modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
copy to 
modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
index e06a3a9..8c91b7d 100644
--- 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
+++ 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
@@ -22,55 +22,44 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.transport.http.SimpleHTTPServer;
 import org.junit.rules.ExternalResource;
 
-public class Axis2Server extends ExternalResource {
+public abstract class AbstractAxis2Server extends ExternalResource {
     private final String repositoryPath;
-    private int port = -1;
     private ConfigurationContext configurationContext;
-    private SimpleHTTPServer server;
 
-    public Axis2Server(String repositoryPath) {
-        this.repositoryPath = repositoryPath;
-    }
-
-    public int getPort() {
-        if (port == -1) {
-            throw new IllegalStateException();
+    public AbstractAxis2Server(String repositoryPath) {
+        if (repositoryPath == null || repositoryPath.trim().length() == 0) {
+            throw new IllegalArgumentException("Axis2 repository must not be 
null or empty");
         }
-        return port;
+        this.repositoryPath = repositoryPath;
     }
 
-    public ConfigurationContext getConfigurationContext() {
+    public final ConfigurationContext getConfigurationContext() {
         if (configurationContext == null) {
             throw new IllegalStateException();
         }
         return configurationContext;
     }
 
-    public String getEndpoint(String serviceName) throws AxisFault {
-        return 
getConfigurationContext().getAxisConfiguration().getService(serviceName).getEPRs()[0];
-    }
-
-    public EndpointReference getEndpointReference(String serviceName) throws 
AxisFault {
-        return new EndpointReference(getEndpoint(serviceName));
-    }
-
     @Override
     protected void before() throws Throwable {
-        port = PortAllocator.allocatePort();
         configurationContext =
                 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
-        server = new SimpleHTTPServer(configurationContext, port);
-        server.start();
+        startServer(configurationContext);
     }
 
     @Override
     protected void after() {
-        port = -1;
+        stopServer();
         configurationContext = null;
-        server.stop();
-        server = null;
     }
+
+    protected abstract void startServer(ConfigurationContext 
configurationContext) throws Throwable;
+    protected abstract void stopServer();
+
+    public abstract boolean isSecure();
+    public abstract int getPort();
+    public abstract String getEndpoint(String serviceName) throws AxisFault;
+    public abstract EndpointReference getEndpointReference(String serviceName) 
throws AxisFault;
 }
diff --git 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
index e06a3a9..2f88402 100644
--- 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
+++ 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
@@ -21,20 +21,22 @@ package org.apache.axis2.testutils;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.transport.http.SimpleHTTPServer;
-import org.junit.rules.ExternalResource;
 
-public class Axis2Server extends ExternalResource {
-    private final String repositoryPath;
+public class Axis2Server extends AbstractAxis2Server {
     private int port = -1;
-    private ConfigurationContext configurationContext;
     private SimpleHTTPServer server;
 
     public Axis2Server(String repositoryPath) {
-        this.repositoryPath = repositoryPath;
+        super(repositoryPath);
     }
 
+    @Override
+    public boolean isSecure() {
+        return false;
+    }
+
+    @Override
     public int getPort() {
         if (port == -1) {
             throw new IllegalStateException();
@@ -42,34 +44,26 @@ public class Axis2Server extends ExternalResource {
         return port;
     }
 
-    public ConfigurationContext getConfigurationContext() {
-        if (configurationContext == null) {
-            throw new IllegalStateException();
-        }
-        return configurationContext;
-    }
-
+    @Override
     public String getEndpoint(String serviceName) throws AxisFault {
-        return 
getConfigurationContext().getAxisConfiguration().getService(serviceName).getEPRs()[0];
+        return getEndpointReference(serviceName).getAddress();
     }
 
+    @Override
     public EndpointReference getEndpointReference(String serviceName) throws 
AxisFault {
-        return new EndpointReference(getEndpoint(serviceName));
+        return server.getEPRForService(serviceName, "localhost");
     }
 
     @Override
-    protected void before() throws Throwable {
+    protected void startServer(ConfigurationContext configurationContext) 
throws Throwable {
         port = PortAllocator.allocatePort();
-        configurationContext =
-                
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
         server = new SimpleHTTPServer(configurationContext, port);
         server.start();
     }
 
     @Override
-    protected void after() {
+    protected void stopServer() {
         port = -1;
-        configurationContext = null;
         server.stop();
         server = null;
     }
diff --git 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
index a84957b..ee52e46 100644
--- 
a/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
+++ 
b/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
@@ -41,10 +41,8 @@ import 
org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
 import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.webapp.WebAppContext;
-import org.junit.rules.ExternalResource;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.transport.http.AxisServlet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -58,7 +56,7 @@ import 
org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
 /**
  * Support for running an embedded Jetty server
  */
-public class JettyServer extends ExternalResource {
+public class JettyServer extends AbstractAxis2Server {
     /**
      * The alias of the certificate to configure for Jetty's ssl context 
factory: {@value}
      */
@@ -71,7 +69,6 @@ public class JettyServer extends ExternalResource {
     
     private static final Log log = LogFactory.getLog(JettyServer.class);
     
-    private final String repository;
     private final boolean secure;
     private File keyStoreFile;
     private File trustStoreFile;
@@ -84,16 +81,13 @@ public class JettyServer extends ExternalResource {
     /**
      * Constructor.
      * 
-     * @param repository
+     * @param repositoryPath
      *            The path to the Axis2 repository to use. Must not be null or 
empty.
      * @param secure
      *            Whether to enable HTTPS.
      */
-    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;
+    public JettyServer(String repositoryPath, boolean secure) {
+        super(repositoryPath);
         this.secure = secure;
     }
     
@@ -115,7 +109,7 @@ public class JettyServer extends ExternalResource {
     }
     
     @Override
-    protected void before() throws Throwable {
+    protected void startServer(final ConfigurationContext 
configurationContext) throws Throwable {
         server = new Server();
         
         if (!secure) {
@@ -187,8 +181,6 @@ public class JettyServer extends ExternalResource {
         context.setParentLoaderPriority(true);
         context.setThrowUnavailableOnStartupException(true);
         
-        final ConfigurationContext configurationContext =
-                
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository);
         @SuppressWarnings("serial")
         ServletHolder servlet = new ServletHolder(new AxisServlet() {
             @Override
@@ -222,7 +214,7 @@ public class JettyServer extends ExternalResource {
     }
     
     @Override
-    protected void after() {
+    protected void stopServer() {
         if (server != null) {
             log.info("Stop called");
             try {
@@ -263,10 +255,16 @@ public class JettyServer extends ExternalResource {
         }
     }
 
+    @Override
+    public boolean isSecure() {
+        return secure;
+    }
+
     /**
      * @return Jetty's http connector port. 
      * @throws IllegalStateException If Jetty is not running or the http 
connector cannot be found.
      */
+    @Override
     public int getPort() throws IllegalStateException {
         if (server == null) {
             throw new IllegalStateException("Jetty server is not initialized");
@@ -290,10 +288,12 @@ public class JettyServer extends ExternalResource {
         throw new IllegalStateException("Could not find Jetty http connector");
     }
 
+    @Override
     public String getEndpoint(String serviceName) {
         return String.format("%s://localhost:%s/axis2/services/%s", secure ? 
"https" : "http", getPort(), serviceName);
     }
 
+    @Override
     public EndpointReference getEndpointReference(String serviceName) {
         return new EndpointReference(getEndpoint(serviceName));
     }

Reply via email to