1 package org
.argeo
.cms
.jetty
;
3 import java
.util
.ArrayList
;
5 import java
.util
.Objects
;
7 import org
.argeo
.cms
.websocket
.server
.WebsocketEndpoints
;
8 import org
.eclipse
.jetty
.ee8
.servlet
.ServletContextHandler
;
10 import com
.sun
.net
.httpserver
.Authenticator
;
11 import com
.sun
.net
.httpserver
.Filter
;
12 import com
.sun
.net
.httpserver
.HttpContext
;
13 import com
.sun
.net
.httpserver
.HttpHandler
;
14 import com
.sun
.net
.httpserver
.HttpServer
;
17 * An @{HttpContext} implementation based on Jetty. It supports web sockets if
18 * the handler implements {@link WebsocketEndpoints}.
20 abstract class JettyHttpContext
extends HttpContext
{
21 private final JettyHttpServer httpServer
;
22 private final String path
;
23 private final List
<Filter
> filters
= new ArrayList
<>();
25 private HttpHandler handler
;
26 private Authenticator authenticator
;
28 public JettyHttpContext(JettyHttpServer httpServer
, String path
) {
29 this.httpServer
= httpServer
;
30 if (!path
.endsWith("/"))
31 throw new IllegalArgumentException("Path " + path
+ " should end with a /");
35 protected abstract ServletContextHandler
getServletContextHandler();
38 public HttpHandler
getHandler() {
43 public void setHandler(HttpHandler handler
) {
44 if (this.handler
!= null)
45 throw new IllegalArgumentException("Handler is already set");
46 Objects
.requireNonNull(handler
);
47 this.handler
= handler
;
51 public String
getPath() {
56 public HttpServer
getServer() {
57 return getJettyHttpServer();
60 protected JettyHttpServer
getJettyHttpServer() {
65 public List
<Filter
> getFilters() {
70 public Authenticator
setAuthenticator(Authenticator auth
) {
71 Authenticator previousAuthenticator
= authenticator
;
72 this.authenticator
= auth
;
73 return previousAuthenticator
;
77 public Authenticator
getAuthenticator() {