View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.http.spi;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import com.sun.net.httpserver.Authenticator;
27  import com.sun.net.httpserver.Filter;
28  import com.sun.net.httpserver.HttpHandler;
29  import com.sun.net.httpserver.HttpServer;
30  
31  /**
32   * Jetty implementation of {@link com.sun.net.httpserver.HttpContext}
33   */
34  public class JettyHttpContext extends com.sun.net.httpserver.HttpContext
35  {
36  
37      private HttpSpiContextHandler _jettyContextHandler;
38  
39      private HttpServer _server;
40      
41      private Map<String,Object> _attributes = new HashMap<String,Object>();
42      
43      private List<Filter> _filters = new ArrayList<Filter>();
44      
45      private Authenticator _authenticator;
46  
47  
48      protected JettyHttpContext(HttpServer server, String path,
49              HttpHandler handler)
50      {
51          this._server = server;
52          _jettyContextHandler = new HttpSpiContextHandler(this, handler);
53          _jettyContextHandler.setContextPath(path);
54      }
55  
56      protected HttpSpiContextHandler getJettyContextHandler()
57      {
58          return _jettyContextHandler;
59      }
60  
61      @Override
62      public HttpHandler getHandler()
63      {
64          return _jettyContextHandler.getHttpHandler();
65      }
66  
67      @Override
68      public void setHandler(HttpHandler h)
69      {
70          _jettyContextHandler.setHttpHandler(h);
71      }
72  
73      @Override
74      public String getPath()
75      {
76          return _jettyContextHandler.getContextPath();
77      }
78  
79      @Override
80      public HttpServer getServer()
81      {
82          return _server;
83      }
84  
85      @Override
86      public Map<String, Object> getAttributes()
87      {
88          return _attributes;
89      }
90  
91      @Override
92      public List<Filter> getFilters()
93      {
94          return _filters;
95      }
96  
97      @Override
98      public Authenticator setAuthenticator(Authenticator auth)
99      {
100         Authenticator previous = _authenticator;
101         _authenticator = auth;
102         return previous;
103     }
104 
105     @Override
106     public Authenticator getAuthenticator()
107     {
108         return _authenticator;
109     }
110 
111 }