Author: kmalhi
Date: Thu Jul 7 16:56:27 2011
New Revision: 1143919
URL: http://svn.apache.org/viewvc?rev=1143919&view=rev
Log:
Reformatting
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppLookupException.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatus.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatusRemote.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEArchiveAppender.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEConfiguration.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEContainer.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestEjb.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestServlet.java
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppLookupException.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppLookupException.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppLookupException.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppLookupException.java
Thu Jul 7 16:56:27 2011
@@ -18,21 +18,21 @@ package org.apache.openejb.arquillian;
public class AppLookupException extends Exception {
- private static final long serialVersionUID = 5131748818917110220L;
+ private static final long serialVersionUID = 5131748818917110220L;
- public AppLookupException() {
- }
+ public AppLookupException() {
+ }
- public AppLookupException(String message) {
- super(message);
- }
-
- public AppLookupException(Throwable throwable) {
- super(throwable);
- }
-
- public AppLookupException(String message, Throwable throwable) {
- super(message, throwable);
- }
+ public AppLookupException(String message) {
+ super(message);
+ }
+
+ public AppLookupException(Throwable throwable) {
+ super(throwable);
+ }
+
+ public AppLookupException(String message, Throwable throwable) {
+ super(message, throwable);
+ }
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatus.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatus.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatus.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatus.java
Thu Jul 7 16:56:27 2011
@@ -26,43 +26,43 @@ import javax.ejb.Stateless;
@Stateless
public class AppStatus implements AppStatusRemote {
- public String[] getDeployedApps() throws AppLookupException {
- // Basically the reflection equivalent of:
- //
- // Assembler assembler =
SystemInstance.get().getComponent(Assembler.class);
- // Collection<AppInfo> deployedApplications =
assembler.getDeployedApplications();
- // for (AppInfo appInfo : deployedApplications) {
- // result.add(appInfo.path);
- // }
-
- List<String> result;
- try {
- result = new ArrayList<String>();
-
- Class<?> systemInstanceCls =
Class.forName("org.apache.openejb.loader.SystemInstance");
- Method getMethod = systemInstanceCls.getMethod("get");
- Object systemInstanceObj = getMethod.invoke(null);
-
- Class<?> assemblerCls =
Class.forName("org.apache.openejb.assembler.classic.Assembler");
- Method getComponentMethod = systemInstanceCls.getMethod("getComponent",
Class.class);
- Object assemblerObj = getComponentMethod.invoke(systemInstanceObj,
assemblerCls);
-
- Class<?> appInfoCls =
Class.forName("org.apache.openejb.assembler.classic.AppInfo");
-
- Method getDeployedApplicationsMethod =
assemblerCls.getMethod("getDeployedApplications");
- Collection<?> deployedApplications = (Collection<?>)
getDeployedApplicationsMethod.invoke(assemblerObj);
- for (Object deployedApplication : deployedApplications) {
- String path = (String)
appInfoCls.getDeclaredField("path").get(deployedApplication);
- result.add(path);
- }
-
- return result.toArray(new String[result.size()]);
- } catch (Exception e) {
- throw new AppLookupException("Unable to lookup deployed apps in TomEE.
Is this EJB running in TomEE?", e);
+ public String[] getDeployedApps() throws AppLookupException {
+ // Basically the reflection equivalent of:
+ //
+ // Assembler assembler =
+ // SystemInstance.get().getComponent(Assembler.class);
+ // Collection<AppInfo> deployedApplications =
+ // assembler.getDeployedApplications();
+ // for (AppInfo appInfo : deployedApplications) {
+ // result.add(appInfo.path);
+ // }
+
+ List<String> result;
+ try {
+ result = new ArrayList<String>();
+
+ Class<?> systemInstanceCls =
Class.forName("org.apache.openejb.loader.SystemInstance");
+ Method getMethod = systemInstanceCls.getMethod("get");
+ Object systemInstanceObj = getMethod.invoke(null);
+
+ Class<?> assemblerCls =
Class.forName("org.apache.openejb.assembler.classic.Assembler");
+ Method getComponentMethod =
systemInstanceCls.getMethod("getComponent", Class.class);
+ Object assemblerObj = getComponentMethod.invoke(systemInstanceObj,
assemblerCls);
+
+ Class<?> appInfoCls =
Class.forName("org.apache.openejb.assembler.classic.AppInfo");
+
+ Method getDeployedApplicationsMethod =
assemblerCls.getMethod("getDeployedApplications");
+ Collection<?> deployedApplications = (Collection<?>)
getDeployedApplicationsMethod.invoke(assemblerObj);
+ for (Object deployedApplication : deployedApplications) {
+ String path = (String)
appInfoCls.getDeclaredField("path").get(deployedApplication);
+ result.add(path);
+ }
+
+ return result.toArray(new String[result.size()]);
+ } catch (Exception e) {
+ throw new AppLookupException("Unable to lookup deployed apps in
TomEE. Is this EJB running in TomEE?", e);
+ }
+
}
-
-
-
- }
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatusRemote.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatusRemote.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatusRemote.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/AppStatusRemote.java
Thu Jul 7 16:56:27 2011
@@ -20,5 +20,5 @@ import javax.ejb.Remote;
@Remote
public interface AppStatusRemote {
- public String[] getDeployedApps() throws AppLookupException;
+ public String[] getDeployedApps() throws AppLookupException;
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEArchiveAppender.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEArchiveAppender.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEArchiveAppender.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEArchiveAppender.java
Thu Jul 7 16:56:27 2011
@@ -27,16 +27,11 @@ import org.jboss.shrinkwrap.api.spec.Jav
public class TomEEArchiveAppender implements AuxiliaryArchiveAppender {
- public Archive<?> createAuxiliaryArchive() {
- JavaArchive archive = ShrinkWrap
- .create(JavaArchive.class, "arquillian-jboss-testenrichers.jar")
- .addPackages(true, EJBInjectionEnricher.class.getPackage(),
- ResourceInjectionEnricher.class.getPackage(),
- CDIInjectionEnricher.class.getPackage())
- .addAsServiceProvider(TestEnricher.class,
- CDIInjectionEnricher.class, EJBInjectionEnricher.class,
- ResourceInjectionEnricher.class);
- return archive;
- }
+ public Archive<?> createAuxiliaryArchive() {
+ JavaArchive archive = ShrinkWrap.create(JavaArchive.class,
"arquillian-jboss-testenrichers.jar")
+ .addPackages(true, EJBInjectionEnricher.class.getPackage(),
ResourceInjectionEnricher.class.getPackage(),
CDIInjectionEnricher.class.getPackage())
+ .addAsServiceProvider(TestEnricher.class,
CDIInjectionEnricher.class, EJBInjectionEnricher.class,
ResourceInjectionEnricher.class);
+ return archive;
+ }
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEConfiguration.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEConfiguration.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEConfiguration.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEConfiguration.java
Thu Jul 7 16:56:27 2011
@@ -21,65 +21,65 @@ import org.jboss.arquillian.spi.client.c
public class TomEEConfiguration implements ContainerConfiguration {
- private int httpPort = 8080;
- private int stopPort = 8005;
- private String stopCommand = "SHUTDOWN";
- private String dir = System.getProperty("java.io.tmpdir") +
"/arquillian-apache-tomee";
- private String openejbPath = "lib/openejb.war";
- private int timeout = 30;
-
- public int getHttpPort() {
- return httpPort;
- }
-
- public void setHttpPort(int httpPort) {
- this.httpPort = httpPort;
- }
-
- public int getStopPort() {
- return stopPort;
- }
-
- public void setStopPort(int stopPort) {
- this.stopPort = stopPort;
- }
-
- public String getStopCommand() {
- return stopCommand;
- }
-
- public void setStopCommand(String stopCommand) {
- this.stopCommand = stopCommand;
- }
-
- public String getDir() {
- return dir;
- }
-
- public void setDir(String dir) {
- this.dir = dir;
- }
-
- public String getOpenejbPath() {
- return openejbPath;
- }
-
- public void setOpenejbPath(String openejbPath) {
- this.openejbPath = openejbPath;
- }
-
- public void validate() throws ConfigurationException {
- }
-
- public int getTimeOut() {
- return timeout;
- }
-
- public int getTimeout() {
- return timeout;
- }
-
- public void setTimeout(int timeout) {
- this.timeout = timeout;
- }
+ private int httpPort = 8080;
+ private int stopPort = 8005;
+ private String stopCommand = "SHUTDOWN";
+ private String dir = System.getProperty("java.io.tmpdir") +
"/arquillian-apache-tomee";
+ private String openejbPath = "lib/openejb.war";
+ private int timeout = 30;
+
+ public int getHttpPort() {
+ return httpPort;
+ }
+
+ public void setHttpPort(int httpPort) {
+ this.httpPort = httpPort;
+ }
+
+ public int getStopPort() {
+ return stopPort;
+ }
+
+ public void setStopPort(int stopPort) {
+ this.stopPort = stopPort;
+ }
+
+ public String getStopCommand() {
+ return stopCommand;
+ }
+
+ public void setStopCommand(String stopCommand) {
+ this.stopCommand = stopCommand;
+ }
+
+ public String getDir() {
+ return dir;
+ }
+
+ public void setDir(String dir) {
+ this.dir = dir;
+ }
+
+ public String getOpenejbPath() {
+ return openejbPath;
+ }
+
+ public void setOpenejbPath(String openejbPath) {
+ this.openejbPath = openejbPath;
+ }
+
+ public void validate() throws ConfigurationException {
+ }
+
+ public int getTimeOut() {
+ return timeout;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEContainer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEContainer.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEContainer.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/main/java/org/apache/openejb/arquillian/TomEEContainer.java
Thu Jul 7 16:56:27 2011
@@ -56,219 +56,219 @@ import org.jboss.shrinkwrap.descriptor.a
public class TomEEContainer implements DeployableContainer<TomEEConfiguration>
{
- private Bootstrap bootstrap;
- private TomEEConfiguration configuration;
- private File catalinaDirectory;
- private boolean usingOpenEJB;
-
- public Class<TomEEConfiguration> getConfigurationClass() {
- return TomEEConfiguration.class;
- }
-
- public void setup(TomEEConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public void start() throws LifecycleException {
- try {
- System.setProperty("openejb.deployments.classpath.exclude", ".*");
- System.setProperty("openejb.deployments.classpath.include", "");
-
- catalinaDirectory = new File(configuration.getDir());
- if (catalinaDirectory.exists()) {
- catalinaDirectory.delete();
- }
-
- catalinaDirectory.mkdirs();
- catalinaDirectory.deleteOnExit();
-
- createTomcatDirectories(catalinaDirectory);
-
- // copy configs
- copyConfigs(catalinaDirectory);
-
- // deploy status helper app
- copyArchive(getStatusApp());
-
- // call Bootstrap();
- System.out.println("Starting TomEE from: " +
catalinaDirectory.getAbsolutePath());
-
- String catalinaBase = catalinaDirectory.getAbsolutePath();
-
- System.setProperty("catalina.home", catalinaBase);
- System.setProperty("catalina.base", catalinaBase);
-
- bootstrap = new Bootstrap();
- bootstrap.start();
- } catch (Exception e) {
- e.printStackTrace();
- throw new LifecycleException("Summat went wrong", e);
- }
- }
-
- private Archive<?> getStatusApp() {
- return ShrinkWrap.create(JavaArchive.class, "status.jar")
- .addClass(AppStatus.class)
- .addClass(AppStatusRemote.class)
- .addClass(AppLookupException.class)
- .addAsResource(new StringAsset("<ejb-jar/>"), "META-INF/ejb-jar.xml");
- }
-
- public void stop() throws LifecycleException {
- try {
- bootstrap.stopServer();
- deleteTree(catalinaDirectory);
- } catch (Exception e) {
- throw new LifecycleException("Unable to stop server", e);
- }
- }
-
- public ProtocolDescription getDefaultProtocol() {
- return new ProtocolDescription("Servlet 3.0");
- }
-
- public ProtocolMetaData deploy(Archive<?> archive) throws
DeploymentException {
- try {
- copyArchive(archive);
-
- boolean deployed = false;
- int attempts = 0;
- while (attempts < configuration.getTimeout() && deployed == false) {
- // need to poll for the app being deployed
- attempts++;
- Thread.sleep(1000);
-
- deployed = checkDeploymentStatus(archive);
- }
-
- HTTPContext httpContext = new HTTPContext("0.0.0.0",
configuration.getHttpPort());
- return new ProtocolMetaData().addContext(httpContext);
- } catch (Exception e) {
- e.printStackTrace();
- throw new DeploymentException("Unable to deploy", e);
- }
- }
-
- private void copyArchive(Archive<?> archive) throws IOException,
FileNotFoundException {
- InputStream is = archive.as(ZipExporter.class).exportAsInputStream();
- copyStream(is, new FileOutputStream(new File(catalinaDirectory, "webapps/"
+ archive.getName())));
- }
-
- private boolean checkDeploymentStatus(Archive<?> archive) throws Exception {
- if (usingOpenEJB) {
- try {
- String dir = getDir(catalinaDirectory.getAbsolutePath() + "/webapps/"
+ archive.getName());
-
- Properties properties = new Properties();
- properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
- properties.setProperty(Context.PROVIDER_URL, "http://localhost:" +
configuration.getHttpPort() + "/openejb/ejb");
-
- InitialContext context = new InitialContext(properties);
- AppStatusRemote appStatus = (AppStatusRemote)
context.lookup("AppStatusRemote");
- String[] deployedApps = appStatus.getDeployedApps();
- for (String deployedApp : deployedApps) {
- if (deployedApp.equals(dir)) {
- return true;
- }
+ private Bootstrap bootstrap;
+ private TomEEConfiguration configuration;
+ private File catalinaDirectory;
+ private boolean usingOpenEJB;
+
+ public Class<TomEEConfiguration> getConfigurationClass() {
+ return TomEEConfiguration.class;
+ }
+
+ public void setup(TomEEConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public void start() throws LifecycleException {
+ try {
+ System.setProperty("openejb.deployments.classpath.exclude", ".*");
+ System.setProperty("openejb.deployments.classpath.include", "");
+
+ catalinaDirectory = new File(configuration.getDir());
+ if (catalinaDirectory.exists()) {
+ catalinaDirectory.delete();
+ }
+
+ catalinaDirectory.mkdirs();
+ catalinaDirectory.deleteOnExit();
+
+ createTomcatDirectories(catalinaDirectory);
+
+ // copy configs
+ copyConfigs(catalinaDirectory);
+
+ // deploy status helper app
+ copyArchive(getStatusApp());
+
+ // call Bootstrap();
+ System.out.println("Starting TomEE from: " +
catalinaDirectory.getAbsolutePath());
+
+ String catalinaBase = catalinaDirectory.getAbsolutePath();
+
+ System.setProperty("catalina.home", catalinaBase);
+ System.setProperty("catalina.base", catalinaBase);
+
+ bootstrap = new Bootstrap();
+ bootstrap.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new LifecycleException("Summat went wrong", e);
+ }
+ }
+
+ private Archive<?> getStatusApp() {
+ return ShrinkWrap.create(JavaArchive.class,
"status.jar").addClass(AppStatus.class).addClass(AppStatusRemote.class).addClass(AppLookupException.class)
+ .addAsResource(new StringAsset("<ejb-jar/>"),
"META-INF/ejb-jar.xml");
+ }
+
+ public void stop() throws LifecycleException {
+ try {
+ bootstrap.stopServer();
+ deleteTree(catalinaDirectory);
+ } catch (Exception e) {
+ throw new LifecycleException("Unable to stop server", e);
}
- } catch (Exception e) {
- }
-
- return false;
- } else {
- String context = getDir(archive.getName());
-
- MBeanServer platformMBeanServer =
ManagementFactory.getPlatformMBeanServer();
- Set<ObjectInstance> mbeans = platformMBeanServer.queryMBeans(new
ObjectName("Catalina:type=Manager,context=/" + context + ",*"), null);
- for (ObjectInstance objectInstance : mbeans) {
- String status = (String)
platformMBeanServer.getAttribute(objectInstance.getObjectName(), "stateName");
- if ("STARTED".equals(status)) {
- return true;
+ }
+
+ public ProtocolDescription getDefaultProtocol() {
+ return new ProtocolDescription("Servlet 3.0");
+ }
+
+ public ProtocolMetaData deploy(Archive<?> archive) throws
DeploymentException {
+ try {
+ copyArchive(archive);
+
+ boolean deployed = false;
+ int attempts = 0;
+ while (attempts < configuration.getTimeout() && deployed == false)
{
+ // need to poll for the app being deployed
+ attempts++;
+ Thread.sleep(1000);
+
+ deployed = checkDeploymentStatus(archive);
+ }
+
+ HTTPContext httpContext = new HTTPContext("0.0.0.0",
configuration.getHttpPort());
+ return new ProtocolMetaData().addContext(httpContext);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new DeploymentException("Unable to deploy", e);
}
- }
- return false;
}
- }
- public void undeploy(Archive<?> archive) throws DeploymentException {
- // remove the archive file
- new File(catalinaDirectory,"webapps/" + archive.getName()).delete();
-
- // remove the directory
- deleteTree(new File(catalinaDirectory, "/webapps/" +
getDir(archive.getName())));
- }
-
- private String getDir(String filename) {
- int lastDot = filename.lastIndexOf(".");
- if (lastDot == -1) {
- return filename;
- }
-
- return filename.substring(0, lastDot);
- }
-
- private void deleteTree(File file) {
- if (file == null) return;
- if (! file.exists()) return;
-
- if (file.isFile()) {
- file.delete();
- return;
- }
-
- if (file.isDirectory()) {
- if (".".equals(file.getName())) return;
- if ("..".equals(file.getName())) return;
-
- File[] children = file.listFiles();
-
- for (File child : children) {
- deleteTree(child);
- }
-
- file.delete();
- }
- }
-
- public void deploy(Descriptor descriptor) throws DeploymentException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- public void undeploy(Descriptor descriptor) throws DeploymentException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- private void copyConfigs(File directory) throws Exception {
- File confDir = new File(directory, "conf");
- copyFileTo(confDir, "catalina.policy");
- copyTemplateTo(confDir, "catalina.properties");
- copyFileTo(confDir, "context.xml");
- copyFileTo(confDir, "logging.properties");
- copyFileTo(confDir, "openejb.xml");
- copyFileTo(confDir, "server.xml");
- copyFileTo(confDir, "tomcat-users.xml");
- copyFileTo(confDir, "web.xml");
-
- String openejbPath = configuration.getOpenejbPath();
-
-
- if (openejbPath != null && openejbPath.length() > 0) {
- usingOpenEJB = true;
- try {
- if (openejbPath.startsWith("classpath:/")) {
- URL resource =
TomEEContainer.class.getResource(openejbPath.substring(10));
- copyStream(resource.openStream(), new FileOutputStream(new
File(directory, "webapps/openejb.war")));
+ private void copyArchive(Archive<?> archive) throws IOException,
FileNotFoundException {
+ InputStream is = archive.as(ZipExporter.class).exportAsInputStream();
+ copyStream(is, new FileOutputStream(new File(catalinaDirectory,
"webapps/" + archive.getName())));
+ }
+
+ private boolean checkDeploymentStatus(Archive<?> archive) throws Exception
{
+ if (usingOpenEJB) {
+ try {
+ String dir = getDir(catalinaDirectory.getAbsolutePath() +
"/webapps/" + archive.getName());
+
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
+ properties.setProperty(Context.PROVIDER_URL,
"http://localhost:" + configuration.getHttpPort() + "/openejb/ejb");
+
+ InitialContext context = new InitialContext(properties);
+ AppStatusRemote appStatus = (AppStatusRemote)
context.lookup("AppStatusRemote");
+ String[] deployedApps = appStatus.getDeployedApps();
+ for (String deployedApp : deployedApps) {
+ if (deployedApp.equals(dir)) {
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ return false;
} else {
- FileInputStream is = new FileInputStream(new File(openejbPath));
- copyStream(is, new FileOutputStream(new File(directory,
"webapps/openejb.war")));
+ String context = getDir(archive.getName());
+
+ MBeanServer platformMBeanServer =
ManagementFactory.getPlatformMBeanServer();
+ Set<ObjectInstance> mbeans = platformMBeanServer.queryMBeans(new
ObjectName("Catalina:type=Manager,context=/" + context + ",*"), null);
+ for (ObjectInstance objectInstance : mbeans) {
+ String status = (String)
platformMBeanServer.getAttribute(objectInstance.getObjectName(), "stateName");
+ if ("STARTED".equals(status)) {
+ return true;
+ }
+ }
+ return false;
}
- } catch (Exception e) {
- usingOpenEJB = false;
- }
}
- }
- private void copyTemplateTo(File targetDir, String filename) throws
Exception {
+ public void undeploy(Archive<?> archive) throws DeploymentException {
+ // remove the archive file
+ new File(catalinaDirectory, "webapps/" + archive.getName()).delete();
+
+ // remove the directory
+ deleteTree(new File(catalinaDirectory, "/webapps/" +
getDir(archive.getName())));
+ }
+
+ private String getDir(String filename) {
+ int lastDot = filename.lastIndexOf(".");
+ if (lastDot == -1) {
+ return filename;
+ }
+
+ return filename.substring(0, lastDot);
+ }
+
+ private void deleteTree(File file) {
+ if (file == null)
+ return;
+ if (!file.exists())
+ return;
+
+ if (file.isFile()) {
+ file.delete();
+ return;
+ }
+
+ if (file.isDirectory()) {
+ if (".".equals(file.getName()))
+ return;
+ if ("..".equals(file.getName()))
+ return;
+
+ File[] children = file.listFiles();
+
+ for (File child : children) {
+ deleteTree(child);
+ }
+
+ file.delete();
+ }
+ }
+
+ public void deploy(Descriptor descriptor) throws DeploymentException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ public void undeploy(Descriptor descriptor) throws DeploymentException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ private void copyConfigs(File directory) throws Exception {
+ File confDir = new File(directory, "conf");
+ copyFileTo(confDir, "catalina.policy");
+ copyTemplateTo(confDir, "catalina.properties");
+ copyFileTo(confDir, "context.xml");
+ copyFileTo(confDir, "logging.properties");
+ copyFileTo(confDir, "openejb.xml");
+ copyFileTo(confDir, "server.xml");
+ copyFileTo(confDir, "tomcat-users.xml");
+ copyFileTo(confDir, "web.xml");
+
+ String openejbPath = configuration.getOpenejbPath();
+
+ if (openejbPath != null && openejbPath.length() > 0) {
+ usingOpenEJB = true;
+ try {
+ if (openejbPath.startsWith("classpath:/")) {
+ URL resource =
TomEEContainer.class.getResource(openejbPath.substring(10));
+ copyStream(resource.openStream(), new FileOutputStream(new
File(directory, "webapps/openejb.war")));
+ } else {
+ FileInputStream is = new FileInputStream(new
File(openejbPath));
+ copyStream(is, new FileOutputStream(new File(directory,
"webapps/openejb.war")));
+ }
+ } catch (Exception e) {
+ usingOpenEJB = false;
+ }
+ }
+ }
+
+ private void copyTemplateTo(File targetDir, String filename) throws
Exception {
Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new
Log4JLogChute());
Velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
Velocity.setProperty("class.resource.loader.description", "Velocity
Classpath Resource Loader");
@@ -282,40 +282,39 @@ public class TomEEContainer implements D
Writer writer = new FileWriter(new File(targetDir, filename));
template.merge(context, writer);
writer.flush();
- writer.close();
- }
+ writer.close();
+ }
+
+ private void copyFileTo(File targetDir, String filename) throws
IOException {
+ InputStream is =
getClass().getResourceAsStream("/org/apache/openejb/tomee/configs/" + filename);
+ FileOutputStream os = new FileOutputStream(new File(targetDir,
filename));
+
+ copyStream(is, os);
+ }
+
+ private void copyStream(InputStream is, FileOutputStream os) throws
IOException {
+ byte[] buffer = new byte[8192];
+ int bytesRead = -1;
- private void copyFileTo(File targetDir, String filename) throws IOException {
- InputStream is =
getClass().getResourceAsStream("/org/apache/openejb/tomee/configs/" + filename);
- FileOutputStream os = new FileOutputStream(new File(targetDir, filename));
-
- copyStream(is, os);
- }
-
- private void copyStream(InputStream is, FileOutputStream os)
- throws IOException {
- byte[] buffer = new byte[8192];
- int bytesRead = -1;
-
- while ((bytesRead = is.read(buffer)) > -1) {
- os.write(buffer, 0, bytesRead);
- }
-
- is.close();
- os.close();
- }
-
- private void createTomcatDirectories(File directory) {
- createDirectory(directory, "apps");
- createDirectory(directory, "conf");
- createDirectory(directory, "lib");
- createDirectory(directory, "logs");
- createDirectory(directory, "webapps");
- createDirectory(directory, "temp");
- createDirectory(directory, "work");
- }
-
- private void createDirectory(File parent, String directory) {
- new File(parent, directory).mkdirs();
- }
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+ }
+
+ private void createTomcatDirectories(File directory) {
+ createDirectory(directory, "apps");
+ createDirectory(directory, "conf");
+ createDirectory(directory, "lib");
+ createDirectory(directory, "logs");
+ createDirectory(directory, "webapps");
+ createDirectory(directory, "temp");
+ createDirectory(directory, "work");
+ }
+
+ private void createDirectory(File parent, String directory) {
+ new File(parent, directory).mkdirs();
+ }
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestEjb.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestEjb.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestEjb.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestEjb.java
Thu Jul 7 16:56:27 2011
@@ -21,8 +21,8 @@ import javax.ejb.Stateless;
@Stateless
public class TestEjb {
- public String greet(String name) {
- return "Hello, " + name;
- }
-
+ public String greet(String name) {
+ return "Hello, " + name;
+ }
+
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestServlet.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestServlet.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestServlet.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TestServlet.java
Thu Jul 7 16:56:27 2011
@@ -25,19 +25,18 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
-
- @EJB
- private TestEjb myEjb;
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
- String name = req.getParameter("name");
- if (name == null || name.length() == 0) {
- name = "OpenEJB";
+ @EJB
+ private TestEjb myEjb;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+ String name = req.getParameter("name");
+ if (name == null || name.length() == 0) {
+ name = "OpenEJB";
+ }
+
+ resp.getOutputStream().print(myEjb.greet(name));
}
-
- resp.getOutputStream().print(myEjb.greet(name));
- }
-
-
+
}
Modified:
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1143919&r1=1143918&r2=1143919&view=diff
==============================================================================
---
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
(original)
+++
openejb/trunk/sandbox/arquillian-tomee/arquillian-tomee-container/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
Thu Jul 7 16:56:27 2011
@@ -35,35 +35,28 @@ import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class TomEEContainerTest {
- @Deployment(testable=false)
- public static WebArchive createDeployment() {
- return ShrinkWrap.create(WebArchive.class, "test.war")
- .addClass(TestServlet.class)
- .addClass(TestEjb.class)
- .setWebXML(new StringAsset(
- Descriptors.create(WebAppDescriptor.class)
- .version("3.0")
- .servlet(TestServlet.class, "/Test")
- .exportAsString()
- ));
- }
-
- @Test
- public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
- InputStream is = new URL("http://localhost:9080/test/Test").openStream();
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- int bytesRead = -1;
- byte[] buffer = new byte[8192];
- while ((bytesRead = is.read(buffer)) > -1) {
- os.write(buffer, 0, bytesRead);
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ return ShrinkWrap.create(WebArchive.class,
"test.war").addClass(TestServlet.class).addClass(TestEjb.class)
+ .setWebXML(new
StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
"/Test").exportAsString()));
}
-
- is.close();
- os.close();
-
- String output = new String(os.toByteArray(), "UTF-8");
- Assert.assertTrue(output.contains("Hello, OpenEJB"));
- }
-
+
+ @Test
+ public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
+ InputStream is = new
URL("http://localhost:9080/test/Test").openStream();
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ Assert.assertTrue(output.contains("Hello, OpenEJB"));
+ }
+
}