/** * Create new {@link HttpServer} instance. * * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used as * context path, the rest will be ignored. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri) { return createHttpServer(uri, (GrizzlyHttpContainer) null, false, null, true); }
/** * Create new {@link HttpServer} instance. * * @param uri URI on which the Jersey web application will be deployed. Only first path segment will be * used as context path, the rest will be ignored. * @param configuration web application configuration. * @param start if set to false, server will not get started, which allows to configure the underlying * transport layer, see above for details. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration, final boolean start) { return createHttpServer( uri, new GrizzlyHttpContainer(configuration), false, null, start); }
/** * Create a new Grizzly HTTP container. * * @param application JAX-RS / Jersey application to be deployed on Grizzly HTTP container. * @param parentContext DI provider specific context with application's registered bindings. */ /* package */ GrizzlyHttpContainer(final Application application, final Object parentContext) { this.appHandler = new ApplicationHandler(application, new GrizzlyBinder(), parentContext); cacheConfigSetStatusOverSendError(); cacheConfigEnableLeadingContextPathSlashes(); }
/** * The method reads and caches value of configuration property * {@link org.glassfish.jersey.server.ServerProperties#REDUCE_CONTEXT_PATH_SLASHES_ENABLED} for future purposes. */ private void cacheConfigEnableLeadingContextPathSlashes() { this.configReduceContextPathSlashesEnabled = ServerProperties.getValue(getConfiguration().getProperties(), ServerProperties.REDUCE_CONTEXT_PATH_SLASHES_ENABLED, false, Boolean.class); } }
@Override public <T> T createContainer(Class<T> type, Application application) throws ProcessingException { if (HttpHandler.class == type || GrizzlyHttpContainer.class == type) { return type.cast(new GrizzlyHttpContainer(application)); } return null; } }
@Override public void reload() { reload(appHandler.getConfiguration()); }
private URI getBaseUri(final Request request) { try { return new URI(request.getScheme(), null, request.getServerName(), request.getServerPort(), getBasePath(request), null, null); } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
@Override protected void configure() { bindFactory(GrizzlyRequestReferencingFactory.class).to(Request.class) .proxy(false).in(RequestScoped.class); bindFactory(ReferencingFactory.<Request>referenceFactory()).to(new GenericType<Ref<Request>>() {}) .in(RequestScoped.class); bindFactory(GrizzlyResponseReferencingFactory.class).to(Response.class) .proxy(true).proxyForSameScope(false).in(RequestScoped.class); bindFactory(ReferencingFactory.<Response>referenceFactory()).to(new GenericType<Ref<Response>>() {}) .in(RequestScoped.class); } }
/** * Create new {@link HttpServer} instance. * * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path * segment will be used as context path, the rest will be ignored. * @param config web application configuration. * @param parentContext DI provider specific context with application's registered bindings. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. * @see GrizzlyHttpContainer * @since 2.12 */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig config, final Object parentContext) { return createHttpServer(uri, new GrizzlyHttpContainer(config, parentContext), false, null, true); }
/** * Create new {@link HttpServer} instance. * * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path segment will be used * as context path, the rest will be ignored. * @param start if set to false, server will not get started, which allows to configure the underlying transport * layer, see above for details. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri, final boolean start) { return createHttpServer(uri, (GrizzlyHttpContainer) null, false, null, start); }
/** * Create a new Grizzly HTTP container. * * @param application JAX-RS / Jersey application to be deployed on Grizzly HTTP container. */ /* package */ GrizzlyHttpContainer(final Application application) { this.appHandler = new ApplicationHandler(application, new GrizzlyBinder()); cacheConfigSetStatusOverSendError(); cacheConfigEnableLeadingContextPathSlashes(); }
/** * The method reads and caches value of configuration property * {@link org.glassfish.jersey.server.ServerProperties#RESPONSE_SET_STATUS_OVER_SEND_ERROR} for future purposes. */ private void cacheConfigSetStatusOverSendError() { this.configSetStatusOverSendError = ServerProperties.getValue(getConfiguration().getProperties(), ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, false, Boolean.class); }
/** * Create new {@link HttpServer} instance. * * @param uri URI on which the Jersey web application will be deployed. Only first path segment will be * used as context path, the rest will be ignored. * @param configuration web application configuration. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration) { return createHttpServer( uri, new GrizzlyHttpContainer(configuration), false, null, true ); }
public void start(int httpPort) { Preconditions.checkArgument(httpPort > 0); _baseUri = URI.create("http://0.0.0.0:" + httpPort + "/"); _httpServer = GrizzlyHttpServerFactory.createHttpServer(_baseUri, this); setupSwagger(); }
@Override public void reload(final ResourceConfig configuration) { appHandler.onShutdown(this); appHandler = new ApplicationHandler(configuration, new GrizzlyBinder()); appHandler.onReload(this); appHandler.onStartup(this); cacheConfigSetStatusOverSendError(); cacheConfigEnableLeadingContextPathSlashes(); }
/** * Create new {@link HttpServer} instance. * * @param uri URI on which the Jersey web application will be deployed. Only first path segment * will be used as context path, the rest will be ignored. * @param configuration web application configuration. * @param secure used for call {@link NetworkListener#setSecure(boolean)}. * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration, final boolean secure, final SSLEngineConfigurator sslEngineConfigurator) { return createHttpServer( uri, new GrizzlyHttpContainer(configuration), secure, sslEngineConfigurator, true); }
private GrizzlyTestContainer(final URI baseUri, final DeploymentContext context) { this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating GrizzlyTestContainer configured at the base URI " + TestHelper.zeroPortToAvailablePort(baseUri)); } this.server = GrizzlyHttpServerFactory.createHttpServer(this.baseUri, context.getResourceConfig(), false); }
/** * Create new {@link HttpServer} instance. * * @param uri uri on which the {@link ApplicationHandler} will be deployed. Only first path * segment will be used as context path, the rest will be ignored. * @param config web application configuration. * @param secure used for call {@link NetworkListener#setSecure(boolean)}. * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}. * @param parentContext DI provider specific context with application's registered bindings. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. * @see GrizzlyHttpContainer * @since 2.12 */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig config, final boolean secure, final SSLEngineConfigurator sslEngineConfigurator, final Object parentContext) { return createHttpServer(uri, new GrizzlyHttpContainer(config, parentContext), secure, sslEngineConfigurator, true); }
protected static void start() { weld = new Weld(); weld.initialize(); server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createJaxRsApp(), true); }
/** * Create new {@link HttpServer} instance. * * @param uri URI on which the Jersey web application will be deployed. Only first path segment * will be used as context path, the rest will be ignored. * @param configuration web application configuration. * @param secure used for call {@link NetworkListener#setSecure(boolean)}. * @param sslEngineConfigurator Ssl settings to be passed to {@link NetworkListener#setSSLEngineConfig}. * @param start if set to false, server will not get started, which allows to configure the * underlying transport, see above for details. * @return newly created {@code HttpServer}. * @throws ProcessingException in case of any failure when creating a new {@code HttpServer} instance. */ public static HttpServer createHttpServer(final URI uri, final ResourceConfig configuration, final boolean secure, final SSLEngineConfigurator sslEngineConfigurator, final boolean start) { return createHttpServer( uri, new GrizzlyHttpContainer(configuration), secure, sslEngineConfigurator, start); }