org.glassfish.jersey.server.ApplicationHandler Java Examples

The following examples show how to use org.glassfish.jersey.server.ApplicationHandler. 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: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #2
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #3
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #4
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #5
Source File: JerseyRouteExecutionStrategyUtils.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
static RouteStrategiesConfig validateRouteStrategies(
        final ApplicationHandler applicationHandler,
        final RouteExecutionStrategyFactory<HttpExecutionStrategy> strategyFactory) {

    final ExtendedResourceContext resourceContext =
            applicationHandler.getInjectionManager().getInstance(ExtendedResourceContext.class);
    if (resourceContext == null) {
        return new RouteStrategiesConfig(emptyMap(), emptyMap());
    }

    final RouteExecutionStrategyValidator validator = new RouteExecutionStrategyValidator(strategyFactory);
    resourceContext.getResourceModel().accept(validator);
    if (!validator.errors.isEmpty()) {
        throw new IllegalArgumentException("Invalid execution strategy configuration found:\n" + validator.errors);
    }

    return new RouteStrategiesConfig(validator.routeStrategies, validator.methodDefaultStrategies);
}
 
Example #6
Source File: RouterTest.java    From minnal with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void setup() {
	applicationMapping = mock(ApplicationMapping.class);
	request = mock(FullHttpRequest.class);
	response = mock(FullHttpResponse.class);
	when(request.getMethod()).thenReturn(HttpMethod.GET);
	when(request.getUri()).thenReturn("/test");
	when(request.headers()).thenReturn(new DefaultHttpHeaders());
	when(request.content()).thenReturn(mock(ByteBuf.class));
	when(request.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1);
	when(response.getStatus()).thenReturn(HttpResponseStatus.PROCESSING);
	application = mock(Application.class);
	context = mock(MessageContext.class);
	router = spy(new Router(applicationMapping));
	doReturn(new ApplicationHandler()).when(router).getApplicationHandler(application);
	when(application.getPath()).thenReturn(URI.create("/app"));
	when(context.getRequest()).thenReturn(request);
	when(context.getResponse()).thenReturn(response);
	when(context.getApplication()).thenReturn(application);
	when(context.getBaseUri()).thenReturn(URI.create("http://localhost:8080"));
	when(applicationMapping.resolve(request)).thenReturn(application);
}
 
Example #7
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #8
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #9
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void reload_ConfigGiven_ShouldReloadNewAppHandler() {
	ResourceConfig config = new ApplicationHandler().getConfiguration();
	ApplicationHandler newAppHandler = mock(ApplicationHandler.class);
	doReturn(newAppHandler).when(container).createNewApplicationHandler(any());
	container.reload(config);
	verify(newAppHandler, times(1)).onReload(container);
}
 
Example #10
Source File: JerseyHandlerFilter.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new handler filter with a Jax RS application object.
 * @param jaxApplication The JAX RS application to load
 */
JerseyHandlerFilter(Application jaxApplication) {
    Timer.start("JERSEY_FILTER_CONSTRUCTOR");
    app = jaxApplication;

    jersey = new ApplicationHandler(app);
    jersey.onStartup(this);
    Timer.stop("JERSEY_FILTER_CONSTRUCTOR");
}
 
Example #11
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #12
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}
 
Example #13
Source File: DefaultJerseyStreamingHttpRouter.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
DefaultJerseyStreamingHttpRouter(final Application application,
                                 final int publisherInputStreamQueueCapacity,
                                 final BiFunction<ConnectionContext, HttpRequestMetaData, String> baseUriFunction,
                                 final RouteExecutionStrategyFactory<HttpExecutionStrategy> strategyFactory) {
    this(new ApplicationHandler(application), publisherInputStreamQueueCapacity, baseUriFunction,
            strategyFactory);
}
 
Example #14
Source File: DefaultJerseyStreamingHttpRouter.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
DefaultJerseyStreamingHttpRouter(final Class<? extends Application> applicationClass,
                                 final int publisherInputStreamQueueCapacity,
                                 final BiFunction<ConnectionContext, HttpRequestMetaData, String> baseUriFunction,
                                 final RouteExecutionStrategyFactory<HttpExecutionStrategy> strategyFactory) {
    this(new ApplicationHandler(applicationClass), publisherInputStreamQueueCapacity, baseUriFunction,
            strategyFactory);
}
 
