View Javadoc
1   /*
2    * Copyright (C) 2007-2014 JMPEAX.
3    *
4    *     This program is free software: you can redistribute it and/or modify
5    *     it under the terms of the GNU General Public License as published by
6    *     the Free Software Foundation, either version 3 of the License, or
7    *     (at your option) any later version.
8    *
9    *     This program is distributed in the hope that it will be useful,
10   *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *     GNU General Public License for more details.
13   *
14   *     You should have received a copy of the GNU General Public License
15   *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package com.jmpeax.osgi.undertow.http.impl;
19  
20  import org.osgi.service.http.HttpContext;
21  import org.osgi.service.http.HttpService;
22  import org.osgi.service.http.NamespaceException;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import javax.servlet.Servlet;
27  import javax.servlet.ServletException;
28  import java.util.Dictionary;
29  
30  /**
31   * Implementation of HttpService internally uses {@link com.jmpeax.osgi.undertow.http.impl.UndertowHttpServer}
32   *
33   * @author Carlos Ortiz.
34   * @since 1.0.0.
35   */
36  public class UndertowHttpService implements HttpService {
37  
38      private UndertowHttpServer httpServer;
39  
40      private Logger log = LoggerFactory.getLogger(UndertowHttpService.class);
41  
42      public UndertowHttpService(UndertowHttpServer httpServer) {
43          this.httpServer = httpServer;
44      }
45  
46      @Override
47      public void registerServlet(final String alias, final Servlet servlet, final Dictionary initparams, final HttpContext context) throws ServletException, NamespaceException {
48          log.debug("Registering {} with servlet {} properties {} and context {}", alias, servlet, initparams, context);
49          httpServer.addServletHandler(alias, servlet, initparams);
50      }
51  
52      @Override
53      public void registerResources(final String alias, final String name, final HttpContext context) throws NamespaceException {
54  
55      }
56  
57      @Override
58      public void unregister(final String alias) {
59          httpServer.removeHandler(alias);
60      }
61  
62      @Override
63      public HttpContext createDefaultHttpContext() {
64          return null;
65      }
66  }