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));
}
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);
}
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);
}
}
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));
}
}
}
}
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);
}
Aggregations