org.glassfish.grizzly.http.server.HttpServer Java Examples

The following examples show how to use org.glassfish.grizzly.http.server.HttpServer. 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: Main.java    From minie with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        System.out.println("MinIE Service");

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

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

        Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example #2
Source File: DefaultWebhook.java    From TelegramBots with MIT License 6 votes vote down vote up
public void startServer() throws TelegramApiRequestException {
    ResourceConfig rc = new ResourceConfig();
    rc.register(restApi);
    rc.register(JacksonFeature.class);

    final HttpServer grizzlyServer;
    if (keystoreServerFile != null && keystoreServerPwd != null) {
        SSLContextConfigurator sslContext = new SSLContextConfigurator();

        // set up security context
        sslContext.setKeyStoreFile(keystoreServerFile); // contains server keypair
        sslContext.setKeyStorePass(keystoreServerPwd);

        grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true,
                new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
    } else {
        grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
    }

    try {
        grizzlyServer.start();
    } catch (IOException e) {
        throw new TelegramApiRequestException("Error starting webhook server", e);
    }
}
 
Example #3
Source File: Main.java    From http-server-benchmarks with MIT License 6 votes vote down vote up
public static HttpServer startServer() {
    HttpServer server = new HttpServer();
    server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080));

    final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
    //transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
    server.getListener("grizzly").setTransport(transportBuilder.build());
    final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey");
    rc.register(JacksonFeature.class);
    final ServerConfiguration config = server.getServerConfiguration();
    config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/");

    try {
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return server;
}
 
Example #4
Source File: GrizzlyApplication.java    From micro-server with Apache License 2.0 6 votes vote down vote up
private void addAccessLog(HttpServer httpServer) {
	try {
		String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation();

		accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log";
		final AccessLogBuilder builder = new AccessLogBuilder(accessLogLocation);

		builder.rotatedDaily();
		builder.rotationPattern("yyyy-MM-dd");
		builder.instrument(httpServer.getServerConfiguration());
	} catch (Exception e) {
		logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage());
		if (e.getCause() != null)
			logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage());

	}
}
 
Example #5
Source File: ServletRegistrationComponentTest.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonSerialization_application() throws Exception {

	// This test guarantees that in an non-OSGi environment,
	// our REST application uses the properties we define.
	// And, in particular, the JSon serialization that we tailored.

	URI uri = UriBuilder.fromUri( "http://localhost/" ).port( 8090 ).build();
	RestApplication restApp = new RestApplication( this.manager );
	HttpServer httpServer = null;
	String received = null;

	try {
		httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp );
		Assert.assertTrue( httpServer.isStarted());
		URI targetUri = UriBuilder.fromUri( uri ).path( UrlConstants.APPLICATIONS ).build();
		received = Utils.readUrlContent( targetUri.toString());

	} finally {
		if( httpServer != null )
			httpServer.stop();
	}

	String expected = JSonBindingUtils.createObjectMapper().writeValueAsString( Arrays.asList( this.app ));
	Assert.assertEquals( expected, received );
}
 
Example #6
Source File: ControllerAdminApiApplication.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private void setupSwagger(HttpServer httpServer, boolean advertiseHttps) {
  BeanConfig beanConfig = new BeanConfig();
  beanConfig.setTitle("Pinot Controller API");
  beanConfig.setDescription("APIs for accessing Pinot Controller information");
  beanConfig.setContact("https://github.com/apache/incubator-pinot");
  beanConfig.setVersion("1.0");
  if (advertiseHttps) {
    beanConfig.setSchemes(new String[]{"https"});
  } else {
    beanConfig.setSchemes(new String[]{"http"});
  }
  beanConfig.setBasePath("/");
  beanConfig.setResourcePackage(RESOURCE_PACKAGE);
  beanConfig.setScan(true);

  ClassLoader loader = this.getClass().getClassLoader();
  CLStaticHttpHandler apiStaticHttpHandler = new CLStaticHttpHandler(loader, "/api/");
  // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
  httpServer.getServerConfiguration().addHttpHandler(apiStaticHttpHandler, "/api/");
  httpServer.getServerConfiguration().addHttpHandler(apiStaticHttpHandler, "/help/");

  URL swaggerDistLocation = loader.getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
  CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
  httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}
 
Example #7
Source File: AdminApiApplication.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private void setupSwagger(HttpServer httpServer) {
  BeanConfig beanConfig = new BeanConfig();
  beanConfig.setTitle("Pinot Server API");
  beanConfig.setDescription("APIs for accessing Pinot server information");
  beanConfig.setContact("https://github.com/apache/incubator-pinot");
  beanConfig.setVersion("1.0");
  beanConfig.setSchemes(new String[]{"http"});
  beanConfig.setBasePath(baseUri.getPath());
  beanConfig.setResourcePackage(RESOURCE_PACKAGE);
  beanConfig.setScan(true);

  CLStaticHttpHandler staticHttpHandler =
      new CLStaticHttpHandler(AdminApiApplication.class.getClassLoader(), "/api/");
  // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
  httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/api/");
  httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/help/");

  URL swaggerDistLocation =
      AdminApiApplication.class.getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
  CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
  httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}
 
