Search in sources :

Example 11 with Application

use of javax.ws.rs.core.Application in project jersey by jersey.

the class ResourceConfigBuilderTest method testApplication.

@Test
public void testApplication() {
    final javax.ws.rs.core.Application application = new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return super.getClasses();
        }

        @Override
        public Set<Object> getSingletons() {
            return super.getSingletons();
        }
    };
    ApplicationHandler ah = new ApplicationHandler(application);
    assertTrue(ah.getInjectionManager().getInstance(Application.class).equals(application));
}
Also used : Application(javax.ws.rs.core.Application) Application(javax.ws.rs.core.Application) Test(org.junit.Test)

Example 12 with Application

use of javax.ws.rs.core.Application in project jersey by jersey.

the class ApplicationTest method testGetSingletonsNull.

@Test
public void testGetSingletonsNull() {
    Application a = new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return Collections.emptySet();
        }

        @Override
        public Set<Object> getSingletons() {
            return null;
        }
    };
    new ApplicationHandler(a);
}
Also used : Application(javax.ws.rs.core.Application) Test(org.junit.Test)

Example 13 with Application

use of javax.ws.rs.core.Application in project jersey by jersey.

the class RuntimeDelegateTest method testFetch.

@Test
public void testFetch() throws Exception {
    final HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    final HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return Collections.<Class<?>>singleton(Resource.class);
        }
    }, HttpHandler.class);
    try {
        server.createContext("/", handler);
        server.start();
        final Response response = ClientBuilder.newClient().target(UriBuilder.fromUri("http://localhost/").port(server.getAddress().getPort()).build()).request().get();
        assertThat(response.readEntity(String.class), is("get"));
    } finally {
        server.stop(0);
    }
}
Also used : Response(javax.ws.rs.core.Response) HttpHandler(com.sun.net.httpserver.HttpHandler) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) Application(javax.ws.rs.core.Application) Test(org.junit.Test)

Example 14 with Application

use of javax.ws.rs.core.Application in project jersey by jersey.

the class JerseyServletContainerInitializer method addServletWithDefaultConfiguration.

/**
     * Enhance default servlet (named {@link Application}) configuration.
     */
private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException {
    ServletRegistration registration = context.getServletRegistration(Application.class.getName());
    if (registration != null) {
        final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes);
        final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses).addProperties(getInitParams(registration)).addProperties(Utils.getContextParams(context));
        if (registration.getClassName() != null) {
            // class name present - complete servlet registration from container point of view
            Utils.store(resourceConfig, context, registration.getName());
        } else {
            // no class name - no complete servlet registration from container point of view
            final ServletContainer servlet = new ServletContainer(resourceConfig);
            registration = context.addServlet(registration.getName(), servlet);
            ((ServletRegistration.Dynamic) registration).setLoadOnStartup(1);
            if (registration.getMappings().isEmpty()) {
                // Error
                LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName()));
            } else {
                LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses));
            }
        }
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Application(javax.ws.rs.core.Application)

Example 15 with Application

use of javax.ws.rs.core.Application in project swagger-core by swagger-api.

the class DefaultJaxrsScannerTest method classesFromContextTest.

@Test(description = "should return singletones")
public void classesFromContextTest() {
    Application app = mock(Application.class);
    Set<Object> singletons = Sets.newHashSet(new io.swagger.jaxrs.listing.ApiListingResource(), new DefaultJaxrsScannerTest());
    when(app.getClasses()).thenReturn(null);
    when(app.getSingletons()).thenReturn(singletons);
    DefaultJaxrsScanner scanner = new DefaultJaxrsScanner();
    Set<Class<?>> output = scanner.classesFromContext(app, null);
    Set<Class<?>> classes = Sets.newHashSet(Iterables.transform(singletons, new Function<Object, Class<?>>() {

        @Override
        public Class<?> apply(Object o) {
            return o.getClass();
        }
    }));
    assertEquals(output, classes);
}
Also used : Function(com.google.common.base.Function) DefaultJaxrsScanner(io.swagger.jaxrs.config.DefaultJaxrsScanner) Application(javax.ws.rs.core.Application) Test(org.testng.annotations.Test)

Aggregations

Application (javax.ws.rs.core.Application)19 HashSet (java.util.HashSet)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)3 BeanContext (org.apache.openejb.BeanContext)3 IdPropertiesInfo (org.apache.openejb.assembler.classic.IdPropertiesInfo)3 ServiceConfiguration (org.apache.openejb.assembler.classic.util.ServiceConfiguration)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Set (java.util.Set)2 ServiceException (org.apache.openejb.server.ServiceException)2 MetaAnnotatedClass (org.apache.xbean.finder.MetaAnnotatedClass)2 Function (com.google.common.base.Function)1 HttpHandler (com.sun.net.httpserver.HttpHandler)1 HttpServer (com.sun.net.httpserver.HttpServer)1 DefaultJaxrsScanner (io.swagger.jaxrs.config.DefaultJaxrsScanner)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetSocketAddress (java.net.InetSocketAddress)1