tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject [1/3] tomee git commit: Delegate RemoteServer.destroy() to usage - Try/catch
Date Sat, 07 Nov 2015 01:27:23 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x e113c06ed -> 6df9839b2


http://git-wip-us.apache.org/repos/asf/tomee/blob/6df9839b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
----------------------------------------------------------------------
diff --git a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
index 090a816..f4d5cd1 100644
--- a/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
+++ b/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/FullRestartContainer.java
@@ -1,136 +1,137 @@
-/*
- * 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.openejb.tck.impl;
-
-import org.apache.openejb.client.RemoteInitialContextFactory;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.Options;
-import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
-import org.apache.openejb.tck.util.ServerLocal;
-import org.apache.tomee.catalina.facade.ExceptionManagerFacade;
-import org.jboss.testharness.api.DeploymentException;
-import org.jboss.testharness.spi.Containers;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * flow:
- * - copy file
- * - start the server
- * - stop the server
- * - remove the file
- */
-public class FullRestartContainer extends AbstractContainers implements Containers {
-    private static final File WEBAPP_DIR = new File(System.getProperty("openejb.home"), "webapps/");
-    private static final File APPS_DIR = new File(System.getProperty("openejb.home"), "apps/");
-
-    private RemoteServer server;
-    private Exception exception;
-    private File currentFile;
-
-    public FullRestartContainer() {
-        System.out.println("ContainersImpl=" + FullRestartContainer.class.getName());
-    }
-
-    @Override
-    public DeploymentException getDeploymentException() {
-        if (exception instanceof DeploymentException) {
-            return (DeploymentException) exception;
-        }
-        System.out.println("BADCAST");
-        return new DeploymentException("", exception);
-    }
-
-    @Override
-    public boolean deploy(final InputStream archive, final String name) throws IOException
{
-        if (name.endsWith("war")) {
-            currentFile = new File(WEBAPP_DIR, name);
-        } else {
-            currentFile = new File(APPS_DIR, name);
-        }
-
-        System.out.println(currentFile);
-        writeToFile(currentFile, archive);
-
-        final int port = ServerLocal.getPort(-1);
-        if (port > 0) {
-            server = new RemoteServer(100, true);
-            server.setPortStartup(port);
-        } else {
-            throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system
property 'server.http.port'");
-        }
-
-        try {
-            server.start();
-        } catch (final RuntimeException e) {
-            e.printStackTrace();
-            throw e;
-        }
-
-        return (exception = lookup().exception()) == null;
-    }
-
-    @Override
-    public void undeploy(final String name) throws IOException {
-
-        if (null != server) {
-            server.destroy();
-        }
-
-        final File folder = new File(currentFile.getParentFile(), currentFile.getName().substring(0,
currentFile.getName().length() - 4));
-        if (folder.exists()) {
-            delete(folder);
-        }
-        delete(currentFile);
-    }
-
-    @Override
-    public void setup() throws IOException {
-        // no-op
-    }
-
-    @Override
-    public void cleanup() throws IOException {
-        // no-op
-    }
-
-    private ExceptionManagerFacade lookup() {
-        final Options options = new Options(System.getProperties());
-        final Properties props = new Properties();
-        props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
-        final int port = ServerLocal.getPort(-1);
-        if (port > 0) {
-            System.out.println("provider url = " + "http://localhost:" + port + "/tomee/ejb");
-            props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:"
+ port + "/tomee/ejb"));
-        } else {
-            throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system
property 'server.http.port'");
-        }
-
-        try {
-            final InitialContext context = new InitialContext(props);
-            return (ExceptionManagerFacade) context.lookup("openejb/ExceptionManagerFacadeBusinessRemote");
-        } catch (final Exception e) {
-            throw new OpenEJBTCKRuntimeException(e);
-        }
-    }
-}
+/*
+ * 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.openejb.tck.impl;
+
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.loader.Options;
+import org.apache.openejb.tck.OpenEJBTCKRuntimeException;
+import org.apache.openejb.tck.util.ServerLocal;
+import org.apache.tomee.catalina.facade.ExceptionManagerFacade;
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.spi.Containers;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * flow:
+ * - copy file
+ * - start the server
+ * - stop the server
+ * - remove the file
+ */
+public class FullRestartContainer extends AbstractContainers implements Containers {
+    private static final File WEBAPP_DIR = new File(System.getProperty("openejb.home"), "webapps/");
+    private static final File APPS_DIR = new File(System.getProperty("openejb.home"), "apps/");
+
+    private RemoteServer server;
+    private Exception exception;
+    private File currentFile;
+
+    public FullRestartContainer() {
+        System.out.println("ContainersImpl=" + FullRestartContainer.class.getName());
+    }
+
+    @Override
+    public DeploymentException getDeploymentException() {
+        if (exception instanceof DeploymentException) {
+            return (DeploymentException) exception;
+        }
+        System.out.println("BADCAST");
+        return new DeploymentException("", exception);
+    }
+
+    @Override
+    public boolean deploy(final InputStream archive, final String name) throws IOException
{
+        if (name.endsWith("war")) {
+            currentFile = new File(WEBAPP_DIR, name);
+        } else {
+            currentFile = new File(APPS_DIR, name);
+        }
+
+        System.out.println(currentFile);
+        writeToFile(currentFile, archive);
+
+        final int port = ServerLocal.getPort(-1);
+        if (port > 0) {
+            server = new RemoteServer(100, true);
+            server.setPortStartup(port);
+        } else {
+            throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system
property 'server.http.port'");
+        }
+
+        try {
+            server.start();
+        } catch (final Exception e) {
+            server.destroy();
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+
+        return (exception = lookup().exception()) == null;
+    }
+
+    @Override
+    public void undeploy(final String name) throws IOException {
+
+        if (null != server) {
+            server.destroy();
+        }
+
+        final File folder = new File(currentFile.getParentFile(), currentFile.getName().substring(0,
currentFile.getName().length() - 4));
+        if (folder.exists()) {
+            delete(folder);
+        }
+        delete(currentFile);
+    }
+
+    @Override
+    public void setup() throws IOException {
+        // no-op
+    }
+
+    @Override
+    public void cleanup() throws IOException {
+        // no-op
+    }
+
+    private ExceptionManagerFacade lookup() {
+        final Options options = new Options(System.getProperties());
+        final Properties props = new Properties();
+        props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+        final int port = ServerLocal.getPort(-1);
+        if (port > 0) {
+            System.out.println("provider url = " + "http://localhost:" + port + "/tomee/ejb");
+            props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "http://localhost:"
+ port + "/tomee/ejb"));
+        } else {
+            throw new OpenEJBTCKRuntimeException("Please set the tomee port using the system
property 'server.http.port'");
+        }
+
+        try {
+            final InitialContext context = new InitialContext(props);
+            return (ExceptionManagerFacade) context.lookup("openejb/ExceptionManagerFacadeBusinessRemote");
+        } catch (final Exception e) {
+            throw new OpenEJBTCKRuntimeException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/6df9839b/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
b/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
index 1d3f137..1d30c46 100644
--- a/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
+++ b/tomee/apache-tomee/src/main/java/org/apache/tomee/RemoteTomEEEJBContainer.java
@@ -1,154 +1,161 @@
-/**
- * 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.tomee;
-
-import org.apache.geronimo.osgi.locator.ProviderLocator;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.assembler.Deployer;
-import org.apache.openejb.assembler.DeployerEjb;
-import org.apache.openejb.client.RemoteInitialContextFactory;
-import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.IO;
-import org.apache.tomee.util.QuickServerXmlParser;
-
-import javax.ejb.EJBException;
-import javax.ejb.embeddable.EJBContainer;
-import javax.ejb.spi.EJBContainerProvider;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.validation.ValidationException;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-public class RemoteTomEEEJBContainer extends EJBContainer {
-    private static RemoteTomEEEJBContainer instance;
-    private RemoteServer container;
-    private InitialContext context;
-
-    @Override
-    public void close() {
-        instance.container.destroy();
-        instance.container = null;
-    }
-
-    @Override
-    public Context getContext() {
-        return context;
-    }
-
-    public static class Provider implements EJBContainerProvider {
-        private static final List<String> CONTAINER_NAMES = Arrays.asList(RemoteTomEEEJBContainer.class.getName(),
"tomee-remote", "remote-tomee");
-
-        @Override
-        public EJBContainer createEJBContainer(final Map<?, ?> properties) {
-            final Object provider = properties.get(EJBContainer.PROVIDER);
-            int ejbContainerProviders = 1;
-            try {
-                ejbContainerProviders = ProviderLocator.getServices(EJBContainerProvider.class.getName(),
EJBContainer.class, Thread.currentThread().getContextClassLoader()).size();
-            } catch (final Exception e) {
-                // no-op
-            }
-
-            if ((provider == null && ejbContainerProviders > 1)
-                    || (!RemoteTomEEEJBContainer.class.equals(provider)
-                    && !CONTAINER_NAMES.contains(String.valueOf(provider)))) {
-                return null;
-            }
-
-            if (instance != null) {
-                return instance;
-            }
-
-            final Object modules = properties.get(EJBContainer.MODULES);
-
-            System.getProperties().putAll(properties);
-            final File home = new File(System.getProperty("openejb.home", "doesn't exist"));
-            if (!home.exists()) {
-                throw new IllegalArgumentException("You need to set openejb.home");
-            }
-
-            final QuickServerXmlParser parser = QuickServerXmlParser.parse(new File(home,
"conf/server.xml"));
-            final String remoteEjb = System.getProperty(Context.PROVIDER_URL, "http://" +
parser.host() + ":" + parser.http() + "/tomee/ejb");
-
-            try {
-                instance = new RemoteTomEEEJBContainer();
-                instance.container = new RemoteServer();
-                instance.container.setPortStartup(Integer.parseInt(parser.http()));
-                instance.container.start();
-                instance.context = new InitialContext(new Properties() {{
-                    setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
-                    setProperty(Context.PROVIDER_URL, remoteEjb);
-                }});
-
-                final Deployer deployer = Deployer.class.cast(instance.context.lookup("openejb/DeployerBusinessRemote"));
-
-                if (modules instanceof File) {
-                    final File file = File.class.cast(modules);
-                    deployFile(deployer, file);
-                } else if (modules instanceof String) {
-                    final String path = String.class.cast(modules);
-                    final File file = new File(path);
-                    deployFile(deployer, file);
-                } else if (modules instanceof String[]) {
-                    for (final String path : (String[]) modules) {
-                        deployFile(deployer, new File(path));
-                    }
-                } else if (modules instanceof File[]) {
-                    for (final File file : (File[]) modules) {
-                        deployFile(deployer, file);
-                    }
-                } // else suppose already deployed
-
-                return instance;
-            } catch (final OpenEJBException e) {
-                throw new EJBException(e);
-            } catch (final MalformedURLException e) {
-                throw new EJBException(e);
-            } catch (final ValidationException ve) {
-                throw ve;
-            } catch (final Exception e) {
-                if (e instanceof EJBException) {
-                    throw (EJBException) e;
-                }
-                throw new TomEERemoteEJBContainerException("initialization exception", e);
-            }
-        }
-    }
-
-    private static void deployFile(final Deployer deployer, final File file) throws IOException,
OpenEJBException {
-        if ("true".equalsIgnoreCase(System.getProperty(DeployerEjb.OPENEJB_USE_BINARIES,
"false"))) {
-            final Properties props = new Properties();
-            final byte[] slurpBinaries = IO.slurp(file).getBytes();
-            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
-            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, file.getName());
-            deployer.deploy(file.getAbsolutePath(), props);
-        } else {
-            deployer.deploy(file.getAbsolutePath());
-        }
-    }
-
-    protected static class TomEERemoteEJBContainerException extends RuntimeException {
-        protected TomEERemoteEJBContainerException(final String s, final Exception e) {
-            super(s, e);
-        }
-    }
-}
+/**
+ * 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.tomee;
+
+import org.apache.geronimo.osgi.locator.ProviderLocator;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.DeployerEjb;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.loader.IO;
+import org.apache.tomee.util.QuickServerXmlParser;
+
+import javax.ejb.EJBException;
+import javax.ejb.embeddable.EJBContainer;
+import javax.ejb.spi.EJBContainerProvider;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.validation.ValidationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class RemoteTomEEEJBContainer extends EJBContainer {
+    private static RemoteTomEEEJBContainer instance;
+    private RemoteServer container;
+    private InitialContext context;
+
+    @Override
+    public void close() {
+        instance.container.destroy();
+        instance.container = null;
+    }
+
+    @Override
+    public Context getContext() {
+        return context;
+    }
+
+    public static class Provider implements EJBContainerProvider {
+        private static final List<String> CONTAINER_NAMES = Arrays.asList(RemoteTomEEEJBContainer.class.getName(),
"tomee-remote", "remote-tomee");
+
+        @Override
+        public EJBContainer createEJBContainer(final Map<?, ?> properties) {
+            final Object provider = properties.get(EJBContainer.PROVIDER);
+            int ejbContainerProviders = 1;
+            try {
+                ejbContainerProviders = ProviderLocator.getServices(EJBContainerProvider.class.getName(),
EJBContainer.class, Thread.currentThread().getContextClassLoader()).size();
+            } catch (final Exception e) {
+                // no-op
+            }
+
+            if ((provider == null && ejbContainerProviders > 1)
+                    || (!RemoteTomEEEJBContainer.class.equals(provider)
+                    && !CONTAINER_NAMES.contains(String.valueOf(provider)))) {
+                return null;
+            }
+
+            if (instance != null) {
+                return instance;
+            }
+
+            final Object modules = properties.get(EJBContainer.MODULES);
+
+            System.getProperties().putAll(properties);
+            final File home = new File(System.getProperty("openejb.home", "doesn't exist"));
+            if (!home.exists()) {
+                throw new IllegalArgumentException("You need to set openejb.home");
+            }
+
+            final QuickServerXmlParser parser = QuickServerXmlParser.parse(new File(home,
"conf/server.xml"));
+            final String remoteEjb = System.getProperty(Context.PROVIDER_URL, "http://" +
parser.host() + ":" + parser.http() + "/tomee/ejb");
+
+            try {
+                instance = new RemoteTomEEEJBContainer();
+                instance.container = new RemoteServer();
+                instance.container.setPortStartup(Integer.parseInt(parser.http()));
+
+                try {
+                    instance.container.start();
+                } catch (final Exception e) {
+                    instance.container.destroy();
+                    throw e;
+                }
+
+                instance.context = new InitialContext(new Properties() {{
+                    setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+                    setProperty(Context.PROVIDER_URL, remoteEjb);
+                }});
+
+                final Deployer deployer = Deployer.class.cast(instance.context.lookup("openejb/DeployerBusinessRemote"));
+
+                if (modules instanceof File) {
+                    final File file = File.class.cast(modules);
+                    deployFile(deployer, file);
+                } else if (modules instanceof String) {
+                    final String path = String.class.cast(modules);
+                    final File file = new File(path);
+                    deployFile(deployer, file);
+                } else if (modules instanceof String[]) {
+                    for (final String path : (String[]) modules) {
+                        deployFile(deployer, new File(path));
+                    }
+                } else if (modules instanceof File[]) {
+                    for (final File file : (File[]) modules) {
+                        deployFile(deployer, file);
+                    }
+                } // else suppose already deployed
+
+                return instance;
+            } catch (final OpenEJBException e) {
+                throw new EJBException(e);
+            } catch (final MalformedURLException e) {
+                throw new EJBException(e);
+            } catch (final ValidationException ve) {
+                throw ve;
+            } catch (final Exception e) {
+                if (e instanceof EJBException) {
+                    throw (EJBException) e;
+                }
+                throw new TomEERemoteEJBContainerException("initialization exception", e);
+            }
+        }
+    }
+
+    private static void deployFile(final Deployer deployer, final File file) throws IOException,
OpenEJBException {
+        if ("true".equalsIgnoreCase(System.getProperty(DeployerEjb.OPENEJB_USE_BINARIES,
"false"))) {
+            final Properties props = new Properties();
+            final byte[] slurpBinaries = IO.slurp(file).getBytes();
+            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
+            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, file.getName());
+            deployer.deploy(file.getAbsolutePath(), props);
+        } else {
+            deployer.deploy(file.getAbsolutePath());
+        }
+    }
+
+    protected static class TomEERemoteEJBContainerException extends RuntimeException {
+        protected TomEERemoteEJBContainerException(final String s, final Exception e) {
+            super(s, e);
+        }
+    }
+}


Mime
View raw message