Example #8
Source File: JerseyServerBootstrap.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void setupServer(Application application) {
  ResourceConfig rc = ResourceConfig.forApplication(application);

  Properties serverProperties = readProperties();
  int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
  URI serverUri = UriBuilder.fromPath(ROOT_RESOURCE_PATH).scheme("http").host("localhost").port(port).build();

  final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(serverUri, rc);
  try {
    grizzlyServer.start();
  } catch (IOException e) {
    e.printStackTrace();
  }

  server = grizzlyServer;

}
 
Example #9
Source File: EmbeddedHttpServer.java    From tutorials with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    try {
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new ViewApplicationConfig(), false);

        Runtime.getRuntime()
            .addShutdownHook(new Thread(() -> {
                server.shutdownNow();
            }));

        server.start();

        System.out.println(String.format("Application started.\nTry out %s\nStop the application using CTRL+C", BASE_URI + "fruit"));
    } catch (IOException ex) {
        Logger.getLogger(EmbeddedHttpServer.class.getName())
            .log(Level.SEVERE, null, ex);
    }

}
 
Example #10
Source File: GrizzlyHttpService.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
private void addHTTPSRedirectHandler(HttpServer httpServerRef, int httpsPort)
{
    httpServerRef.getServerConfiguration().addHttpHandler(
        new HttpHandler()
        {
            @Override
            public void service(Request request, Response response) throws Exception
            {
                response.setStatus(HttpStatus.NOT_FOUND_404);
                response.sendRedirect(
                    String.format("https://%s:%d", request.getServerName(), httpsPort) +
                        request.getHttpHandlerPath()
                );
            }
        }
    );
}
 
