Exemplo n.º 1
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);
        }
      }
    }
  }
Exemplo n.º 2
0
  public void startServer(String host, int port) throws Exception {

    info("starting Jetty server on " + host + ":" + port);

    /*
     * do all preparatory chores before starting the server
     */
    Thinkcap.get().setBaseUrl("http://" + host + ":" + port);

    if (server != null) throw new ThinkcapException("thinkcap server is already active");

    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setHost(host);
    connector.setPort(port);
    server.setConnectors(new Connector[] {connector});

    WebAppContext wah = new WebAppContext();
    wah.setContextPath("/");
    wah.setWar(Thinkcap.get().getWebSpace().toString());

    ClassLoader cl = this.getClass().getClassLoader();
    WebAppClassLoader wacl = new WebAppClassLoader(cl, wah);
    wah.setClassLoader(wacl);

    server.addHandler(wah);
    server.setStopAtShutdown(true);

    server.start();
    server.join();
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
0
  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);
    }
  }
Exemplo n.º 5
0
  WebAppContext webApp()
      throws IOException, SAXException, ClassNotFoundException, UnavailableException {
    WebAppContext wac = new WebAppContext();
    configuration.setWebAppContext(wac);
    configuration.initialize(getWarFile());

    wac.setConfigurationClasses(
        new String[] {
          "org.mortbay.jetty.webapp.WebInfConfiguration",
          "org.mortbay.jetty.webapp.WebXmlConfiguration",
          "org.mortbay.jetty.webapp.JettyWebXmlConfiguration",
        });
    wac.setContextPath(new SystemEnvironment().getWebappContextPath());
    wac.setWar(getWarFile());
    wac.setParentLoaderPriority(new SystemEnvironment().getParentLoaderPriority());
    setCookieExpireIn2Weeks(wac);
    addExtraJarsToClasspath(wac);
    addJRubyContextInitParams(wac);
    addStopServlet(wac);

    return wac;
  }
  @Test
  public void submitJob() throws Exception {
    org.h2.tools.Server h2 = org.h2.tools.Server.createTcpServer();
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8081);
    connector.setHost("127.0.0.1");
    server.addConnector(connector);

    WebAppContext wac = new WebAppContext();
    wac.setContextPath("/springbatchadmin");
    wac.setWar("./src/main/webapp");
    server.setHandler(wac);
    server.setStopAtShutdown(true);

    try {
      h2.start();
      server.start();
      assertTrue(restTemplate.getForObject(BASE_URL + "jobs.json", String.class).contains(JOB));
    } finally {
      server.stop();
      h2.stop();
    }
  }
Exemplo n.º 7
0
  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);
    }
  }
