Repository: nifi
Updated Branches:
  refs/heads/master 03f4c0fc4 -> 98c295dfc


NIFI-5013 create test jar for standard processors

remove unnec TestServer instances

This closes #2580.

Signed-off-by: Aldrin Piri <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/98c295df
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/98c295df
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/98c295df

Branch: refs/heads/master
Commit: 98c295dfc71ff866a44d3accafb613043ef88789
Parents: 03f4c0f
Author: Otto Fowler <[email protected]>
Authored: Fri Mar 23 17:13:45 2018 -0400
Committer: Aldrin Piri <[email protected]>
Committed: Sat Mar 24 10:18:46 2018 -0400

----------------------------------------------------------------------
 .../nifi-slack-processors/pom.xml               |   7 +
 .../nifi/processors/slack/PutSlackTest.java     |   1 +
 .../nifi/processors/slack/TestServer.java       | 164 ------------------
 .../nifi-livy-processors/pom.xml                |   7 +
 .../livy/TestExecuteSparkInteractive.java       |   1 +
 .../livy/TestExecuteSparkInteractiveSSL.java    |   1 +
 .../apache/nifi/processors/livy/TestServer.java | 167 -------------------
 .../nifi-standard-processors/pom.xml            |  11 ++
 .../nifi/processors/slack/TestServer.java       | 164 ------------------
 9 files changed, 28 insertions(+), 495 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/pom.xml 
b/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/pom.xml
index b0aca8c..473720d 100644
--- a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/pom.xml
@@ -87,5 +87,12 @@
             <artifactId>nifi-ssl-context-service-api</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-standard-processors</artifactId>
+            <version>1.6.0-SNAPSHOT</version>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
 
b/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
index 1d7308b..a6b330d 100644
--- 
a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
+++ 
b/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/PutSlackTest.java
@@ -19,6 +19,7 @@ package org.apache.nifi.processors.slack;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.flowfile.FlowFile;
 import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processors.standard.TestServer;
 import org.apache.nifi.util.TestRunner;
 import org.apache.nifi.util.TestRunners;
 import org.eclipse.jetty.servlet.ServletHandler;

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
 
b/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
deleted file mode 100644
index d8a8e6a..0000000
--- 
a/nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.nifi.processors.slack;
-
-import org.apache.nifi.ssl.StandardRestrictedSSLContextService;
-import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.HandlerCollection;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
-import java.util.Map;
-
-/**
- * Test server to assist with unit tests that requires a server to be stood up.
- */
-public class TestServer {
-
-    public static final String NEED_CLIENT_AUTH = "clientAuth";
-
-    private Server jetty;
-    private boolean secure = false;
-
-    /**
-     * Creates the test server.
-     */
-    public TestServer() {
-        createServer(null);
-    }
-
-    /**
-     * Creates the test server.
-     *
-     * @param sslProperties SSLProps to be used in the secure connection. The 
keys should should use the StandardSSLContextService properties.
-     */
-    public TestServer(final Map<String, String> sslProperties) {
-        createServer(sslProperties);
-    }
-
-    private void createServer(final Map<String, String> sslProperties) {
-        jetty = new Server();
-
-        // create the unsecure connector
-        createConnector();
-
-        // create the secure connector if sslProperties are specified
-        if (sslProperties != null) {
-            createSecureConnector(sslProperties);
-        }
-
-        jetty.setHandler(new HandlerCollection(true));
-    }
-
-    /**
-     * Creates the http connection
-     */
-    private void createConnector() {
-        final ServerConnector http = new ServerConnector(jetty);
-        http.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        http.setIdleTimeout(30000L);
-        jetty.addConnector(http);
-    }
-
-    private void createSecureConnector(final Map<String, String> 
sslProperties) {
-        SslContextFactory ssl = new SslContextFactory();
-
-        if 
(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE.getName()) != 
null) {
-            
ssl.setKeyStorePath(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE.getName()));
-            
ssl.setKeyStorePassword(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE_PASSWORD.getName()));
-            
ssl.setKeyStoreType(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE_TYPE.getName()));
-        }
-
-        if 
(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE.getName()) != 
null) {
-            
ssl.setTrustStorePath(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE.getName()));
-            
ssl.setTrustStorePassword(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE_PASSWORD.getName()));
-            
ssl.setTrustStoreType(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE_TYPE.getName()));
-        }
-
-        final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH);
-        if (clientAuth == null) {
-            ssl.setNeedClientAuth(true);
-        } else {
-            ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth));
-        }
-
-        // build the connector
-        final ServerConnector https = new ServerConnector(jetty, ssl);
-
-        // set host and port
-        https.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        https.setIdleTimeout(30000L);
-
-        // add the connector
-        jetty.addConnector(https);
-
-        // mark secure as enabled
-        secure = true;
-    }
-
-    public void clearHandlers() {
-        HandlerCollection hc = (HandlerCollection) jetty.getHandler();
-        Handler[] ha = hc.getHandlers();
-        if (ha != null) {
-            for (Handler h : ha) {
-                hc.removeHandler(h);
-            }
-        }
-    }
-
-    public void addHandler(Handler handler) {
-        ((HandlerCollection) jetty.getHandler()).addHandler(handler);
-    }
-
-    public void startServer() throws Exception {
-        jetty.start();
-    }
-
-    public void shutdownServer() throws Exception {
-        jetty.stop();
-        jetty.destroy();
-    }
-
-    private int getPort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
-    }
-
-    private int getSecurePort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[1]).getLocalPort();
-    }
-
-    public String getUrl() {
-        return "http://localhost:"; + getPort();
-    }
-
-    public String getSecureUrl() {
-        String url = null;
-        if (secure) {
-            url = "https://localhost:"; + getSecurePort();
-        }
-        return url;
-    }
-}

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/pom.xml 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/pom.xml
index 750ffc0..9f42ab8 100644
--- a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/pom.xml
@@ -75,6 +75,13 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-standard-processors</artifactId>
+            <version>1.6.0-SNAPSHOT</version>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractive.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractive.java
 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractive.java
index 4219783..fc454ab 100644
--- 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractive.java
+++ 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractive.java
@@ -17,6 +17,7 @@
 package org.apache.nifi.processors.livy;
 
 import org.apache.nifi.controller.livy.LivySessionController;
+import org.apache.nifi.processors.standard.TestServer;
 import org.apache.nifi.util.MockFlowFile;
 import org.apache.nifi.util.TestRunner;
 import org.apache.nifi.util.TestRunners;

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractiveSSL.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractiveSSL.java
 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractiveSSL.java
index e732617..133c773 100644
--- 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractiveSSL.java
+++ 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestExecuteSparkInteractiveSSL.java
@@ -17,6 +17,7 @@
 package org.apache.nifi.processors.livy;
 
 import org.apache.nifi.controller.livy.LivySessionController;
+import org.apache.nifi.processors.standard.TestServer;
 import org.apache.nifi.ssl.StandardSSLContextService;
 import org.apache.nifi.util.MockFlowFile;
 import org.apache.nifi.util.TestRunner;

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestServer.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestServer.java
 