Example #11
Source File: Main.java    From RestExpress-Examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException
{
	final HttpServer server = startServer();
	System.out.println(String.format(
	    "Jersey app started with WADL available at "
	        + "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
	System.in.read();
	server.stop();
}
 
Example #12
Source File: SimpleBankServer.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException
{
    initResources();
    URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
    server.start();
}
 
Example #13
Source File: Ahc2Test.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Before
public void before(final MockTracer tracer) throws IOException {
  // clear traces
  tracer.reset();

  httpServer = HttpServer.createSimpleServer(".", port);
  httpServer.start();
  setupServer(httpServer);
}
 
Example #14
Source File: WeatherServer.java    From training with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try {
        System.out.println("Starting Weather App local testing server: " + BASE_URL);
        System.out.println("Not for production use");

        final ResourceConfig resourceConfig = new ResourceConfig();
        resourceConfig.register(RestWeatherCollectorEndpoint.class);
        resourceConfig.register(RestWeatherQueryEndpoint.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URL), resourceConfig, false);

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                server.shutdownNow();
            }
        }));

        HttpServerProbe probe = new HttpServerProbe.Adapter() {
            public void onRequestReceiveEvent(HttpServerFilter filter, Connection connection, Request request) {
                System.out.println(request.getRequestURI());
            }
        };

        server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
        System.out.println(format("Weather Server started.\n url=%s\n", BASE_URL));
        server.start();

        Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(WeatherServer.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example #15
Source File: Server.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
public static void startServer(final int port) throws Exception {
    final URI baseUri = URI.create("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + port + "/selenium");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, new ServerConfiguration());

    System.in.read();
    server.shutdown();
}
 
Example #16
Source File: VanillaExtract.java    From osm-lib with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) {

        OSM osm = new OSM(args[0]);

        if (args.length > 1 && args[1].startsWith("--load")) {
            osm.intersectionDetection = true;
            osm.tileIndexing = true;
            if (args[1].equalsIgnoreCase("--loadurl")) {
                osm.readFromUrl(args[2]);
            } else {
                osm.readFromFile(args[2]);
            }
            // TODO catch writing exceptions here and shut down properly, closing OSM database.
            LOG.info("Done populating OSM database.");
            osm.close();
            return;
        }

        Thread updateThread = Updater.spawnUpdateThread(osm);

        LOG.info("Starting VEX HTTP server on port {} of interface {}", PORT, BIND_ADDRESS);
        HttpServer httpServer = new HttpServer();
        httpServer.addListener(new NetworkListener("vanilla_extract", BIND_ADDRESS, PORT));
        // Bypass Jersey etc. and add a low-level Grizzly handler.
        // As in servlets, * is needed in base path to identify the "rest" of the path.
        httpServer.getServerConfiguration().addHttpHandler(new VexHttpHandler(osm), "/*");
        try {
            httpServer.start();
            LOG.info("VEX server running.");
            Thread.currentThread().join();
            updateThread.interrupt();
        } catch (BindException be) {
            LOG.error("Cannot bind to port {}. Is it already in use?", PORT);
        } catch (IOException ioe) {
            LOG.error("IO exception while starting server.");
        } catch (InterruptedException ie) {
            LOG.info("Interrupted, shutting down.");
        }
        httpServer.shutdown();
    }
 
Example #17
Source File: SrvTakeTest.java    From takes with MIT License 5 votes vote down vote up
@Test
public void executeATakesAsAServlet() throws Exception {
    final String name = "webapp";
    final HttpServer server = HttpServer.createSimpleServer("./", 18080);
    final WebappContext context = new WebappContext(name);
    final ServletRegistration servlet = context.addServlet(
        "takes",
        SrvTake.class
    );
    servlet.setInitParameter("take", TkApp.class.getName());
    servlet.addMapping("/test");
    context.deploy(server);
    server.start();
    new JdkRequest("http://localhost:18080/test")
        .fetch()
        .as(RestResponse.class)
        .assertStatus(HttpURLConnection.HTTP_OK)
        .assertBody(
            new StringContains(
                new FormattedText(
                    SrvTakeTest.MSG,
                    name
                ).asString()
            )
        );
    server.shutdownNow();
}
 
Example #18
Source File: RestServer.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public void shutdownAndAwait(final long timeoutMillis) {
    try {
        logger.info("Shutting down REST server");
        if (httpServer != null) {
            final GrizzlyFuture<HttpServer> future = httpServer.shutdown(timeoutMillis, TimeUnit.MILLISECONDS);
            future.get();
        }
        logger.info("Shutdown of REST server complete");
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example #19
Source File: WebServer.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {
	try {
		final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI,
				createApp(), false);
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			@Override
			public void run() {
				server.shutdownNow();
			}
		}));

		// Some modifications
		NetworkListener defaultListener = server.getListener("grizzly");
		defaultListener.getKeepAlive().setIdleTimeoutInSeconds(-1);
		defaultListener.getKeepAlive().setMaxRequestsCount(-1);
		defaultListener.getFileCache().setEnabled(false);
		defaultListener.registerAddOn(new SimplifyAddOn());
		defaultListener.registerAddOn(new HttpPipelineOptAddOn());

		final TCPNIOTransport transport = defaultListener.getTransport();
		transport.setWorkerThreadPoolConfig(null); // force to not
													// initialize worker
													// thread pool
		transport.setSelectorRunnersCount(Runtime.getRuntime().availableProcessors() * 2);
		transport.setMemoryManager(new PooledMemoryManager());

		server.start();

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

		Thread.currentThread().join();
	} catch (IOException | InterruptedException ex) {
		Logger.getLogger(WebServer.class.getName()).log(Level.SEVERE, null, ex);
	}
}
 
Example #20
Source File: ServletRegistrationComponentTest.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonSerialization_instance() throws Exception {

	// This test guarantees that in an non-OSGi environment,
	// our REST application uses the properties we define.
	// And, in particular, the JSon serialization that we tailored.

	URI uri = UriBuilder.fromUri( "http://localhost/" ).port( 8090 ).build();
	RestApplication restApp = new RestApplication( this.manager );
	HttpServer httpServer = null;
	String received = null;

	try {
		httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp );
		Assert.assertTrue( httpServer.isStarted());
		URI targetUri = UriBuilder.fromUri( uri )
				.path( UrlConstants.APP ).path( this.app.getName()).path( "instances" )
				.queryParam( "instance-path", "/tomcat-vm" ).build();

		received = Utils.readUrlContent( targetUri.toString());

	} finally {
		if( httpServer != null )
			httpServer.stop();
	}

	String expected = JSonBindingUtils.createObjectMapper().writeValueAsString( Arrays.asList( this.app.getTomcat()));
	Assert.assertEquals( expected, received );
}
 
Example #21
Source File: Main.java    From Jax-RS-Performance-Comparison with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    String host = "0.0.0.0";
    int port = 8080;
    if (args.length > 0) {
        host = args[0];
    }
    if (args.length > 1) {
        port = Integer.parseInt(args[1]);
    }

    final HttpServer server = startServer(host,port);
    System.in.read();
    server.shutdown();
}
 