Exemplo n.º 8
0
  public static void main(String[] args) throws Exception {
    int port = 8080;
    try {
      if (System.getProperty("port") != null && !System.getProperty("port").equals("")) {
        port = Integer.decode(System.getProperty("port"));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    boolean rhttpEnabled = (args.length == 0);
    boolean rsoapEnabled =
        args.length == 0
            && System.getProperty("soapenabled") != null
            && System.getProperty("soapenabled").equals("true");

    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(port);
    connector.setHost(getHostIp());
    server.addConnector(connector);

    Connector connectorLocal = new SelectChannelConnector();
    connectorLocal.setPort(port);
    connectorLocal.setHost("127.0.0.1");
    server.addConnector(connectorLocal);

    if (rhttpEnabled) {
      cacheJar(
          new URL("http://biocep-distrib.r-forge.r-project.org/appletlibs/rvirtual.war"),
          ServerManager.INSTALL_DIR,
          LOG_PRGRESS_TO_SYSTEM_OUT,
          false);
      if (rsoapEnabled) {
        cacheJar(
            new URL("http://biocep-distrib.r-forge.r-project.org/appletlibs/rws.war"),
            ServerManager.INSTALL_DIR,
            LOG_PRGRESS_TO_SYSTEM_OUT,
            false);
        args =
            new String[] {
              ServerManager.INSTALL_DIR + "rvirtual.war", ServerManager.INSTALL_DIR + "rws.war"
            };
      } else {
        args = new String[] {ServerManager.INSTALL_DIR + "rvirtual.war"};
      }
    }

    for (int i = 0; i < args.length; ++i) {
      File warfile = new File(args[i]);
      if (!warfile.exists()) {
        System.out.println("couldn't find the war file :" + args[i]);
        System.exit(0);
      }

      String contextPath = "/" + warfile.getName();
      if (contextPath.endsWith(".war"))
        contextPath = contextPath.substring(0, contextPath.length() - ".war".length());

      WebAppContext wac = new WebAppContext();
      wac.setContextPath(contextPath);
      wac.setWar(warfile.getAbsolutePath());
      server.addHandler(wac);
    }

    server.setStopAtShutdown(true);
    server.start();

    while (!server.isStarted()) {
      try {
        Thread.sleep(20);
      } catch (Exception ex) {
      }
    }

    System.out.println("--> Http Server Started sucessfully on port " + port);

    if (rhttpEnabled) {
      System.out.println("R-HTTP URL: http://" + getHostIp() + ":" + port + "/rvirtual/cmd");
      System.out.println(
          "--> From the Virtual R Workbench, in Http mode, connect via the following URL:"
              + "http://"
              + getHostIp()
              + ":"
              + port
              + "/rvirtual/cmd");
    }

    if (rsoapEnabled) {
      System.out.println(
          "R-SOAP WSDL:" + "http://" + getHostIp() + ":" + port + "/rws/rGlobalEnvFunction?wsdl");
    }
  }
Exemplo n.º 9
0
  private void deployWebApp() {
    try {
      Server server = new Server();
      SelectChannelConnector connector = new SelectChannelConnector();
      connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
      connector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
      connector.setHost(getHost());
      connector.setPort(getPort());
      if (isHttpsEnabled()) {
        connector.setConfidentialPort(getHttpsPort());
      }
      server.addConnector(connector);

      if (isHttpsEnabled()) {
        SslSocketConnector sslConnector = new SslSocketConnector();
        sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
        sslConnector.setHost(getHost());
        sslConnector.setPort(getHttpsPort());
        sslConnector.setKeystore(
            System.getProperty(
                "subsonic.ssl.keystore",
                getClass().getResource("/subsonic.keystore").toExternalForm()));
        sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
        server.addConnector(sslConnector);
      }

      WebAppContext context = new WebAppContext();
      context.setTempDirectory(getJettyDirectory());
      context.setContextPath(getContextPath());
      context.setWar(getWar());
      context.setOverrideDescriptor("/web-jetty.xml");

      if (isHttpsEnabled()) {

        // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
        context
            .getSecurityHandler()
            .setConstraintMappings(
                new ConstraintMapping[] {
                  createConstraintMapping("/stream", Constraint.DC_NONE),
                  createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
                  createConstraintMapping("/ws/*", Constraint.DC_NONE),
                  createConstraintMapping("/sonos/*", Constraint.DC_NONE),
                  createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
                });
      }

      server.addHandler(context);
      server.start();

      System.err.println("Subsonic running on: " + getUrl());
      if (isHttpsEnabled()) {
        System.err.println("                and: " + getHttpsUrl());
      }

    } catch (Throwable x) {
      x.printStackTrace();
      exception = x;
    }
  }
Exemplo n.º 10
0
  private static void initWebappContext(Server server, Configs configs)
      throws IOException, URISyntaxException {
    web = new WebAppContext();

    if (configs.getParentLoaderPriority()) {
      System.err.println("ParentLoaderPriority enabled");
      web.setParentLoaderPriority(true);
    }

    web.setContextPath(configs.getContext());
    System.err.println("Context path:" + configs.getContext());
    web.setWar(configs.getWebAppDir());

    /** open a way to set the configuration classes */
    List<String> configurationClasses = configs.getConfigurationClassesList();
    if (configurationClasses.size() != 0) {
      web.setConfigurationClasses(configurationClasses.toArray(new String[0]));

      for (String conf : configurationClasses) System.err.println("Enable config class:" + conf);
    }

    // Fix issue 7, File locking on windows/Disable Jetty's locking of
    // static files
    // http://code.google.com/p/run-jetty-run/issues/detail?id=7
    // by disabling the use of the file mapped buffers. The default Jetty
    // behavior is
    // intended to provide a performance boost, but run-jetty-run is focused
    // on
    // development (especially debugging) of web apps, not high-performance
    // production
    // serving of static content. Therefore, I'm not worried about the
    // performance
    // degradation of this change. My only concern is that there might be a
    // need to
    // test this feature that I'm disabling.
    web.setInitParams(
        Collections.singletonMap("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false"));

    if (configs.getWebAppClassPath() != null) {
      ProjectClassLoader loader =
          new ProjectClassLoader(web, configs.getWebAppClassPath(), configs.getExcludedclasspath());
      web.setClassLoader(loader);
    }

    List<Resource> resources = new ArrayList<Resource>();

    URL urlWebapp = new File(configs.getWebAppDir()).toURI().toURL();
    Resource webapp = new FileResource(urlWebapp);
    resources.add(webapp);

    Map<String, String> map = configs.getResourceMap();
    for (String key : map.keySet()) {
      /*
      * 			URL url = new File(map.get(key)).toURI().toURL();
      		Resource resource;
      		try {
      			resource = new FileResource(url);
      			final ResourceHandler handler = new ResourceHandler();
      			handler.setBaseResource(resource);
      			handler.setServer(server);
      			handler.setContextPath(key);
      			web.addHandler(handler);
      		} catch (URISyntaxException e) {
      			e.printStackTrace();
      		}

      */
      resources.add(new VirtualResource(webapp, "/" + key, map.get(key)));
      //			final WebAppContext js = new WebAppContext();
      //			js.setContextPath(key);
      //			js.setResourceBase(map.get(key)); // or whatever the correct path is in your case
      //			js.setParentLoaderPriority(true);
      //			server.addHandler(js);
    }

    ResourceCollection webAppDirResources = new ResourceCollection();
    webAppDirResources.setResources(resources.toArray(new Resource[0]));
    web.setBaseResource(webAppDirResources);

    server.addHandler(web);
  }