Search in sources :

Example 41 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class JaxRsRiBundleTest method testSimpleResource.

@Test
public void testSimpleResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(SimpleResource.class);
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
    final Client client = ClientBuilder.newClient();
    final String response = client.target(baseUri).path("/simple").request().get(String.class);
    System.out.println("RESULT = " + response);
    assertEquals("OK", response);
    server.shutdownNow();
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 42 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class ParamConverterInternalTest method testLazyConverter.

@Test
public void testLazyConverter() throws Exception {
    final ApplicationHandler application = new ApplicationHandler(new ResourceConfig(MyLazyParamProvider.class, Resource.class));
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
    assertEquals(400, response.getStatus());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 43 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class ActiveBindingBindingTest method testReq.

@Test
@Ignore("At the time of ignoring this test, ResourceConfig does not support HK2 Binder registering.")
public void testReq() throws Exception {
    // bootstrap the test application
    ResourceConfig myConfig = new ResourceConfig();
    myConfig.register(ReqResource.class);
    myConfig.register(SingletonResource.class);
    final MyRequestDataDescriptor activeDescriptor = new MyRequestDataDescriptor();
    myConfig.register(new AbstractBinder() {

        @Override
        protected void configure() {
            addActiveDescriptor(activeDescriptor);
        }
    });
    initiateWebApplication(myConfig);
    activeDescriptor.injectionManager = app().getInjectionManager();
    // end bootstrap
    String response;
    response = getResponseEntity("/req");
    assertThat(response, containsString(REQUEST_TAG));
    assertThat(response, not(containsString(PROXY_TAG)));
    response = getResponseEntity("/req/param");
    assertThat(response, containsString(REQUEST_TAG));
    assertThat(response, not(containsString(PROXY_TAG)));
    response = getResponseEntity("/singleton");
    assertThat(response, containsString(SINGLETON_TAG));
    assertThat(response, containsString(PROXY_TAG));
    response = getResponseEntity("/req");
    assertThat(response, containsString(REQUEST_TAG));
    assertThat(response, not(containsString(PROXY_TAG)));
    response = getResponseEntity("/singleton");
    assertThat(response, containsString(SINGLETON_TAG));
    assertThat(response, containsString(PROXY_TAG));
    response = getResponseEntity("/singleton/param");
    assertThat(response, containsString(SINGLETON_TAG));
    assertThat(response, not(containsString(PROXY_TAG)));
    response = getResponseEntity("/singleton/param");
    assertThat(response, containsString(SINGLETON_TAG));
    assertThat(response, not(containsString(PROXY_TAG)));
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 44 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class UriTest method testManagedClientInjection2.

@Test
public void testManagedClientInjection2() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource4.class);
    resourceConfig.property(Managed.class.getName() + ".property.test-property", "test-value");
    initiateWebApplication(resourceConfig);
    final ContainerResponse response = apply(RequestContextBuilder.from("/test/2", "GET").build());
    assertEquals("test-value", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 45 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class UriTest method testManagedClientInjection1.

@Test
public void testManagedClientInjection1() throws ExecutionException, InterruptedException {
    final ResourceConfig resourceConfig = new ResourceConfig(Resource4.class);
    // TODO introduce new ResourceConfig.setClientProperty(Class<? extends Annotation>, String name, Object value) helper method
    resourceConfig.property(Managed.class.getName() + ".property.test-property", "test-value");
    initiateWebApplication(resourceConfig);
    final ContainerResponse response = apply(RequestContextBuilder.from("/test/1", "GET").build());
    assertEquals("test-value", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Aggregations

ResourceConfig (org.glassfish.jersey.server.ResourceConfig)358 Test (org.junit.Test)135 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)105 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)62 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)33 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)29 Response (javax.ws.rs.core.Response)28 HttpServer (org.glassfish.grizzly.http.server.HttpServer)28 URI (java.net.URI)24 Resource (org.glassfish.jersey.server.model.Resource)24 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)23 IOException (java.io.IOException)22 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)22 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)17 ApplicationInfoListener (org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener)17 MonitoringEventListener (org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener)17 MBeanExposer (org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)17 MetricRegistry (com.codahale.metrics.MetricRegistry)15 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)15