1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.servlet.jetty.util; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.config.MuleProperties; |
11 | |
|
12 | |
import javax.servlet.Servlet; |
13 | |
import javax.servlet.ServletContextEvent; |
14 | |
import javax.servlet.ServletContextListener; |
15 | |
|
16 | |
import org.mortbay.jetty.Server; |
17 | |
import org.mortbay.jetty.servlet.Context; |
18 | |
import org.mortbay.jetty.servlet.ServletHolder; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class EmbeddedJettyServer |
24 | |
{ |
25 | |
private Server httpServer; |
26 | |
|
27 | |
public EmbeddedJettyServer(int port, String contextPath, String servletPath, Servlet servlet, final MuleContext context) |
28 | 0 | { |
29 | 0 | httpServer = new Server(port); |
30 | |
|
31 | 0 | Context c = new Context(httpServer, contextPath, Context.SESSIONS); |
32 | 0 | c.addServlet(new ServletHolder(servlet), servletPath); |
33 | 0 | c.addEventListener(new ServletContextListener() { |
34 | |
public void contextInitialized(ServletContextEvent sce) |
35 | |
{ |
36 | 0 | sce.getServletContext().setAttribute(MuleProperties.MULE_CONTEXT_PROPERTY, context); |
37 | 0 | } |
38 | |
|
39 | 0 | public void contextDestroyed(ServletContextEvent sce) { } |
40 | |
}); |
41 | 0 | } |
42 | |
|
43 | |
public void start() throws Exception |
44 | |
{ |
45 | 0 | httpServer.start(); |
46 | 0 | } |
47 | |
|
48 | |
public void stop() throws Exception |
49 | |
{ |
50 | 0 | httpServer.stop(); |
51 | 0 | } |
52 | |
|
53 | |
public void destroy() |
54 | |
{ |
55 | 0 | httpServer.destroy(); |
56 | 0 | } |
57 | |
|
58 | |
public boolean isStarted() |
59 | |
{ |
60 | 0 | return httpServer.isStarted(); |
61 | |
} |
62 | |
} |