Blob Blame History Raw
From e4af9e97b2b94401ee1f3cba75a1892bc5d269c9 Mon Sep 17 00:00:00 2001
From: Marek Goldmann <mgoldman@redhat.com>
Date: Mon, 19 Nov 2012 11:14:57 +0100
Subject: [PATCH] [JBWS-3446] Add methods for creating a test https connector

---
 .../as/webservices/deployer/RemoteDeployer.java    | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/webservices/tests-integration/src/main/java/org/jboss/as/webservices/deployer/RemoteDeployer.java b/webservices/tests-integration/src/main/java/org/jboss/as/webservices/deployer/RemoteDeployer.java
index 4262fa1..0aac4d6 100644
--- a/webservices/tests-integration/src/main/java/org/jboss/as/webservices/deployer/RemoteDeployer.java
+++ b/webservices/tests-integration/src/main/java/org/jboss/as/webservices/deployer/RemoteDeployer.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Semaphore;
 
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
@@ -47,12 +48,14 @@ import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
 import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult;
 import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
 import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult;
+import org.jboss.as.controller.operations.common.Util;
 import org.jboss.dmr.ModelNode;
 import org.jboss.logging.Logger;
 import org.jboss.wsf.spi.deployer.Deployer;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.COMPOSITE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
@@ -65,6 +68,7 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REM
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STEPS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
 import static org.jboss.as.security.Constants.AUTHENTICATION;
@@ -96,6 +100,7 @@ public final class RemoteDeployer implements Deployer {
     private final CallbackHandler callbackHandler = getCallbackHandler();
     private final ServerDeploymentManager deploymentManager;
     private final ModelControllerClient modelControllerClient;
+    private final Semaphore httpsConnSemaphore = new Semaphore(1);
 
     public RemoteDeployer() throws IOException {
         final String host = System.getProperty(JBWS_DEPLOYER_HOST);
@@ -203,6 +208,41 @@ public final class RemoteDeployer implements Deployer {
         applyUpdate(op, getModelControllerClient());
     }
 
+    public void addHttpsConnector(Map<String, String> sslOptions) throws Exception {
+        httpsConnSemaphore.acquire();
+        try {
+            final ModelNode composite = Util.getEmptyOperation(COMPOSITE, new ModelNode());
+            final ModelNode steps = composite.get(STEPS);
+            ModelNode op = createOpNode("subsystem=web/connector=jbws-test-https-connector", ADD);
+            op.get("socket-binding").set("https");
+            op.get("scheme").set("https");
+            op.get("protocol").set("HTTP/1.1");
+            op.get("secure").set(true);
+            op.get("enabled").set(true);
+            steps.add(op);
+            ModelNode ssl = createOpNode("subsystem=web/connector=jbws-test-https-connector/ssl=configuration", ADD);
+            if (sslOptions != null) {
+                for (final String k : sslOptions.keySet()) {
+                    ssl.get(k).set(sslOptions.get(k));
+                }
+            }
+            steps.add(ssl);
+            applyUpdate(composite, getModelControllerClient());
+        } catch (Exception e) {
+            httpsConnSemaphore.release();
+            throw e;
+        }
+    }
+
+    public void removeHttpsConnector() throws Exception {
+        try {
+            ModelNode op = createOpNode("subsystem=web/connector=jbws-test-https-connector", REMOVE);
+            applyUpdate(op, getModelControllerClient());
+        } finally {
+            httpsConnSemaphore.release();
+        }
+    }
+
     private ModelControllerClient getModelControllerClient() {
         return modelControllerClient;
     }
@@ -263,6 +303,21 @@ public final class RemoteDeployer implements Deployer {
         };
     }
 
+    public static ModelNode createOpNode(String address, String operation) {
+        ModelNode op = new ModelNode();
+        // set address
+        ModelNode list = op.get("address").setEmptyList();
+        if (address != null) {
+            String[] pathSegments = address.split("/");
+            for (String segment : pathSegments) {
+                String[] elements = segment.split("=");
+                list.add(elements[0], elements[1]);
+            }
+        }
+        op.get("operation").set(operation);
+        return op;
+    }
+
     private static String getSystemProperty(final String name, final String defaultValue) {
         PrivilegedAction<String> action = new PrivilegedAction<String>() {
             public String run() {