1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
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 | |
} |