Java Code Examples for org.eclipse.jetty.servlet.ServletHolder#setName()

The following examples show how to use org.eclipse.jetty.servlet.ServletHolder#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExplorerServer.java    From Explorer with Apache License 2.0 6 votes vote down vote up
/**
 * Swagger core handler - Needed for the RestFul api documentation
 *
 * @return ServletContextHandler of Swagger
 */
private static ServletContextHandler setupSwaggerContextHandler(int port) {
    // Configure Swagger-core
    final ServletHolder SwaggerServlet = new ServletHolder(
            new com.wordnik.swagger.jersey.config.JerseyJaxrsConfig());
    SwaggerServlet.setName("JerseyJaxrsConfig");
    SwaggerServlet.setInitParameter("api.version", "1.0.0");
    SwaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:" + port + "/api");
    SwaggerServlet.setInitOrder(2);

    // Setup the handler
    final ServletContextHandler handler = new ServletContextHandler();
    handler.setSessionHandler(new SessionHandler());
    handler.addServlet(SwaggerServlet, "/api-docs/*");
    return handler;
}
 
Example 2
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing {} servlet at path {}; will replace mapping with {} servlet"
            , servletMappings[i].getServletName(), pathSpec, sh.getName());
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 3
Source File: ZeppelinServer.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
private static void setupRestApiContextHandler(WebAppContext webapp, ZeppelinConfiguration conf) {
  final ServletHolder servletHolder =
      new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer());

  servletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
  servletHolder.setName("rest");
  servletHolder.setForcedPath("rest");
  webapp.setSessionHandler(new SessionHandler());
  webapp.addServlet(servletHolder, "/api/*");

  String shiroIniPath = conf.getShiroPath();
  if (!StringUtils.isBlank(shiroIniPath)) {
    webapp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
    webapp
        .addFilter(ShiroFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class))
        .setInitParameter("staticSecurityManagerEnabled", "true");
    webapp.addEventListener(new EnvironmentLoaderListener());
  }
}
 
Example 4
Source File: HttpServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, boolean requireAuthz) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  if (authenticationEnabled && requireAuthz) {
    FilterHolder filter = new FilterHolder(AdminAuthorizedFilter.class);
    filter.setName(AdminAuthorizedFilter.class.getSimpleName());
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setDispatches(FilterMapping.ALL);
    fmap.setFilterName(AdminAuthorizedFilter.class.getSimpleName());
    webAppContext.getServletHandler().addFilter(filter, fmap);
  }
  webAppContext.addServlet(holder, pathSpec);
}
 
Example 5
Source File: VarOneServer.java    From varOne with MIT License 5 votes vote down vote up
private static ServletContextHandler setupResourcesContextHandler(
		VarOneConfiguration conf) {
	final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    cxfServletHolder.setInitParameter("javax.ws.rs.Application", VarOneServer.class.getName());
    cxfServletHolder.setName("rest");
    cxfServletHolder.setForcedPath("rest");

    final ServletContextHandler cxfContext = new ServletContextHandler();
    cxfContext.setSessionHandler(new SessionHandler());
    cxfContext.setContextPath(conf.getServerContextPath());
    cxfContext.addServlet(cxfServletHolder, "/rest/*");

    return cxfContext;
}
 
Example 6
Source File: ExplorerServer.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler setupRestApiContextHandler() {
    final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    cxfServletHolder.setInitParameter("javax.ws.rs.Application", ExplorerServer.class.getName());
    cxfServletHolder.setName("rest");
    cxfServletHolder.setForcedPath("rest");

    final ServletContextHandler cxfContext = new ServletContextHandler();
    cxfContext.setSessionHandler(new SessionHandler());
    cxfContext.setContextPath("/api");
    cxfContext.addServlet(cxfServletHolder, "/*");
    cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*",
            EnumSet.allOf(DispatcherType.class));
    return cxfContext;
}
 
Example 7
Source File: ServletHolderMapper.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Override
public ServletHolder apply(ServletDescriptor servletDescriptor) {
    ServletHolder servletHolder = servletHandler.newServletHolder(Source.EMBEDDED);
    servletHolder.setHeldClass(servletDescriptor.servletClass());
    servletHolder.setName(servletDescriptor.name());
    if(servletDescriptor.initParams() != null) {
        Arrays.stream(servletDescriptor.initParams())
                .forEach(p -> servletHolder.setInitParameter(p.name(), p.value()));
    }
    for(String pattern : servletDescriptor.urlPatterns()) {
        servletHandler.addServletWithMapping(servletHolder, pattern);
    }
    return servletHolder;
}
 