Example #22
Source File: GatfConfigToolUtil.java    From gatf with Apache License 2.0 5 votes vote down vote up
protected static void handleRootContext(HttpServer server, final String mainDir, final GatfConfigToolMojoInt mojo) {
	server.getServerConfiguration().addHttpHandler(
	    new HttpHandler() {
	        public void service(Request request, Response response) throws Exception {
	        	new CacheLessStaticHttpHandler(mainDir).service(request, response);
	        }
	    }, "/");
	
	server.getServerConfiguration().addHttpHandler(new GatfProjectZipHandler(mojo), "/projectZip");
}
 
Example #23
Source File: StarTreeIndexViewer.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void startServer(final File segmentDirectory, final String json)
    throws Exception {
  int httpPort = 8090;
  URI baseUri = URI.create("http://0.0.0.0:" + Integer.toString(httpPort) + "/");
  HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, new StarTreeResource(json));

  LOGGER.info("Go to http://{}:{}/  to view the star tree", "localhost", httpPort);
}
 
Example #24
Source File: ControllerAdminApiApplication.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void configureListener(ListenerConfig listenerConfig, HttpServer httpServer) {
  final NetworkListener listener = new NetworkListener(listenerConfig.getName() + "-" + listenerConfig.getPort(),
      listenerConfig.getHost(), listenerConfig.getPort());

  listener.getTransport().getWorkerThreadPoolConfig()
      .setThreadFactory(new ThreadFactoryBuilder().setNameFormat("grizzly-http-server-%d")
          .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());

  listener.setSecure(listenerConfig.getTlsConfiguration() != null);
  if (listener.isSecure()) {
    listener.setSSLEngineConfig(buildSSLEngineConfigurator(listenerConfig.getTlsConfiguration()));
  }
  httpServer.addListener(listener);
}
 
Example #25
Source File: WatcherServer.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
public static void startServer(final int port) throws Exception {
    final URI baseUri = URI.create("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + port);
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, new WatcherConfiguration());

    System.in.read();
    server.shutdown();
}
 
Example #26
Source File: RestDaemon.java    From cloudml with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args){
    
    int port = 9002;
    if(args.length >= 1)
        port = Integer.parseInt(args[0]);
    
    if(Coordinator.SINGLE_INSTANCE == null){
        Coordinator coord = new Coordinator();
        coord.setModelRepo(new FacadeBridge());
        Coordinator.SINGLE_INSTANCE = coord;
        coord.start();
        
        //Only for test purpose
        coord.process("!extended { name : LoadDeployment, params : ['sample://sensapp'] }", commonStub);
    }
            
    
    
    URI uri = UriBuilder.fromUri("http://0.0.0.0/").port(port).build();
    ResourceConfig resourceConfig = new ResourceConfig(QueryResource.class);
    resourceConfig.register(UniversalResource.class);
    resourceConfig.register(CommitResource.class);
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, resourceConfig);
    
    try {
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    while(true){
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            Logger.getLogger(RestDaemon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
Example #27
Source File: App.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
	final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new JerseyApplication());
	server.start();

	Thread.sleep(50);
	System.out.println("\n\nopen http://localhost:8080 in your browser\n\n");
}
 
Example #28
Source File: HttpServerTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Before
public void before(final MockTracer tracer) throws IOException {
  // clear traces
  tracer.reset();

  httpServer = new HttpServer();
  NetworkListener listener = new NetworkListener("grizzly", DEFAULT_NETWORK_HOST, PORT);
  httpServer.addListener(listener);
  httpServer.start();
}
 
Example #29
Source File: GrizzlyHttpServerITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException {
  final HttpServer server = new HttpServer();
  final NetworkListener listener = new NetworkListener("grizzly", DEFAULT_NETWORK_HOST, 18906);
  server.addListener(listener);
  server.start();

  server.getServerConfiguration().addHttpHandler(new HttpHandler() {
    @Override
    public void service(final Request request, final Response response) {
      TestUtil.checkActiveSpan();
      response.setStatus(200);
    }
  });

  int responseCode = -1;
  try {
    final URL url = new URL("http://localhost:18906/");
    final HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    responseCode = connection.getResponseCode();
    connection.disconnect();
  }
  finally {
    server.shutdownNow();

    if (200 != responseCode)
      throw new AssertionError("ERROR: response: " + responseCode);

    TestUtil.checkSpan(true, new ComponentSpanCount("java-grizzly-http-server", 1), new ComponentSpanCount("http-url-connection", 1));
  }
}
 
Example #30
Source File: GrizzlyHttpService.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
private void enableCompression(HttpServer httpServerRef)
{
    CompressionConfig compressionConfig = httpServerRef.getListener("grizzly").getCompressionConfig();
    compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON);
    compressionConfig.setCompressibleMimeTypes("text/plain", "text/html", "application/json");
    compressionConfig.setCompressionMinSize(COMPRESSION_MIN_SIZE);
}