You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/01/28 17:08:47 UTC
svn commit: r1780723 - in
/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils:
AbstractAxis2Server.java Axis2Server.java JettyServer.java
Author: veithen
Date: Sat Jan 28 17:08:47 2017
New Revision: 1780723
URL: http://svn.apache.org/viewvc?rev=1780723&view=rev
Log:
Extract common code from Axis2Server and JettyServer into a common base class.
Added:
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java (with props)
Modified:
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
Added: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java?rev=1780723&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java (added)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java Sat Jan 28 17:08:47 2017
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.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.junit.rules.ExternalResource;
+
+public abstract class AbstractAxis2Server extends ExternalResource {
+ private final String repositoryPath;
+ private ConfigurationContext configurationContext;
+
+ public AbstractAxis2Server(String repositoryPath) {
+ if (repositoryPath == null || repositoryPath.trim().length() == 0) {
+ throw new IllegalArgumentException("Axis2 repository must not be null or empty");
+ }
+ this.repositoryPath = repositoryPath;
+ }
+
+ public final ConfigurationContext getConfigurationContext() {
+ if (configurationContext == null) {
+ throw new IllegalStateException();
+ }
+ return configurationContext;
+ }
+
+ @Override
+ protected void before() throws Throwable {
+ configurationContext =
+ ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
+ startServer(configurationContext);
+ }
+
+ @Override
+ protected void after() {
+ stopServer();
+ configurationContext = 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;
+}
Propchange: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java?rev=1780723&r1=1780722&r2=1780723&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java (original)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java Sat Jan 28 17:08:47 2017
@@ -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 Externa
return port;
}
- public ConfigurationContext getConfigurationContext() {
- if (configurationContext == null) {
- throw new IllegalStateException();
- }
- return configurationContext;
- }
-
+ @Override
public String getEndpoint(String serviceName) throws AxisFault {
return getEndpointReference(serviceName).getAddress();
}
+ @Override
public EndpointReference getEndpointReference(String serviceName) throws AxisFault {
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;
}
Modified: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java?rev=1780723&r1=1780722&r2=1780723&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java (original)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java Sat Jan 28 17:08:47 2017
@@ -41,10 +41,8 @@ import org.eclipse.jetty.server.ssl.SslS
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.
/**
* 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 Externa
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 Externa
/**
* 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 Externa
}
@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 Externa
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 Externa
}
@Override
- protected void after() {
+ protected void stopServer() {
if (server != null) {
log.info("Stop called");
try {
@@ -263,10 +255,16 @@ public class JettyServer extends Externa
}
}
+ @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 Externa
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));
}