Example 8
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 9
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 10
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 11
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (ServletMapping servletMapping : servletMappings) {
    if (servletMapping.containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMapping.getServletName() +
                      " servlet at path " + pathSpec + "; will replace mapping" +
                      " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMapping);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 12
Source File: SubmarineServer.java    From submarine with Apache License 2.0 5 votes vote down vote up
private static void setupRestApiContextHandler(WebAppContext webapp, SubmarineConfiguration conf) {
  final ServletHolder servletHolder =
      new ServletHolder(new org.glassfish.jersey.servlet.ServletContainer());

  servletHolder.setInitParameter("javax.ws.rs.Application", SubmarineServer.class.getName());
  servletHolder.setName("rest");
  servletHolder.setForcedPath("rest");
  webapp.setSessionHandler(new SessionHandler());
  webapp.addServlet(servletHolder, "/api/*");
}
 
Example 13
Source File: ServerCmdlet.java    From HongsCORE with MIT License 5 votes vote down vote up
private void addServlet(ServletContextHandler context, Class clso, WebServlet anno) {
    ServletHolder hd = new ServletHolder(clso );
    hd.setName          (anno./****/name(    ));
    hd.setAsyncSupported(anno.asyncSupported());

    for(WebInitParam nv : anno.initParams ()) {
        hd.setInitParameter(nv.name( ), nv.value());
    }

    for(String       ur : anno.urlPatterns()) {
        context.addServlet(hd, ur/**/);
    }
}
 
Example 14
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
                               Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing {} servlet at path {}; will replace mapping with {} servlet"
            , servletMappings[i].getServletName()
            , pathSpec
            , holder.getName());
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to {}", name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 15
Source File: JettyTransport.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
public void registerServlet(String path, Servlet servletContainer) {
  ServletHolder servletHolder = new ServletHolder(Source.EMBEDDED);
  servletHolder.setName("Data Transfer Project");
  servletHolder.setServlet(servletContainer);
  servletHolder.setInitOrder(1);

  ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  handler.setContextPath("/");

  handlers.add(handler);

  handler.getServletHandler().addServletWithMapping(servletHolder, path);
}
 
Example 16
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, with initialization parameters.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param params init parameters
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, Map<String, String> params) {
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletHolder sh = new ServletHolder(clazz);
  sh.setName(name);
  sh.setInitParameters(params);
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMappings[i].getServletName() +
            " servlet at path " + pathSpec + "; will replace mapping" +
            " with " + sh.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 17
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add an internal servlet in the server, specifying whether or not to
 * protect with Kerberos authentication.
 * Note: This method is to be used for adding servlets that facilitate
 * internal communication and not for user facing functionality. For
 * servlets added using this method, filters (except internal Kerberos
 * filters) are not enabled.
 *
 * @param name The name of the servlet (can be passed as null)
 * @param pathSpec The path spec for the servlet
 * @param clazz The servlet class
 * @param requireAuth Require Kerberos authenticate to access servlet
 */
public void addInternalServlet(String name, String pathSpec,
    Class<? extends HttpServlet> clazz, boolean requireAuth) {
  ServletHolder holder = new ServletHolder(clazz);
  if (name != null) {
    holder.setName(name);
  }
  // Jetty doesn't like the same path spec mapping to different servlets, so
  // if there's already a mapping for this pathSpec, remove it and assume that
  // the newest one is the one we want
  final ServletMapping[] servletMappings =
      webAppContext.getServletHandler().getServletMappings();
  for (int i = 0; i < servletMappings.length; i++) {
    if (servletMappings[i].containsPathSpec(pathSpec)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Found existing " + servletMappings[i].getServletName() +
            " servlet at path " + pathSpec + "; will replace mapping" +
            " with " + holder.getName() + " servlet");
      }
      ServletMapping[] newServletMappings =
          ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
      webAppContext.getServletHandler()
          .setServletMappings(newServletMappings);
      break;
    }
  }
  webAppContext.addServlet(holder, pathSpec);

  if (requireAuth && UserGroupInformation.isSecurityEnabled()) {
    LOG.info("Adding Kerberos (SPNEGO) filter to {}", name);
    ServletHandler handler = webAppContext.getServletHandler();
    FilterMapping fmap = new FilterMapping();
    fmap.setPathSpec(pathSpec);
    fmap.setFilterName(SPNEGO_FILTER);
    fmap.setDispatches(FilterMapping.ALL);
    handler.addFilterMapping(fmap);
  }
}
 
Example 18
Source File: RestOrderServer.java    From camelinaction2 with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create rider order service with dummy backend
    RestOrderService orderService = new RestOrderService();
    orderService.setOrderService(dummy);

    // create JAX-RS application with our rider order serivce
    RestOrderApplication app = new RestOrderApplication(orderService);

    // setup servlet holder with a CXF jax-rs servlet to handle the app
    Servlet servlet = new CXFNonSpringJaxrsServlet(app);
    ServletHolder holder = new ServletHolder(servlet);
    holder.setName("rider");
    holder.setForcedPath("/");
    ServletContextHandler context = new ServletContextHandler();
    context.addServlet(holder, "/*");

    // create and start the jetty server (non blocking)
    Server server = new Server(9000);
    server.setHandler(context);
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop jetty server
    server.stop();
    System.exit(0);
}
 
Example 19
Source File: NoSpringServletServer.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected void run() {
    // setup the system properties
    String busFactory = System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
    System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, "org.apache.cxf.bus.CXFBusFactory");
    try {
        httpServer = new Server(Integer.parseInt(PORT));
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        httpServer.setHandler(contexts);

        ServletContextHandler root = new ServletContextHandler(contexts, "/",
                                                               ServletContextHandler.SESSIONS);
        bus = BusFactory.getDefaultBus(true);
        CXFServlet cxf = new CXFServlet();
        cxf.setBus(bus);
        ServletHolder servlet = new ServletHolder(cxf);
        servlet.setName("soap");
        servlet.setForcedPath("soap");
        root.addServlet(servlet, "/soap/*");

        httpServer.start();
        setBus(bus);
        BusFactory.setDefaultBus(bus);
        GreeterImpl impl = new GreeterImpl();
        Endpoint.publish("/Greeter", impl);
        HelloImpl helloImpl = new HelloImpl();
        Endpoint.publish("/Hello", helloImpl);

        ((EndpointImpl)Endpoint.create(helloImpl)).publish("/");

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        // clean up the system properties
        if (busFactory != null) {
            System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, busFactory);
        } else {
            System.clearProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
        }
    }
}