Exemple #1
0
  /**
   * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
   *
   * @return Grizzly HTTP server.
   */
  public static HttpServer startServer() {
    // create a resource config that scans for JAX-RS resources and providers
    // in com.sixtree.sample package
    final ResourceConfig rc = new ResourceConfig().packages("com.sixtree.sample");

    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
  }
 @Before
 public void setUp() throws Exception {
   server =
       GrizzlyHttpServerFactory.createHttpServer(
           URI.create(RestServer.BASE_URI),
           new ResourceConfig().registerClasses(RestServer.class));
   Client c = ClientBuilder.newClient();
   target = c.target(RestServer.BASE_URI);
 }
 public CrateHttpService(PersistentStateStore crateState, Configuration conf) {
   ResourceConfig httpConf =
       new ResourceConfig()
           .register(new CrateRestResource(crateState, conf))
           .packages(PACKAGE_NAMESPACE);
   URI httpUri =
       UriBuilder.fromPath("/").scheme("http").host("0.0.0.0").port(conf.apiPort).build();
   server = GrizzlyHttpServerFactory.createHttpServer(httpUri, httpConf);
   server.getServerConfiguration().addHttpHandler(new StaticHttpHandler(getRoot()), "/static");
 }
  //    **
  //     * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
  //     * @return Grizzly HTTP server.
  //     *
  private static HttpServer startServer() {
    // create a resource config that scans for JAX-RS resources and providers
    // in com.example package
    final ResourceConfig rc = new ResourceConfig().packages("org.owasp.appsensor");

    //        rc.register(MoxyJsonFeature.class);

    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
  }
    @Override
    public void start() {
      if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "Starting GrizzlyTestContainer...");
      }

      try {
        this.server = GrizzlyHttpServerFactory.createHttpServer(uri, appHandler);
      } catch (ProcessingException e) {
        throw new TestContainerException(e);
      }
    }
Exemple #6
0
  public static HttpServer startServer() {
    // create a resource config that scans for JAX-RS resources and
    // providers
    // in aggiethings.aggregator package
    final ResourceConfig rc = new ResourceConfig().packages("aggiethings.config");
    addressManager = new AddressManager(addressFolderPath);
    aggregatorIdManager = new AggregatorIdManager();

    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
  }
  /**
   * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
   *
   * @return Grizzly HTTP server.
   * @throws URISyntaxException
   */
  public void startServer() throws IOException, URISyntaxException {

    this.toolResource = new ToolResource(this.toolbox);
    this.moduleResource = new ModuleResource(toolbox);
    final ResourceConfig rc =
        RestUtils.getDefaultResourceConfig().register(this.toolResource).register(moduleResource);
    // .register(new LoggingFilter())

    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    URI baseUri = URI.create(this.url);
    this.httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
    logger.info("toolbox service running at " + baseUri);
  }
