Search in sources :

Example 31 with Application

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

the class SortedOutputTest method setUp.

@BeforeMethod
public void setUp() {
    scanner = new JaxrsApplicationAndAnnotationScanner();
    scanner.setApplication(new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return Collections.singleton(ResourceInApplication.class);
        }
    });
}
Also used : Set(java.util.Set) Application(javax.ws.rs.core.Application) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 32 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 33 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 34 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 35 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)

Aggregations

Application (javax.ws.rs.core.Application)63 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)12 ApplicationInfo (org.apache.cxf.jaxrs.model.ApplicationInfo)12 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Set (java.util.Set)7 ServletException (javax.servlet.ServletException)7 Annotation (java.lang.annotation.Annotation)5 List (java.util.List)5 Map (java.util.Map)5 ApplicationPath (javax.ws.rs.ApplicationPath)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 Collection (java.util.Collection)3