Example #1
0
  protected HttpServer createHttpServer() throws IOException {
    HttpServer server = new HttpServer();

    SocketListener listener = new SocketListener();
    listener.setPort(SysConfig.getHttpPortAsInt());
    server.addListener(listener);

    return server;
  }
  private static void startJettytHttpServer() throws MultiException {
    // Set up Jetty HTTP server with our servlet; this accidental
    // complexity is annoying for a demo app, but much less so than the
    // steps in deploying this in to Tomcat or whatever
    HttpServer webServer = new HttpServer();
    SocketListener listener = new SocketListener();
    listener.setPort(8080);
    webServer.addListener(listener);

    ServletHandler sh = new ServletHandler();
    sh.addServlet("service1", "/service1", ServerImpl.class.getName());

    HttpContext context = new HttpContext(webServer, "/");
    context.addHandler(sh);

    webServer.start();
  }
Example #3
0
  protected void doConnect() throws Exception {
    httpServer = new Server();
    SocketListener socketListener =
        new SocketListener(new InetAddrPort(endpoint.getEndpointURI().getPort()));

    // apply Threading settings
    ThreadingProfile tp = connector.getReceiverThreadingProfile();
    socketListener.setMaxIdleTimeMs((int) tp.getThreadTTL());
    int threadsActive = tp.getMaxThreadsActive();
    int threadsMin = socketListener.getMinThreads();
    if (threadsMin >= threadsActive) {
      socketListener.setMinThreads(threadsActive - 1);
    }
    socketListener.setMaxThreads(threadsActive);
    // thread priorities are evil and gone from ThreadingProfile
    // (google for priority inversion)
    // socketListener.setThreadsPriority(tp.getThreadPriority());

    httpServer.addListener(socketListener);

    String path = endpoint.getEndpointURI().getPath();
    if (StringUtils.isEmpty(path)) {
      path = "/";
    }

    if (!path.endsWith("/")) {
      path += "/";
    }

    HttpContext context = httpServer.getContext("/");
    context.setRequestLog(null);

    ServletHandler handler = new ServletHandler();
    if ("rest".equals(endpoint.getEndpointURI().getScheme())) {
      handler.addServlet(
          "MuleRESTReceiverServlet", path + "*", MuleRESTReceiverServlet.class.getName());
    } else {
      handler.addServlet("JettyReceiverServlet", path + "*", JettyReceiverServlet.class.getName());
    }

    context.addHandler(handler);
    context.setAttribute("messageReceiver", this);
  }