Exemple #8
0
  public static void main(String[] args) {
    try {
      System.out.println("System Properties Jersey Example App");

      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());

      System.out.println(
          String.format(
              "Application started.%n" + "Try out %s%n" + "Hit enter to stop it...",
              BASE_URI + "/properties"));
      System.in.read();
      server.shutdownNow();
    } catch (IOException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Exemple #9
0
  @SuppressWarnings({"ResultOfMethodCallIgnored"})
  public static void main(String[] args) {
    try {
      System.out.println("JSONP Jersey Example App");

      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());

      System.out.println(
          String.format(
              "Application started.%nTry out %s%s%nHit enter to stop it...", BASE_URI, ROOT_PATH));
      System.in.read();
      server.stop();
    } catch (IOException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Exemple #10
0
  /**
   * Main application entry point.
   *
   * @param args application arguments.
   */
  public static void main(String[] args) {
    try {
      System.out.println("Clipboard Jersey Example App");

      final ResourceConfig config = createProgrammaticClipboardApp();
      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, config);

      System.out.println(
          String.format(
              "Application started.%n" + "Try out %s%s%n" + "Hit enter to stop it...",
              BASE_URI, ROOT_PATH));
      System.in.read();
      server.stop();
    } catch (IOException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Exemple #11
0
  @Test
  public void testMultiPartResource() throws Exception {
    final ResourceConfig resourceConfig =
        new ResourceConfig(MultiPartResource.class).addBinders(new MultiPartBinder());
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

    Client c = ClientFactory.newClient(new ClientConfig().binders(new MultiPartClientBinder()));
    final Response response =
        c.target(baseUri).path("/multipart-simple").request().buildGet().invoke();

    MultiPart result = response.readEntity(MultiPart.class);
    System.out.println("RESULT = " + result);

    checkEntity(
        "This is the only segment", (BodyPartEntity) result.getBodyParts().get(0).getEntity());

    server.stop();
  }
  @Override
  public void startServer() throws Exception {
    server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI));

    AtmosphereServlet atmoServlet = new AtmosphereServlet();

    WebappContext context = new WebappContext("Chatty", "/chatty");

    ServletRegistration atmosphereRegistration = context.addServlet("Atmosphere", atmoServlet);
    atmosphereRegistration.addMapping("/atmos/*");

    ServletContainer jerseyContainer = new ServletContainer(resourceConfig);
    ServletRegistration jerseyRegistration = context.addServlet("Jersey", jerseyContainer);
    jerseyRegistration.addMapping("/api/*");

    context.deploy(server);

    server.start();
  }
Exemple #13
0
  private static HttpServer startServer() {
    final SqlSession sqlSession = MybatisConnectionFactory.getSqlSessionFactory().openSession();
    final PriceMapper priceMapper = sqlSession.getMapper(PriceMapper.class);
    final ProductRepository productRepository = sqlSession.getMapper(ProductRepository.class);

    final ResourceConfig config =
        new ResourceConfig()
            .packages("org.kiwi.resource")
            .register(ResourceNotFoundExceptionHandler.class)
            .register(
                new AbstractBinder() {
                  @Override
                  protected void configure() {
                    bind(priceMapper).to(PriceMapper.class);
                    bind(productRepository).to(ProductRepository.class);
                  }
                });
    return GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), config);
  }
Exemple #14
0
  /**
   * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
   *
   * @return Grizzly HTTP server.
   */
  public static HttpServer startServer() {

    BASE_URI =
        protocol
            + (host == null ? "localhost" : host)
            + ":"
            + (port == null ? "8080" : port)
            + "/"
            + path
            + "/";

    // create a resource config that scans for JAX-RS resources and providers
    // in com.example.rest package
    final ResourceConfig rc = new ResourceConfig().packages(Main.class.getPackage().getName());

    //        rc.register(NotFoundException.class);
    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
  }
    private static HttpServer create(
        URI u,
        Servlet servlet,
        Map<String, String> initParams,
        Map<String, String> contextParams,
        List<String> listeners,
        List<String> urlMappings)
        throws IOException {
      if (u == null) {
        throw new IllegalArgumentException("The URI must not be null");
      }

      String path = u.getPath();

      WebappContext context = new WebappContext("GrizzlyContext", path);

      for (String listener : listeners) {
        context.addListener(listener);
      }

      ServletRegistration registration = context.addServlet(servlet.getClass().getName(), servlet);

      for (String mapping : urlMappings) {
        registration.addMapping(mapping);
      }

      if (contextParams != null) {
        for (Map.Entry<String, String> e : contextParams.entrySet()) {
          context.setInitParameter(e.getKey(), e.getValue());
        }
      }

      if (initParams != null) {
        registration.setInitParameters(initParams);
      }

      HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
      context.deploy(server);

      return server;
    }
Exemple #16
0
  // TODO: the test is unreliable, the server returns null occasionally
  @Ignore
  @Test
  public void testJson() throws Exception {

    final ResourceConfig resourceConfig =
        new ResourceConfig(JsonResource.class).addModules(new JsonJacksonModule());
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

    Client c = ClientFactory.newClient();

    // TODO: enable JSON on the client side once JERSEY-1083 gets resolved
    //        c.configuration().register(new JsonJacksonFeature());

    final Response response =
        c.target(baseUri).path("/json").request(MediaType.APPLICATION_JSON).buildGet().invoke();
    String result = response.readEntity(String.class);
    System.out.println("RESULT = " + result);

    assertTrue(result.contains("Jim"));

    server.stop();
  }
