Coverage Report - org.mule.transport.servlet.jetty.util.EmbeddedJettyServer
 
Classes in this File Line Coverage Branch Coverage Complexity
EmbeddedJettyServer
0%
0/13
N/A
1
EmbeddedJettyServer$1
0%
0/4
N/A
1
 
 1  
 /*
 2  
  * $Id: EmbeddedJettyServer.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.transport.servlet.jetty.util;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.config.MuleProperties;
 14  
 
 15  
 import javax.servlet.Servlet;
 16  
 import javax.servlet.ServletContextEvent;
 17  
 import javax.servlet.ServletContextListener;
 18  
 
 19  
 import org.mortbay.jetty.Server;
 20  
 import org.mortbay.jetty.servlet.Context;
 21  
 import org.mortbay.jetty.servlet.ServletHolder;
 22  
 
 23  
 /**
 24  
  * A simple helper class for Mule testing that creates an embedded Jetty Server
 25  
  */
 26  
 public class EmbeddedJettyServer
 27  
 {
 28  
     private Server httpServer;
 29  
 
 30  
     public EmbeddedJettyServer(int port, String contextPath, String servletPath, Servlet servlet, final MuleContext context)
 31  0
     {
 32  0
          httpServer = new Server(port);
 33  
 
 34  0
         Context c = new Context(httpServer, contextPath, Context.SESSIONS);
 35  0
         c.addServlet(new ServletHolder(servlet), servletPath);
 36  0
         c.addEventListener(new ServletContextListener() {
 37  
             public void contextInitialized(ServletContextEvent sce)
 38  
             {
 39  0
                 sce.getServletContext().setAttribute(MuleProperties.MULE_CONTEXT_PROPERTY, context);
 40  0
             }
 41  
 
 42  0
             public void contextDestroyed(ServletContextEvent sce) { }
 43  
         });
 44  0
     }
 45  
 
 46  
     public void start() throws Exception
 47  
     {
 48  0
         httpServer.start();
 49  0
     }
 50  
 
 51  
     public void stop() throws Exception
 52  
     {
 53  0
         httpServer.stop();
 54  0
     }
 55  
 
 56  
     public void destroy()
 57  
     {
 58  0
         httpServer.destroy();
 59  0
     }
 60  
 
 61  
     public boolean isStarted()
 62  
     {
 63  0
         return httpServer.isStarted();
 64  
     }
 65  
 }