cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buhhu...@apache.org
Subject [cxf-fediz] branch master updated: fix deprecation warnings after Jetty update
Date Mon, 16 Sep 2019 14:43:53 GMT
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git


The following commit(s) were added to refs/heads/master by this push:
     new a09220d  fix deprecation warnings after Jetty update
a09220d is described below

commit a09220dd08ea2cc070382e72c36f94291f882ef4
Author: Alexey Markevich <buhhunyx@gmail.com>
AuthorDate: Mon Sep 16 17:43:20 2019 +0300

    fix deprecation warnings after Jetty update
---
 .../jetty9/ClientCertificatePreAuthSpringTest.java | 102 ++-------------------
 .../systests/jetty9/ClientCertificateTest.java     | 102 ++-------------------
 .../systests/jetty9/JettyPreAuthSpringTest.java    |  87 ++----------------
 .../cxf/fediz/systests/jetty9/JettyTest.java       |  84 ++---------------
 .../cxf/fediz/systests/jetty9/JettyUtils.java      |  35 ++-----
 .../cxf/fediz/systests/jetty9/TokenExpiryTest.java | 101 ++------------------
 .../cxf/fediz/systests/jetty9/TomcatUtils.java     |  92 +++++++++++++++++++
 .../cxf/fediz/systests/samlsso/JettyTest.java      |  95 +++++++++----------
 .../cxf/fediz/systests/samlsso/JettyUtils.java     |  35 ++-----
 9 files changed, 195 insertions(+), 538 deletions(-)

diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificatePreAuthSpringTest.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificatePreAuthSpringTest.java
index cb5e08d..51a0ea3 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificatePreAuthSpringTest.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificatePreAuthSpringTest.java
@@ -19,15 +19,7 @@
 
 package org.apache.cxf.fediz.systests.jetty9;
 
-import java.io.File;
-
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
 import org.apache.cxf.fediz.systests.common.AbstractClientCertTests;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.xml.XmlConfiguration;
 
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -39,103 +31,29 @@ import org.junit.BeforeClass;
  */
 public class ClientCertificatePreAuthSpringTest extends AbstractClientCertTests {
 
-    static String idpHttpsPort;
-    static String rpHttpsPort;
-
-    private static Server rpServer;
-    private static Tomcat idpServer;
+    private static final String RP_HTTPS_PORT = System.getProperty("rp.https.port");
 
     @BeforeClass
-    public static void init() {
-        idpHttpsPort = System.getProperty("idp.https.port");
-        Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
-        rpHttpsPort = System.getProperty("rp.https.port");
-        Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
-        initIdp();
-
-        try {
-            Resource testServerConfig = Resource.newSystemResource("rp-client-cert-server.xml");
-            XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
-            rpServer = (Server)configuration.configure();
-            rpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void init() throws Exception {
+        Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
+        TomcatUtils.initIdpServer();
+        JettyUtils.initRpServer("rp-client-cert-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        if (rpServer != null && rpServer.isStarted()) {
-            try {
-                rpServer.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void cleanup() throws Exception {
+        TomcatUtils.stopIdpServer();
+        JettyUtils.stopRpServer();
     }
 
-
     @Override
     public String getIdpHttpsPort() {
-        return idpHttpsPort;
+        return TomcatUtils.getIdpHttpsPort();
     }
 
     @Override
     public String getRpHttpsPort() {
-        return rpHttpsPort;
+        return RP_HTTPS_PORT;
     }
 
     @Override
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificateTest.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificateTest.java
index 18d6c7e..e30800e 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificateTest.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/ClientCertificateTest.java
@@ -19,15 +19,7 @@
 
 package org.apache.cxf.fediz.systests.jetty9;
 
-import java.io.File;
-
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
 import org.apache.cxf.fediz.systests.common.AbstractClientCertTests;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.xml.XmlConfiguration;
 
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -39,103 +31,29 @@ import org.junit.BeforeClass;
  */
 public class ClientCertificateTest extends AbstractClientCertTests {
 
-    static String idpHttpsPort;
-    static String rpHttpsPort;
-
-    private static Server rpServer;
-    private static Tomcat idpServer;
+    private static final String RP_HTTPS_PORT = System.getProperty("rp.https.port");
 
     @BeforeClass
-    public static void init() {
-        idpHttpsPort = System.getProperty("idp.https.port");
-        Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
-        rpHttpsPort = System.getProperty("rp.https.port");
-        Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
-        initIdp();
-
-        try {
-            Resource testServerConfig = Resource.newSystemResource("rp-client-cert-server.xml");
-            XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
-            rpServer = (Server)configuration.configure();
-            rpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void init() throws Exception {
+        Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
+        TomcatUtils.initIdpServer();
+        JettyUtils.initRpServer("rp-client-cert-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        if (rpServer != null && rpServer.isStarted()) {
-            try {
-                rpServer.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void cleanup() throws Exception {
+        TomcatUtils.stopIdpServer();
+        JettyUtils.stopRpServer();
     }
 
-
     @Override
     public String getIdpHttpsPort() {
-        return idpHttpsPort;
+        return TomcatUtils.getIdpHttpsPort();
     }
 
     @Override
     public String getRpHttpsPort() {
-        return rpHttpsPort;
+        return RP_HTTPS_PORT;
     }
 
     @Override
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyPreAuthSpringTest.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyPreAuthSpringTest.java
index b44ac6c..4618561 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyPreAuthSpringTest.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyPreAuthSpringTest.java
@@ -19,13 +19,6 @@
 
 package org.apache.cxf.fediz.systests.jetty9;
 
-
-
-import java.io.File;
-
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
 import org.apache.cxf.fediz.systests.common.AbstractTests;
 
 import org.junit.AfterClass;
@@ -33,93 +26,31 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 
-
 public class JettyPreAuthSpringTest extends AbstractTests {
 
-    static String idpHttpsPort;
-    static String rpHttpsPort;
-
-    private static Tomcat idpServer;
+    private static final String RP_HTTPS_PORT = System.getProperty("rp.https.port");
 
     @BeforeClass
-    public static void init() {
-        idpHttpsPort = System.getProperty("idp.https.port");
-        Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
-        rpHttpsPort = System.getProperty("rp.https.port");
-        Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
-        initIdp();
-
-        JettyUtils.initRpServer();
-        JettyUtils.startRpServer();
+    public static void init() throws Exception {
+        Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
+        TomcatUtils.initIdpServer();
+        JettyUtils.initRpServer("rp-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
+    public static void cleanup() throws Exception {
+        TomcatUtils.stopIdpServer();
         JettyUtils.stopRpServer();
     }
 
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
     @Override
     public String getIdpHttpsPort() {
-        return idpHttpsPort;
+        return TomcatUtils.getIdpHttpsPort();
     }
 
     @Override
     public String getRpHttpsPort() {
-        return rpHttpsPort;
+        return RP_HTTPS_PORT;
     }
 
     @Override
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyTest.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyTest.java
index c80f955..0ad6505 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyTest.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyTest.java
@@ -19,11 +19,6 @@
 
 package org.apache.cxf.fediz.systests.jetty9;
 
-import java.io.File;
-
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
 import org.apache.cxf.fediz.systests.common.AbstractTests;
 
 import org.junit.AfterClass;
@@ -31,92 +26,31 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 
-
 public class JettyTest extends AbstractTests {
 
-    static String idpHttpsPort;
-    static String rpHttpsPort;
-
-    private static Tomcat idpServer;
+    private static final String RP_HTTPS_PORT = System.getProperty("rp.https.port");
 
     @BeforeClass
-    public static void init() {
-        idpHttpsPort = System.getProperty("idp.https.port");
-        Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
-        rpHttpsPort = System.getProperty("rp.https.port");
-        Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
-        initIdp();
-
-        JettyUtils.initRpServer();
-        JettyUtils.startRpServer();
+    public static void init() throws Exception {
+        Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
+        TomcatUtils.initIdpServer();
+        JettyUtils.initRpServer("rp-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
+    public static void cleanup() throws Exception {
+        TomcatUtils.stopIdpServer();
         JettyUtils.stopRpServer();
     }
 
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
     @Override
     public String getIdpHttpsPort() {
-        return idpHttpsPort;
+        return TomcatUtils.getIdpHttpsPort();
     }
 
     @Override
     public String getRpHttpsPort() {
-        return rpHttpsPort;
+        return RP_HTTPS_PORT;
     }
 
     @Override
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyUtils.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyUtils.java
index 3cab12e..eb05949 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyUtils.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/JettyUtils.java
@@ -30,40 +30,17 @@ public final class JettyUtils {
     private JettyUtils() {
     }
 
-    public static void initRpServer() {
-        initRpServer("rp-server.xml");
-    }
-
-    public static void initRpServer(String configurationFile) {
+    public static void initRpServer(String configurationFile) throws Exception {
         if (rpServer == null) {
-            try {
-                Resource testServerConfig = Resource.newSystemResource(configurationFile);
-                XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
-                rpServer = (Server)configuration.configure();
-
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    public static void startRpServer() {
-        if (rpServer != null && !rpServer.isStarted()) {
-            try {
-                rpServer.start();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            XmlConfiguration configuration = new XmlConfiguration(Resource.newSystemResource(configurationFile));
+            rpServer = (Server) configuration.configure();
+            rpServer.start();
         }
     }
 
-    public static void stopRpServer() {
+    public static void stopRpServer() throws Exception {
         if (rpServer != null && rpServer.isStarted()) {
-            try {
-                rpServer.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            rpServer.stop();
         }
     }
 
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TokenExpiryTest.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TokenExpiryTest.java
index 31870c9..a7da071 100644
--- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TokenExpiryTest.java
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TokenExpiryTest.java
@@ -19,15 +19,7 @@
 
 package org.apache.cxf.fediz.systests.jetty9;
 
-import java.io.File;
-
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
 import org.apache.cxf.fediz.systests.common.AbstractExpiryTests;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.xml.XmlConfiguration;
 
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -38,102 +30,29 @@ import org.junit.BeforeClass;
  */
 public class TokenExpiryTest extends AbstractExpiryTests {
 
-    static String idpHttpsPort;
-    static String rpHttpsPort;
-
-    private static Tomcat idpServer;
-    private static Server rpServer;
+    private static final String RP_HTTPS_PORT = System.getProperty("rp.https.port");
 
     @BeforeClass
-    public static void init() {
-        idpHttpsPort = System.getProperty("idp.https.port");
-        Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
-        rpHttpsPort = System.getProperty("rp.https.port");
-        Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
-        initIdp();
-
-        try {
-            Resource testServerConfig = Resource.newSystemResource("rp-expiry-server.xml");
-            XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
-            rpServer = (Server)configuration.configure();
-            rpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void init() throws Exception {
+        Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
+        TomcatUtils.initIdpServer();
+        JettyUtils.initRpServer("rp-expiry-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        if (rpServer != null && rpServer.isStarted()) {
-            try {
-                rpServer.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(idpHttpsPort));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    public static void cleanup() throws Exception {
+        TomcatUtils.stopIdpServer();
+        JettyUtils.stopRpServer();
     }
 
     @Override
     public String getIdpHttpsPort() {
-        return idpHttpsPort;
+        return TomcatUtils.getIdpHttpsPort();
     }
 
     @Override
     public String getRpHttpsPort() {
-        return rpHttpsPort;
+        return RP_HTTPS_PORT;
     }
 
     @Override
diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TomcatUtils.java
b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TomcatUtils.java
new file mode 100644
index 0000000..aff1c74
--- /dev/null
+++ b/systests/jetty9/src/test/java/org/apache/cxf/fediz/systests/jetty9/TomcatUtils.java
@@ -0,0 +1,92 @@
+/**
+ * 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.cxf.fediz.systests.jetty9;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Tomcat;
+
+import org.junit.Assert;
+
+public final class TomcatUtils {
+
+    private static final String IDP_HTTPS_PORT = System.getProperty("idp.https.port");
+
+    private static Tomcat idpServer;
+
+    private TomcatUtils() {
+    }
+
+    public static void initIdpServer() throws Exception {
+        Assert.assertNotNull("Property 'idp.https.port' null", IDP_HTTPS_PORT);
+        if (idpServer == null) {
+            idpServer = new Tomcat();
+            idpServer.setPort(0);
+            final Path targetDir = Paths.get("target").toAbsolutePath();
+            idpServer.setBaseDir(targetDir.toString());
+
+            idpServer.getHost().setAppBase("tomcat/idp/webapps");
+            idpServer.getHost().setAutoDeploy(true);
+            idpServer.getHost().setDeployOnStartup(true);
+
+            final Connector httpsConnector = new Connector();
+            httpsConnector.setPort(Integer.parseInt(IDP_HTTPS_PORT));
+            httpsConnector.setSecure(true);
+            httpsConnector.setScheme("https");
+            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
+            httpsConnector.setAttribute("keystorePass", "tompass");
+            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
+            httpsConnector.setAttribute("truststorePass", "tompass");
+            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
+            httpsConnector.setAttribute("clientAuth", "want");
+            // httpsConnector.setAttribute("clientAuth", "false");
+            httpsConnector.setAttribute("sslProtocol", "TLS");
+            httpsConnector.setAttribute("SSLEnabled", true);
+
+            idpServer.getService().addConnector(httpsConnector);
+
+            final Path stsWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp-sts");
+            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.toString());
+
+            final Path idpWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp");
+            idpServer.addWebapp("/fediz-idp", idpWebapp.toString());
+
+            idpServer.start();
+        }
+    }
+
+    public static String getIdpHttpsPort() {
+        return IDP_HTTPS_PORT;
+    }
+
+    public static void stopIdpServer() throws Exception {
+        if (idpServer != null && idpServer.getServer() != null
+            && idpServer.getServer().getState() != LifecycleState.DESTROYED) {
+            if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
+                idpServer.stop();
+            }
+            idpServer.destroy();
+        }
+    }
+
+}
diff --git a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyTest.java
b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyTest.java
index a4433e2..2fde8e6 100644
--- a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyTest.java
+++ b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyTest.java
@@ -19,7 +19,8 @@
 
 package org.apache.cxf.fediz.systests.samlsso;
 
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.connector.Connector;
@@ -42,71 +43,61 @@ public class JettyTest extends AbstractTests {
     private static Tomcat idpServer;
 
     @BeforeClass
-    public static void init() {
+    public static void init() throws Exception {
         Assert.assertNotNull("Property 'idp.https.port' null", IDP_HTTPS_PORT);
         Assert.assertNotNull("Property 'rp.jetty.https.port' null", RP_HTTPS_PORT);
 
         initIdp();
 
-        JettyUtils.initRpServer();
-        JettyUtils.startRpServer();
+        JettyUtils.initRpServer("rp-server.xml");
     }
 
     @AfterClass
-    public static void cleanup() {
-        try {
-            if (idpServer != null && idpServer.getServer() != null
-                && idpServer.getServer().getState() != LifecycleState.DESTROYED)
{
-                if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
-                    idpServer.stop();
-                }
-                idpServer.destroy();
+    public static void cleanup() throws Exception {
+        if (idpServer != null && idpServer.getServer() != null
+            && idpServer.getServer().getState() != LifecycleState.DESTROYED) {
+            if (idpServer.getServer().getState() != LifecycleState.STOPPED) {
+                idpServer.stop();
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+            idpServer.destroy();
         }
 
         JettyUtils.stopRpServer();
     }
 
-    private static void initIdp() {
-        try {
-            idpServer = new Tomcat();
-            idpServer.setPort(0);
-            String currentDir = new File(".").getCanonicalPath();
-            String baseDir = currentDir + File.separator + "target";
-            idpServer.setBaseDir(baseDir);
-
-            idpServer.getHost().setAppBase("tomcat/idp/webapps");
-            idpServer.getHost().setAutoDeploy(true);
-            idpServer.getHost().setDeployOnStartup(true);
-
-            Connector httpsConnector = new Connector();
-            httpsConnector.setPort(Integer.parseInt(IDP_HTTPS_PORT));
-            httpsConnector.setSecure(true);
-            httpsConnector.setScheme("https");
-            httpsConnector.setAttribute("keyAlias", "mytomidpkey");
-            httpsConnector.setAttribute("keystorePass", "tompass");
-            httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("truststorePass", "tompass");
-            httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
-            httpsConnector.setAttribute("clientAuth", "want");
-            // httpsConnector.setAttribute("clientAuth", "false");
-            httpsConnector.setAttribute("sslProtocol", "TLS");
-            httpsConnector.setAttribute("SSLEnabled", true);
-
-            idpServer.getService().addConnector(httpsConnector);
-
-            File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp-sts");
-            idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
-            File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(),
"fediz-idp");
-            idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
-
-            idpServer.start();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    private static void initIdp() throws Exception {
+        idpServer = new Tomcat();
+        idpServer.setPort(0);
+        final Path targetDir = Paths.get("target").toAbsolutePath();
+        idpServer.setBaseDir(targetDir.toString());
+
+        idpServer.getHost().setAppBase("tomcat/idp/webapps");
+        idpServer.getHost().setAutoDeploy(true);
+        idpServer.getHost().setDeployOnStartup(true);
+
+        Connector httpsConnector = new Connector();
+        httpsConnector.setPort(Integer.parseInt(IDP_HTTPS_PORT));
+        httpsConnector.setSecure(true);
+        httpsConnector.setScheme("https");
+        httpsConnector.setAttribute("keyAlias", "mytomidpkey");
+        httpsConnector.setAttribute("keystorePass", "tompass");
+        httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
+        httpsConnector.setAttribute("truststorePass", "tompass");
+        httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
+        httpsConnector.setAttribute("clientAuth", "want");
+        // httpsConnector.setAttribute("clientAuth", "false");
+        httpsConnector.setAttribute("sslProtocol", "TLS");
+        httpsConnector.setAttribute("SSLEnabled", true);
+
+        idpServer.getService().addConnector(httpsConnector);
+
+        Path stsWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp-sts");
+        idpServer.addWebapp("/fediz-idp-sts", stsWebapp.toString());
+
+        Path idpWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp");
+        idpServer.addWebapp("/fediz-idp", idpWebapp.toString());
+
+        idpServer.start();
     }
 
     @Override
diff --git a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyUtils.java
b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyUtils.java
index 3986d15..94a5fcc 100644
--- a/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyUtils.java
+++ b/systests/samlsso/src/test/java/org/apache/cxf/fediz/systests/samlsso/JettyUtils.java
@@ -30,40 +30,17 @@ public final class JettyUtils {
     private JettyUtils() {
     }
 
-    public static void initRpServer() {
-        initRpServer("rp-server.xml");
-    }
-
-    public static void initRpServer(String configurationFile) {
+    public static void initRpServer(String configurationFile) throws Exception {
         if (rpServer == null) {
-            try {
-                Resource testServerConfig = Resource.newSystemResource(configurationFile);
-                XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
-                rpServer = (Server)configuration.configure();
-
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    public static void startRpServer() {
-        if (rpServer != null && !rpServer.isStarted()) {
-            try {
-                rpServer.start();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            XmlConfiguration configuration = new XmlConfiguration(Resource.newSystemResource(configurationFile));
+            rpServer = (Server) configuration.configure();
+            rpServer.start();
         }
     }
 
-    public static void stopRpServer() {
+    public static void stopRpServer() throws Exception {
         if (rpServer != null && rpServer.isStarted()) {
-            try {
-                rpServer.stop();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            rpServer.stop();
         }
     }
 


Mime
View raw message