View Javadoc

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