b/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestServer.java
deleted file mode 100644
index 396df07..0000000
--- 
a/nifi-nar-bundles/nifi-spark-bundle/nifi-livy-processors/src/test/java/org/apache/nifi/processors/livy/TestServer.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.nifi.processors.livy;
-
-import org.apache.nifi.ssl.StandardSSLContextService;
-import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.HandlerCollection;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
-import java.util.Map;
-
-/**
- * Test server to assist with unit tests that requires a server to be stood up.
- */
-/**
- * Test server to assist with unit tests that requires a server to be stood up.
- */
-public class TestServer {
-
-    public static final String NEED_CLIENT_AUTH = "clientAuth";
-
-    private Server jetty;
-    private boolean secure = false;
-
-    /**
-     * Creates the test server.
-     */
-    public TestServer() {
-        createServer(null);
-    }
-
-    /**
-     * Creates the test server.
-     *
-     * @param sslProperties SSLProps to be used in the secure connection. The 
keys should should use the StandardSSLContextService properties.
-     */
-    public TestServer(final Map<String, String> sslProperties) {
-        createServer(sslProperties);
-    }
-
-    private void createServer(final Map<String, String> sslProperties) {
-        jetty = new Server();
-
-        // create the unsecure connector
-        createConnector();
-
-        // create the secure connector if sslProperties are specified
-        if (sslProperties != null) {
-            createSecureConnector(sslProperties);
-        }
-
-        jetty.setHandler(new HandlerCollection(true));
-    }
-
-    /**
-     * Creates the http connection
-     */
-    private void createConnector() {
-        final ServerConnector http = new ServerConnector(jetty);
-        http.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        http.setIdleTimeout(30000L);
-        jetty.addConnector(http);
-    }
-
-    private void createSecureConnector(final Map<String, String> 
sslProperties) {
-        SslContextFactory ssl = new SslContextFactory();
-
-        if (sslProperties.get(StandardSSLContextService.KEYSTORE.getName()) != 
null) {
-            
ssl.setKeyStorePath(sslProperties.get(StandardSSLContextService.KEYSTORE.getName()));
-            
ssl.setKeyStorePassword(sslProperties.get(StandardSSLContextService.KEYSTORE_PASSWORD.getName()));
-            
ssl.setKeyStoreType(sslProperties.get(StandardSSLContextService.KEYSTORE_TYPE.getName()));
-        }
-
-        if (sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()) 
!= null) {
-            
ssl.setTrustStorePath(sslProperties.get(StandardSSLContextService.TRUSTSTORE.getName()));
-            
ssl.setTrustStorePassword(sslProperties.get(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName()));
-            
ssl.setTrustStoreType(sslProperties.get(StandardSSLContextService.TRUSTSTORE_TYPE.getName()));
-        }
-
-        final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH);
-        if (clientAuth == null) {
-            ssl.setNeedClientAuth(true);
-        } else {
-            ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth));
-        }
-
-        // build the connector
-        final ServerConnector https = new ServerConnector(jetty, ssl);
-
-        // set host and port
-        https.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        https.setIdleTimeout(30000L);
-
-        // add the connector
-        jetty.addConnector(https);
-
-        // mark secure as enabled
-        secure = true;
-    }
-
-    public void clearHandlers() {
-        HandlerCollection hc = (HandlerCollection) jetty.getHandler();
-        Handler[] ha = hc.getHandlers();
-        if (ha != null) {
-            for (Handler h : ha) {
-                hc.removeHandler(h);
-            }
-        }
-    }
-
-    public void addHandler(Handler handler) {
-        ((HandlerCollection) jetty.getHandler()).addHandler(handler);
-    }
-
-    public void startServer() throws Exception {
-        jetty.start();
-    }
-
-    public void shutdownServer() throws Exception {
-        jetty.stop();
-        jetty.destroy();
-    }
-
-    private int getPort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
-    }
-
-    private int getSecurePort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[1]).getLocalPort();
-    }
-
-    public String getUrl() {
-        return "http://localhost:"; + getPort();
-    }
-
-    public String getSecureUrl() {
-        String url = null;
-        if (secure) {
-            url = "https://localhost:"; + getSecurePort();
-        }
-        return url;
-    }
-}

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
index e9e2a1a..d1816a8 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml
@@ -481,6 +481,17 @@
                     </excludes>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
     <profiles>

