All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.test.EmbeddedContainer Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package org.jboss.resteasy.test;

import org.jboss.resteasy.plugins.server.embedded.SecurityDomain;
import org.jboss.resteasy.spi.ResteasyDeployment;

import java.lang.reflect.Method;
import java.util.Hashtable;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
public class EmbeddedContainer
{
   private static Class bootstrap = TJWSServletContainer.class;

   public static Class getBootstrap()
   {
      return bootstrap;
   }

   /**
    * Exists for tests that require a servlet container behind the scenes.
    *
    * @return
    */
   public static boolean isServlet()
   {
      return true;
   }

   static
   {
      String boot = System.getProperty("org.resteasy.test.embedded.container");
      if (boot != null)
      {
         try
         {
            bootstrap = Thread.currentThread().getContextClassLoader().loadClass(boot);
         }
         catch (ClassNotFoundException e)
         {
            throw new RuntimeException(e);
         }
      }
   }

   public static void setBootstrap(Class bootstrap)
   {
      EmbeddedContainer.bootstrap = bootstrap;
   }

   public static ResteasyDeployment start() throws Exception
   {
      return start("/", (Hashtable) null);
   }
   
   public static ResteasyDeployment start(String bindPath) throws Exception
   {
      return start(bindPath, null, null);
   }
   
   public static ResteasyDeployment start(Hashtable initParams) throws Exception
   {
      return start("/", initParams);
   }

   public static ResteasyDeployment start(Hashtable initParams, Hashtable contextParams) throws Exception
   {
      return start("/", initParams, contextParams);
   }
   
   public static ResteasyDeployment start(String bindPath, Hashtable initParams) throws Exception
   {
      Method start = bootstrap.getMethod("start", String.class, Hashtable.class);
      return (ResteasyDeployment) start.invoke(null, bindPath, initParams);
   }

   public static ResteasyDeployment start(String bindPath, Hashtable initParams, Hashtable contextParams) throws Exception
   {
      Method start = bootstrap.getMethod("start", String.class, Hashtable.class, Hashtable.class);
      return (ResteasyDeployment) start.invoke(null, bindPath, initParams, contextParams);
   }
   
   public static ResteasyDeployment start(String bindPath, SecurityDomain domain) throws Exception
   {
      Method start = bootstrap.getMethod("start", String.class, SecurityDomain.class);
      return (ResteasyDeployment) start.invoke(null, bindPath, domain);

   }

   public static void start(ResteasyDeployment deployment) throws Exception
   {
      Method start = bootstrap.getMethod("start", ResteasyDeployment.class);
      start.invoke(null, deployment);

   }

   public static void stop() throws Exception
   {
      Method stop = bootstrap.getMethod("stop");
      stop.invoke(null);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy