public void start(SoapMonitor soapMonitor, int localPort) {
    Settings settings = soapMonitor.getProject().getSettings();
    server.setThreadPool(new SoapUIJettyThreadPool());
    Context context = new Context(server, ROOT, 0);

    if (sslEndpoint != null) {
      if (sslEndpoint.startsWith(HTTPS)) {
        sslConnector = new SslSocketConnector();
        sslConnector.setKeystore(
            settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_KEYSTORE, "JKS"));
        sslConnector.setPassword(
            settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_PASSWORD, ""));
        sslConnector.setKeyPassword(
            settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_KEYPASSWORD, ""));
        sslConnector.setTruststore(
            settings.getString(SoapMonitorAction.SecurityTabForm.SSLTUNNEL_TRUSTSTORE, "JKS"));
        sslConnector.setTrustPassword(
            settings.getString(
                SoapMonitorAction.SecurityTabForm.SSLTUNNEL_TRUSTSTORE_PASSWORD, ""));
        sslConnector.setNeedClientAuth(false);
        sslConnector.setMaxIdleTime(30000);
        sslConnector.setPort(localPort);

        server.addConnector(sslConnector);
        context.addServlet(new ServletHolder(new TunnelServlet(soapMonitor, sslEndpoint)), ROOT);
      } else {
        if (sslEndpoint.startsWith(HTTP)) {
          connector.setPort(localPort);
          server.addConnector(connector);
          context.addServlet(new ServletHolder(new TunnelServlet(soapMonitor, sslEndpoint)), ROOT);
        } else {
          UISupport.showErrorMessage("Unsupported/unknown protocol tunnel will not start");
          return;
        }
      }
      proxyOrTunnel = false;
    } else {
      proxyOrTunnel = true;
      connector.setPort(localPort);
      server.addConnector(connector);
      context.addServlet(new ServletHolder(new ProxyServlet(soapMonitor)), ROOT);
    }
    try {
      server.start();
    } catch (Exception e) {
      UISupport.showErrorMessage("Error starting monitor: " + e.getMessage());
    }
  }
Exemple #2
0
  public static void start() throws Exception {
    try {

      SocketConnector connector = new SocketConnector();
      connector.setPort(8080);

      server.setConnectors(new Connector[] {connector});
      WebAppContext context = new WebAppContext();
      context.setServer(server);
      context.setContextPath("/DBService");
      // context.setContextPath("/");
      context.setWar("src/main/webapp");
      server.addHandler(context);
      SQLExecutor.setConfigfile("local_logging.properties");

      server.start();

    } catch (Exception e) {
      if (server != null) {
        try {
          server.stop();
        } catch (Exception e1) {
          throw new RuntimeException(e1);
        }
      }
    }
  }
  protected void configureConnectors() {
    if (server != null) {
      if (_useNIO) {
        SelectChannelConnector nioConnector = new SelectChannelConnector();
        nioConnector.setUseDirectBuffers(false);
        nioConnector.setPort(_port);
        server.addConnector(nioConnector);
      } else {
        SocketConnector bioConnector = new SocketConnector();
        bioConnector.setPort(_port);
        bioConnector.setMaxIdleTime(3000);
        server.addConnector(bioConnector);
      }

      if (_useSSL) {
        SslSocketConnector sslConnector = new SslSocketConnector();
        sslConnector.setPort(_sslPort);
        // sslConnector.setKeystore("/sdcard/jetty/etc/keystore");
        sslConnector.setKeystore(_keystoreFile);
        sslConnector.setKeystoreType("bks");
        // sslConnector.setTruststore("/sdcard/jetty/etc/keystore");
        sslConnector.setTruststore(_truststoreFile);
        // sslConnector.setPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
        sslConnector.setPassword(_keystorePassword);
        // sslConnector.setKeyPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
        sslConnector.setKeyPassword(_keymgrPassword);
        // sslConnector.setTrustPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
        sslConnector.setTrustPassword(_truststorePassword);
        sslConnector.setTruststoreType("bks");
        server.addConnector(sslConnector);
      }
    }
  }
  public EmbeddedWebServer(String host, int port) {
    server = new Server();
    handler = new ContextHandlerCollection();
    root = new Context(handler, "/", new SessionHandler(), null, null, null);

    if (EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE))
        || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS))
        || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE))
        || EMPTY.equals(
            Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS))) {
      sock = new SocketConnector();
      usingSsl = false;
    } else {
      sock = new SslSocketConnector();
      ((SslSocketConnector) sock)
          .setKeystore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE));
      ((SslSocketConnector) sock)
          .setKeyPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS));
      ((SslSocketConnector) sock)
          .setTruststore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE));
      ((SslSocketConnector) sock)
          .setTrustPassword(
              Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS));
      usingSsl = true;
    }
    sock.setHost(host);
    sock.setPort(port);
  }
Exemple #5
0
  public static void main(String[] args) throws Exception {
    ApplicationProperties properties = new ApplicationProperties();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);

    int port = Integer.getInteger("jetty.port", properties.getHttpPort());
    connector.setPort(port);

    SslSocketConnector sslConnector = new SslSocketConnector();
    sslConnector.setMaxIdleTime(1000 * 60 * 60);
    sslConnector.setSoLingerTime(-1);
    sslConnector.setKeyPassword("password");
    sslConnector.setPassword("password");
    sslConnector.setKeystore("src/main/webapp/WEB-INF/keystore");

    port = Integer.getInteger("jetty.sslport", properties.getHttpsPort());
    sslConnector.setPort(port);

    server.setConnectors(new Connector[] {connector, sslConnector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.addHandler(bb);

    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      while (System.in.available() == 0) {
        Thread.sleep(5000);
      }
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
  protected void startHttpServer() throws Exception {
    Server server = new Server();
    SocketConnector sc = new SocketConnector();
    sc.setHost("127.0.0.1");
    sc.setPort(7777);
    server.addConnector(sc);
    ResourceHandler rhandler = new ResourceHandler();
    rhandler.setResourceBase(getSrcHtdocs().getAbsolutePath());

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {rhandler, new DefaultHandler()});
    server.setHandler(handlers);

    this.httpServer = server;
    server.start();
  }
Exemple #7
0
 public static void main(String[] args) throws Exception {
   Server server = new Server();
   SocketConnector connector = new SocketConnector();
   connector.setHost(ApplicationProperties.getProperty("host"));
   connector.setPort(Integer.valueOf(ApplicationProperties.getProperty("port")));
   server.setConnectors(new Connector[] {connector});
   WebAppContext webAppContext =
       new WebAppContext(
           ApplicationProperties.getProperty("webappPath"),
           ApplicationProperties.getProperty("contextPath"));
   webAppContext.setClassLoader(Thread.currentThread().getContextClassLoader());
   server.setHandler(webAppContext);
   server.setStopAtShutdown(true);
   System.out.println("Starting server");
   server.start();
   server.join();
 }
  public static void main(String[] args) throws Exception {
    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(PORT);
    server.setConnectors(new Connector[] {connector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.addHandler(bb);

    try {
      System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
      server.start();
      System.out.println(String.format("Started, see you at port %d", PORT));
      System.in.read();
      System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
      // while (System.in.available() == 0) {
      //   Thread.sleep(5000);
      // }
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
  public static void main(String[] args) throws Exception {
    final int port = Integer.parseInt(System.getProperty("jetty.port", "10000"));

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(port);
    server.setConnectors(new Connector[] {connector});

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.addHandler(bb);

    try {
      System.out.println(
          ">>> STARTING EMBEDDED JETTY SERVER ON PORT: " + port + ", PRESS ANY KEY TO STOP");
      server.start();
      System.in.read();
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
  public static void main(String[] args) throws Exception {
    SocketConnector socketConnector = new SocketConnector();
    socketConnector.setPort(6080);

    SslSocketConnector sslSocketConnector = new SslSocketConnector();
    sslSocketConnector.setPort(6443);
    //        sslSocketConnector.setNeedClientAuth(true); //why not use mutual authentication when
    // we can

    String serverKeystore =
        MockHttpListenerWithAuthentication.class
            .getClassLoader()
            .getResource("cert/serverkeystore.jks")
            .getPath();
    sslSocketConnector.setKeystore(serverKeystore);
    sslSocketConnector.setKeyPassword("serverpass");
    String serverTruststore =
        MockHttpListenerWithAuthentication.class
            .getClassLoader()
            .getResource("cert/servertruststore.jks")
            .getPath();
    sslSocketConnector.setTruststore(serverTruststore);
    sslSocketConnector.setTrustPassword("serverpass");

    server.addConnector(socketConnector);
    server.addConnector(sslSocketConnector);

    SecurityHandler securityHandler = createBasicAuthenticationSecurityHandler();

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(securityHandler);
    handlerList.addHandler(
        new AbstractHandler() {
          @Override
          public void handle(
              String s,
              HttpServletRequest httpServletRequest,
              HttpServletResponse httpServletResponse,
              int i)
              throws IOException, ServletException {
            System.out.println("uri: " + httpServletRequest.getRequestURI());
            System.out.println("queryString: " + httpServletRequest.getQueryString());
            System.out.println("method: " + httpServletRequest.getMethod());

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(httpServletRequest.getInputStream(), baos);

            System.out.println("body: " + baos.toString());

            PrintWriter writer = httpServletResponse.getWriter();
            writer.append("testsvar");
            Random r = new Random();
            for (int j = 0; j < 10; j++) {
              int value = r.nextInt(Integer.MAX_VALUE);
              writer.append(value + "");
            }
            System.out.println();
            writer.close();
            httpServletResponse.setStatus(HttpServletResponse.SC_OK);
          }
        });

    server.addHandler(handlerList);
    server.start();
  }
 protected Connector createConnector() {
   SocketConnector socketConnector = new SocketConnector();
   socketConnector.setPort(PORT);
   socketConnector.setAcceptors(1);
   return socketConnector;
 }