1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http.spi;
20
21 import java.io.IOException;
22 import java.net.InetSocketAddress;
23
24 import org.eclipse.jetty.server.Handler;
25 import org.eclipse.jetty.server.Server;
26 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
27 import org.eclipse.jetty.server.handler.DefaultHandler;
28 import org.eclipse.jetty.server.handler.HandlerCollection;
29 import org.eclipse.jetty.util.thread.QueuedThreadPool;
30 import org.eclipse.jetty.util.thread.ThreadPool;
31
32 import com.sun.net.httpserver.HttpServer;
33 import com.sun.net.httpserver.HttpsServer;
34 import com.sun.net.httpserver.spi.HttpServerProvider;
35
36
37
38
39 public class JettyHttpServerProvider extends HttpServerProvider
40 {
41
42 private static Server _server;
43
44 public static void setServer(Server server)
45 {
46 _server = server;
47 }
48
49 @Override
50 public HttpServer createHttpServer(InetSocketAddress addr, int backlog)
51 throws IOException
52 {
53 Server server = _server;
54 boolean shared = true;
55
56 if (server == null)
57 {
58 ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
59 server = new Server(threadPool);
60
61 HandlerCollection handlerCollection = new HandlerCollection();
62 handlerCollection.setHandlers(new Handler[] {new ContextHandlerCollection(), new DefaultHandler()});
63 server.setHandler(handlerCollection);
64
65 shared = false;
66 }
67
68 JettyHttpServer jettyHttpServer = new JettyHttpServer(server, shared);
69 jettyHttpServer.bind(addr, backlog);
70 return jettyHttpServer;
71 }
72
73 @Override
74 public HttpsServer createHttpsServer(InetSocketAddress addr, int backlog) throws IOException
75 {
76 throw new UnsupportedOperationException();
77 }
78
79 }