Exemple #17
0
  public static void main(String[] args) {
    try {
      System.out.println("Jersey Entity Data Filtering Example.");

      final HttpServer server =
          GrizzlyHttpServerFactory.createHttpServer(
              BASE_URI, new EntityFilteringApplication(), false);
      Runtime.getRuntime()
          .addShutdownHook(
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      server.shutdownNow();
                    }
                  }));
      server.start();

      System.out.println("Application started.\nTry out one of these URIs:");
      for (final String path :
          new String[] {
            "projects",
            "projects/detailed",
            "users",
            "users?detailed=true",
            "tasks",
            "tasks/detailed"
          }) {
        System.out.println(BASE_URI + path);
      }
      System.out.println("Stop the application using CTRL+C");

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName())
          .log(Level.SEVERE, "I/O error occurred during reading from an system input stream.", ex);
    }
  }
Exemple #18
0
  public static void main(String[] args) throws IOException {
    try {
      System.out.println("JSON with MOXy Jersey Example App");

      final HttpServer server =
          GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), createAppConfig());
      Runtime.getRuntime()
          .addShutdownHook(
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      server.shutdownNow();
                    }
                  }));
      server.start();

      System.out.println(String.format("Application started.%nStop the application using CTRL+C"));

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  @Override
  public void actionPerformed(ActionEvent ev) {
    Object geklicked = ev.getSource();
    if (button[0] == geklicked) {
      // Host-IPs auslesen
      try {
        Enumeration<?> ifaces = NetworkInterface.getNetworkInterfaces();
        System.out.println("verfuegbare IP-Adressen des Host-PCs:");
        while (ifaces.hasMoreElements()) {
          NetworkInterface nic = (NetworkInterface) ifaces.nextElement();
          Enumeration<?> addrs = nic.getInetAddresses();
          while (addrs.hasMoreElements()) {
            InetAddress ia = (InetAddress) addrs.nextElement();
            String ip = ia.getHostAddress();
            if ((!ip.contains(":")) && (!ip.equals("127.0.0.1"))) {
              System.out.println("  " + nic.getName() + ": " + ip);
              jIP.setText(ip);
            }
          }
        }
        if (jIP.getText().length() == 0) jIP.setText("127.0.0.1");
        System.out.println("  127.0.0.1");
        System.out.println("");
      } catch (Exception e) {
        System.out.println("FEHLER: " + e.getMessage());
      }
    }
    if (button[2] == geklicked) {
      // Log speichern
      speichernLog();
    }
    if (button[3] == geklicked) {
      // Log loeschen
      loeschenLog();
    }
    if (button[5] == geklicked) {
      // Server Start
      try {
        URI uri = UriBuilder.fromUri("http://" + jIP.getText() + "/").port(8000).build();
        System.out.println("Starte Server auf " + uri + "... ");

        // TODO
        String[] packages = {"ru.backend.server", "schach.backend.server"};
        final ResourceConfig rc = new ResourceConfig().packages(packages);

        server = GrizzlyHttpServerFactory.createHttpServer(uri, rc);
        System.out.println("OK: Server laueft.");
        System.out.println("Lade Startzustand ueber die Initialisierungsfunktion...");
        Initialisierung.ausfuehren();
        System.out.println("OK");
      } catch (Exception e) {
        System.out.println("FEHLER: " + e.getMessage());
      }
    }
    if (button[6] == geklicked) {
      button[7].doClick();
      button[5].doClick();
    }
    if (button[7] == geklicked) {
      // Server Stop
      System.out.println("Stoppe Server... ");
      if (server != null) {
        server.shutdownNow();
        server = null;
      }
      System.out.println("Server gestoppt.");
    }
  }