Example #15
Source File: DefaultJerseyStreamingHttpRouter.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private DefaultJerseyStreamingHttpRouter(final ApplicationHandler applicationHandler,
                                         final int publisherInputStreamQueueCapacity,
                                         final BiFunction<ConnectionContext, HttpRequestMetaData,
                                                 String> baseUriFunction,
                                         final RouteExecutionStrategyFactory<HttpExecutionStrategy>
                                                 strategyFactory) {

    if (!applicationHandler.getConfiguration().isEnabled(ServiceTalkFeature.class)) {
        throw new IllegalStateException("The " + ServiceTalkFeature.class.getSimpleName()
                + " needs to be enabled for this application.");
    }

    final RouteStrategiesConfig routeStrategiesConfig =
            validateRouteStrategies(applicationHandler, strategyFactory);

    this.applicationHandler = applicationHandler;
    this.publisherInputStreamQueueCapacity = publisherInputStreamQueueCapacity;
    this.baseUriFunction = requireNonNull(baseUriFunction);

    applicationHandler.getInjectionManager().register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(routeStrategiesConfig).to(RouteStrategiesConfig.class).proxy(false);
        }
    });

    container = new DefaultContainer(applicationHandler);
    applicationHandler.onStartup(container);
}
 
Example #16
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #17
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #18
Source File: RouterTest.java    From minnal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotCreateApplicationHandlerSecondTime() {
	router = spy(new Router(applicationMapping));
	ResourceConfig config = mock(ResourceConfig.class);
	when(application.getResourceConfig()).thenReturn(config);
	ApplicationHandler handler = new ApplicationHandler();
	doReturn(handler).when(router).createApplicationHandler(config);
	handler = router.getApplicationHandler(application);
	assertEquals(router.getApplicationHandler(application), handler);
}
 
Example #19
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}
 
Example #20
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void reload_ConfigGiven_ShouldStartNewAppHandler() {
	ResourceConfig config = new ApplicationHandler().getConfiguration();
	ApplicationHandler newAppHandler = mock(ApplicationHandler.class);
	doReturn(newAppHandler).when(container).createNewApplicationHandler(any());
	container.reload(config);
	verify(newAppHandler, times(1)).onStartup(container);
}
 
Example #21
Source File: JRestlessHandlerContainerTest.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@Test
public void reload_ConfigGiven_ShouldResetAppHandler() {
	ResourceConfig config = new ApplicationHandler().getConfiguration();
	ApplicationHandler newAppHandler = mock(ApplicationHandler.class);
	doReturn(newAppHandler).when(container).createNewApplicationHandler(any());
	container.reload(config);
	assertSame(newAppHandler, container.getApplicationHandler());
}
 
Example #22
Source File: AuthServerHelper.java    From divide with Apache License 2.0 5 votes vote down vote up
public void init(String url) throws Exception {
    URI uri = URI.create(url);
    ApplicationHandler h = new ApplicationHandler(TestApplication.class);
    WebContainerFactory factory = new WebContainerFactory();
    factory.enableEncrementPort(false);
    container = factory.create(uri,h);
    container.start();
}
 
Example #23
Source File: NettyRestServerListener.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void onAfterShutdown(Object obj) {
  if (container instanceof NettyRestHandlerContainer) {
    NettyRestHandlerContainer restHandlerContainer = ((NettyRestHandlerContainer) container);
    ApplicationHandler applicationHandler = restHandlerContainer.getApplicationHandler();
    ContainerLifecycleListener lifecycleListener = ConfigHelper.getContainerLifecycleListener(applicationHandler);
    lifecycleListener.onShutdown(container);
  }
}
 
Example #24
Source File: NettyRestServerListener.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void onAfterStart(Object obj) {
  if (container instanceof NettyRestHandlerContainer) { 
    NettyRestHandlerContainer restHandlerContainer = ((NettyRestHandlerContainer) container);
    ApplicationHandler applicationHandler = restHandlerContainer.getApplicationHandler();
    ContainerLifecycleListener lifecycleListener = ConfigHelper.getContainerLifecycleListener(applicationHandler);
    lifecycleListener.onStartup(container);
  }
}
 
Example #25
Source File: NettyRestHandlerContainerProvider.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T createContainer(Class<T> type, ApplicationHandler application) throws ProcessingException {
  if (type != NettyRestHandlerContainer.class && 
      (type == null || !ChannelHandler.class.isAssignableFrom(type))) {
    return null;
  }
  return type.cast(new NettyRestHandlerContainer(application));
}
 
Example #26
Source File: WebContainerFactory.java    From divide with Apache License 2.0 5 votes vote down vote up
@Override
public TestContainer create(URI baseUri, ApplicationHandler application) throws IllegalArgumentException {
    URI uri = UriBuilder.fromUri(baseUri).port(baseUri.getPort() + getCount()).build();
    System.out.println("Uri: " + uri);
    System.out.println("App: " + application.getConfiguration().getApplication().getClass().getName());

    return new MyTestContainer(uri, application);
}
 
Example #27
Source File: ConfigHelper.java    From ameba with MIT License 5 votes vote down vote up
@Override
public void onShutdown(final Container container) {
    final ApplicationHandler handler = container.getApplicationHandler();
    final InjectionManager injectionManager = handler.getInjectionManager();

    // Call @PreDestroy method on Application.
    injectionManager.preDestroy(getWrappedApplication(handler.getConfiguration()));
    // Shutdown ServiceLocator.
    injectionManager.shutdown();
}
 
Example #28
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #29
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #30
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}