http://git-wip-us.apache.org/repos/asf/nifi/blob/98c295df/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
deleted file mode 100644
index f508c7f..0000000
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/slack/TestServer.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.nifi.processors.slack;
-
-import java.util.Map;
-
-import org.apache.nifi.ssl.StandardRestrictedSSLContextService;
-import org.eclipse.jetty.server.Handler;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.HandlerCollection;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
-/**
- * Test server to assist with unit tests that requires a server to be stood up.
- */
-public class TestServer {
-
-    public static final String NEED_CLIENT_AUTH = "clientAuth";
-
-    private Server jetty;
-    private boolean secure = false;
-
-    /**
-     * Creates the test server.
-     */
-    public TestServer() {
-        createServer(null);
-    }
-
-    /**
-     * Creates the test server.
-     *
-     * @param sslProperties SSLProps to be used in the secure connection. The 
keys should should use the StandardSSLContextService properties.
-     */
-    public TestServer(final Map<String, String> sslProperties) {
-        createServer(sslProperties);
-    }
-
-    private void createServer(final Map<String, String> sslProperties) {
-        jetty = new Server();
-
-        // create the unsecure connector
-        createConnector();
-
-        // create the secure connector if sslProperties are specified
-        if (sslProperties != null) {
-            createSecureConnector(sslProperties);
-        }
-
-        jetty.setHandler(new HandlerCollection(true));
-    }
-
-    /**
-     * Creates the http connection
-     */
-    private void createConnector() {
-        final ServerConnector http = new ServerConnector(jetty);
-        http.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        http.setIdleTimeout(30000L);
-        jetty.addConnector(http);
-    }
-
-    private void createSecureConnector(final Map<String, String> 
sslProperties) {
-        SslContextFactory ssl = new SslContextFactory();
-
-        if 
(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE.getName()) != 
null) {
-            
ssl.setKeyStorePath(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE.getName()));
-            
ssl.setKeyStorePassword(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE_PASSWORD.getName()));
-            
ssl.setKeyStoreType(sslProperties.get(StandardRestrictedSSLContextService.KEYSTORE_TYPE.getName()));
-        }
-
-        if 
(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE.getName()) != 
null) {
-            
ssl.setTrustStorePath(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE.getName()));
-            
ssl.setTrustStorePassword(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE_PASSWORD.getName()));
-            
ssl.setTrustStoreType(sslProperties.get(StandardRestrictedSSLContextService.TRUSTSTORE_TYPE.getName()));
-        }
-
-        final String clientAuth = sslProperties.get(NEED_CLIENT_AUTH);
-        if (clientAuth == null) {
-            ssl.setNeedClientAuth(true);
-        } else {
-            ssl.setNeedClientAuth(Boolean.parseBoolean(clientAuth));
-        }
-
-        // build the connector
-        final ServerConnector https = new ServerConnector(jetty, ssl);
-
-        // set host and port
-        https.setPort(0);
-        // Severely taxed environments may have significant delays when 
executing.
-        https.setIdleTimeout(30000L);
-
-        // add the connector
-        jetty.addConnector(https);
-
-        // mark secure as enabled
-        secure = true;
-    }
-
-    public void clearHandlers() {
-        HandlerCollection hc = (HandlerCollection) jetty.getHandler();
-        Handler[] ha = hc.getHandlers();
-        if (ha != null) {
-            for (Handler h : ha) {
-                hc.removeHandler(h);
-            }
-        }
-    }
-
-    public void addHandler(Handler handler) {
-        ((HandlerCollection) jetty.getHandler()).addHandler(handler);
-    }
-
-    public void startServer() throws Exception {
-        jetty.start();
-    }
-
-    public void shutdownServer() throws Exception {
-        jetty.stop();
-        jetty.destroy();
-    }
-
-    private int getPort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
-    }
-
-    private int getSecurePort() {
-        if (!jetty.isStarted()) {
-            throw new IllegalStateException("Jetty server not started");
-        }
-        return ((ServerConnector) jetty.getConnectors()[1]).getLocalPort();
-    }
-
-    public String getUrl() {
-        return "http://localhost:"; + getPort();
-    }
-
-    public String getSecureUrl() {
-        String url = null;
-        if (secure) {
-            url = "https://localhost:"; + getSecurePort();
-        }
-        return url;
-    }
-}

Reply via email to