org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory Java Examples
The following examples show how to use
org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.
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 |
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: RestServer.java From Cheddar with Apache License 2.0 | 6 votes |
public void start(final int servicePort, final String bindAddress, final int workerThreads) throws IOException { final URI baseUri = UriBuilder.fromUri("http://" + bindAddress).port(servicePort).build(); logger.info("Configuring REST server on: " + baseUri.toString()); httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false); enableAutoGenerationOfSwaggerSpecification(); configureWorkerThreadPool(httpServer.getListener("grizzly"), workerThreads); logger.info("Starting REST server; servicePort:[" + servicePort + "]"); httpServer.start(); }
Example #3
Source File: MCRJerseyTest.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public void start() { System.out.println("Starting GrizzlyTestContainer..."); try { this.server = GrizzlyHttpServerFactory.createHttpServer(uri, rc); // Initialize and register Jersey Servlet WebappContext context = new WebappContext("WebappContext", ""); ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class); registration.setInitParameter("javax.ws.rs.Application", rc.getClass().getName()); // Add an init parameter - this could be loaded from a parameter in the constructor registration.setInitParameter("myparam", "myvalue"); registration.addMapping("/*"); context.deploy(server); } catch (ProcessingException e) { throw new TestContainerException(e); } }
Example #4
Source File: RestServiceManager.java From lumongo with Apache License 2.0 | 6 votes |
public void start() throws IOException { URI baseUri = UriBuilder.fromUri("http://0.0.0.0/").port(restPort).build(); ResourceConfig config = new ResourceConfig(); config.register(new AssociatedResource(indexManager)); config.register(new QueryResource(indexManager)); config.register(new FetchResource(indexManager)); config.register(new FieldsResource(indexManager)); config.register(new IndexResource(indexManager)); config.register(new IndexesResource(indexManager)); config.register(new TermsResource(indexManager)); config.register(new MembersResource(indexManager)); config.register(new StatsResource(indexManager)); server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); server.getListener("grizzly").setMaxHttpHeaderSize(128 * 1024); }
Example #5
Source File: RESTServer.java From pravega with Apache License 2.0 | 6 votes |
/** * Start REST service. */ @Override protected void startUp() { long traceId = LoggerHelpers.traceEnterWithContext(log, this.objectId, "startUp"); try { log.info("Starting REST server listening on port: {}", this.restServerConfig.getPort()); if (restServerConfig.isTlsEnabled()) { SSLContextConfigurator contextConfigurator = new SSLContextConfigurator(); contextConfigurator.setKeyStoreFile(restServerConfig.getKeyFilePath()); contextConfigurator.setKeyStorePass(JKSHelper.loadPasswordFrom(restServerConfig.getKeyFilePasswordPath())); httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, true, new SSLEngineConfigurator(contextConfigurator, false, false, false)); } else { httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, true); } } finally { LoggerHelpers.traceLeave(log, this.objectId, "startUp", traceId); } }
Example #6
Source File: RestManager.java From cep with GNU Affero General Public License v3.0 | 6 votes |
/** * Starts the HTTP server exposing the resources defined in the RestRules class. * It takes a reference to an object that implements the RestListener interface, * which will be notified every time the REST API receives a request of some type. * * @param wsUri The base URL of the HTTP REST API * @param rl The RestListener object that will be notified when a user sends * an HTTP request to the API * @see RestRules * @see RestListener */ public static void startServer(String wsUri, RestListener rl) { // Create a resource config that scans for JAX-RS resources and providers ResourceConfig rc = new ResourceConfig() .register(RestRules.class) .register(JacksonFeature.class); // Set the listener for the petitions listener = rl; // Create a new instance of grizzly http server // exposing the Jersey application at BASE_URI server = GrizzlyHttpServerFactory.createHttpServer(URI.create(wsUri), rc); // start the server try { server.start(); } catch (IOException e) { log.error(e.getMessage()); } log.info("HTTP server started"); }
Example #7
Source File: CubeResourceTest.java From cubedb with GNU General Public License v3.0 | 6 votes |
@Before public void setup() throws Exception { // create ResourceConfig from Resource class ResourceConfig rc = new ResourceConfig(); MultiCube cube = new MultiCubeTest(null); rc.registerInstances(new CubeResource(cube)); rc.register(JsonIteratorConverter.class); // create the Grizzly server instance httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc); // start the server httpServer.start(); // configure client with the base URI path Client client = ClientBuilder.newClient(); client.register(JsonIteratorConverter.class); webTarget = client.target(baseUri); }
Example #8
Source File: CubeResourceGeneralTest.java From cubedb with GNU General Public License v3.0 | 6 votes |
@Before public void setup() throws Exception { //create ResourceConfig from Resource class ResourceConfig rc = new ResourceConfig(); cube = new MultiCubeImpl(null); rc.registerInstances(new CubeResource(cube)); rc.register(JsonIteratorConverter.class); //create the Grizzly server instance httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc); //start the server httpServer.start(); //configure client with the base URI path Client client = ClientBuilder.newClient(); client.register(JsonIteratorConverter.class); webTarget = client.target(baseUri); }
Example #9
Source File: DefaultWebhook.java From TelegramBots with MIT License | 6 votes |
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 #10
Source File: Server.java From Stargraph with MIT License | 6 votes |
void start() { try { Config config = stargraph.getMainConfig(); String urlStr = config.getString("networking.rest-url"); ResourceConfig rc = new ResourceConfig(); rc.register(LoggingFilter.class); rc.register(JacksonFeature.class); rc.register(MultiPartFeature.class); rc.register(CatchAllExceptionMapper.class); rc.register(SerializationExceptionMapper.class); rc.register(AdminResourceImpl.class); rc.register(new KBResourceImpl(stargraph)); rc.register(new QueryResourceImpl(stargraph)); httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(urlStr), rc, true); logger.info(marker, "Stargraph listening on {}", urlStr); } catch (Exception e) { throw new StarGraphException(e); } }
Example #11
Source File: WeatherServer.java From training with MIT License | 6 votes |
public static void start(int port) throws IOException { String baseUrl = "http://localhost:"+port+"/"; System.out.println("Starting Weather App local testing server: " + baseUrl); System.out.println("Not for production use"); final ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.register(RestWeatherCollectorEndpoint.class); resourceConfig.register(RestWeatherQueryEndpoint.class); resourceConfig.register(GenericExceptionMapper.class); resourceConfig.register(new MyApplicationBinder()); server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), resourceConfig, false); HttpServerProbe probe = new HttpServerProbe.Adapter() { @Override public void onRequestReceiveEvent(HttpServerFilter filter, @SuppressWarnings("rawtypes") 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", baseUrl)); server.start(); }
Example #12
Source File: EmbeddedHttpServer.java From tutorials with MIT License | 6 votes |
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 #13
Source File: ToolboxService.java From chipster with MIT License | 6 votes |
/** * * @param enableStatsAndAdminServer * @throws IOException * @throws URISyntaxException */ public void startServerOldChipster() throws IOException, URISyntaxException { this.toolResource = new ToolResource(this.toolbox); this.moduleResource = new ModuleResource(toolbox); final ResourceConfig rc = RestUtils.getResourceConfig().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); this.httpServer.start(); logger.info("toolbox service running at " + baseUri); }
Example #14
Source File: JerseyServerBootstrap.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
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 #15
Source File: AbstractAPI.java From clouditor with Apache License 2.0 | 5 votes |
/** Starts the API. */ public void start() { LOGGER.info("Starting {}...", this.getClass().getSimpleName()); this.httpServer = GrizzlyHttpServerFactory.createHttpServer( UriBuilder.fromUri( "http://" + NetworkListener.DEFAULT_NETWORK_HOST + "/" + this.contextPath) .port(this.port) .build(), this); LOGGER.info("{} successfully started.", this.getClass().getSimpleName()); // update the associated with the real port used, if port 0 was specified. if (this.port == 0) { component.setAPIPort(this.httpServer.getListener("grizzly").getPort()); } var config = new ResourceConfig(); config.register(OAuthResource.class); config.register(InjectionBridge.class); var context = new WebappContext("WebappContext", "/oauth2"); var registration = context.addServlet("OAuth2 Client", new ServletContainer(config)); registration.addMapping("/*"); context.deploy(httpServer); this.httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("html"), "/"); }
Example #16
Source File: WeatherServer.java From training with MIT License | 5 votes |
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 #17
Source File: TradeHistoryTest.java From ThriftBook with Apache License 2.0 | 5 votes |
@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); }
Example #18
Source File: TestDao.java From alm-rest-api with GNU General Public License v3.0 | 5 votes |
@BeforeClass public void setUp() throws Exception { final ResourceConfig rc = new ResourceConfig(AlmApiStub.class); server = GrizzlyHttpServerFactory.createHttpServer( URI.create(String.format("http://%s:%s/", host, port)), rc); }
Example #19
Source File: StarTreeIndexViewer.java From incubator-pinot with Apache License 2.0 | 5 votes |
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 #20
Source File: ControllerAdminApiApplication.java From incubator-pinot with Apache License 2.0 | 5 votes |
public void start(List<ListenerConfig> listenerConfigs, boolean advertiseHttps) { // ideally greater than reserved port but then port 80 is also valid Preconditions.checkNotNull(listenerConfigs); // The URI is irrelevant since the default listener will be manually rewritten. _httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create("http://0.0.0.0/"), this, false); // Listeners cannot be configured with the factory. Manual overrides is required as instructed by Javadoc. _httpServer.removeListener("grizzly"); listenerConfigs.forEach(listenerConfig->configureListener(listenerConfig, _httpServer)); try { _httpServer.start(); } catch (IOException e) { throw new RuntimeException("Failed to start Http Server", e); } setupSwagger(_httpServer, advertiseHttps); ClassLoader classLoader = ControllerAdminApiApplication.class.getClassLoader(); // This is ugly from typical patterns to setup static resources but all our APIs are // at path "/". So, configuring static handler for path "/" does not work well. // Configuring this as a default servlet is an option but that is still ugly if we evolve // So, we setup specific handlers for static resource directory. index.html is served directly // by a jersey handler _httpServer.getServerConfiguration() .addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/query/"), "/query/"); _httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/css/"), "/css/"); _httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/js/"), "/js/"); // without this explicit request to /index.html will not work _httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/"), "/index.html"); LOGGER.info("Admin API started on ports: {}", listenerConfigs.stream().map(ListenerConfig::getPort) .map(port -> port.toString()).collect(Collectors.joining(","))); }
Example #21
Source File: AdminApiApplication.java From incubator-pinot with Apache License 2.0 | 5 votes |
public boolean start(int httpPort) { if (httpPort <= 0) { LOGGER.warn("Invalid admin API port: {}. Not starting admin service", httpPort); return false; } baseUri = URI.create("http://0.0.0.0:" + Integer.toString(httpPort) + "/"); httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, this); setupSwagger(httpServer); started = true; return true; }
Example #22
Source File: AbstractApiControllerTest.java From cassandra-mesos-deprecated with Apache License 2.0 | 5 votes |
@Before public void cleanState() { super.cleanState(); try { try (ServerSocket sock = new ServerSocket(0)) { httpServerBaseUri = URI.create(String.format("http://%s:%d/", InetAddressUtils.formatInetAddress(InetAddress.getLoopbackAddress()), sock.getLocalPort())); } final ResourceConfig rc = new ResourceConfig() .registerInstances(Sets.newHashSet( new ApiController(factory), new ClusterCleanupController(cluster,factory), new ClusterRepairController(cluster,factory), new ClusterRollingRestartController(cluster,factory), new ClusterBackupController(cluster,factory), new ClusterRestoreController(cluster,factory), new ConfigController(cluster,factory), new LiveEndpointsController(cluster,factory), new NodeController(cluster,factory), new QaReportController(cluster, factory) )); httpServer = GrizzlyHttpServerFactory.createHttpServer(httpServerBaseUri, rc); httpServer.start(); } catch (final Exception e) { throw new RuntimeException(e); } }
Example #23
Source File: WebServer.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #24
Source File: RestDaemon.java From cloudml with GNU Lesser General Public License v3.0 | 5 votes |
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 #25
Source File: WatcherServer.java From at.info-knowledge-base with MIT License | 5 votes |
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: Server.java From at.info-knowledge-base with MIT License | 5 votes |
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 #27
Source File: JaxrsTest.java From immutables with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException { httpServer = GrizzlyHttpServerFactory.createHttpServer( SERVER_URI, createResourceConfig(), false); httpServer.start(); client = ClientBuilder.newBuilder() .register(GsonMessageBodyProvider.class) .register(PURE_GSON_TEXT_PLAIN) .build(); }
Example #28
Source File: TestRestConnector.java From alm-rest-api with GNU General Public License v3.0 | 5 votes |
@BeforeClass public void setUp() throws Exception { final ResourceConfig rc = new ResourceConfig(Resource.class); server = GrizzlyHttpServerFactory.createHttpServer( URI.create(String.format("http://%s:%s/api", Host, Port)), rc); }
Example #29
Source File: HelloHttpRunner.java From karate with MIT License | 5 votes |
@BeforeClass public static void beforeClass() throws Exception { ResourceConfig resourceConfig = new ResourceConfig(HelloResource.class); URI uri = URI.create("http://localhost:8080"); server = GrizzlyHttpServerFactory.createHttpServer(uri, resourceConfig, false); server.start(); logger.info("server started: {}", uri); }
Example #30
Source File: App.java From crnk-framework with Apache License 2.0 | 5 votes |
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"); }