use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class MultiPartTest method testMultiPartResource.
@Test
public void testMultiPartResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(MultiPartResource.class).register(new MultiPartFeature());
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
Client c = ClientBuilder.newClient(new ClientConfig().register(MultiPartFeature.class));
final Response response = c.target(baseUri).path("/multipart-simple").request().buildGet().invoke();
MultiPart result = response.readEntity(MultiPart.class);
System.out.println("RESULT = " + result);
checkEntity("This is the only segment", (BodyPartEntity) result.getBodyParts().get(0).getEntity());
server.shutdownNow();
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class PackageScanningTest method testSimpleResource.
@Test
public void testSimpleResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig().packages(SimpleResource.class.getPackage().getName());
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
_testScannedResources(server);
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class ResourceBundleTest method testBadResource.
@Test
public void testBadResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(BadResource.class);
ByteArrayOutputStream logOutput = new ByteArrayOutputStream();
Handler logHandler = new StreamHandler(logOutput, new SimpleFormatter());
GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
// TODO: there should be a better way to get the log output!
final Enumeration<String> loggerNames = LogManager.getLogManager().getLoggerNames();
while (loggerNames.hasMoreElements()) {
String name = loggerNames.nextElement();
if (name.startsWith("org.glassfish")) {
LogManager.getLogManager().getLogger(Errors.class.getName()).addHandler(logHandler);
}
}
GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
logOutput.flush();
final String logOutputAsString = logOutput.toString();
Assert.assertFalse(logOutputAsString.contains("[failed to localize]"));
Assert.assertTrue(logOutputAsString.contains("BadResource"));
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class SseTest method testSse.
@Test
public void testSse() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(SseResource.class, SseFeature.class);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
Client c = ClientBuilder.newClient();
c.register(SseFeature.class);
final List<String> data = new LinkedList<String>();
final CountDownLatch latch = new CountDownLatch(2);
final EventSource eventSource = new EventSource(c.target(baseUri).path("/sse")) {
@Override
public void onEvent(InboundEvent event) {
try {
data.add(event.readData());
latch.countDown();
} catch (ProcessingException e) {
// ignore
}
}
};
assertTrue(latch.await(2, TimeUnit.SECONDS));
eventSource.close();
assertEquals(2, data.size());
server.shutdownNow();
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class AbstractJsonOsgiIntegrationTest method testJson.
@Test
public void testJson() throws Exception {
final Feature jsonProviderFeature = getJsonProviderFeature();
final Client client = ClientBuilder.newClient();
final ResourceConfig resourceConfig = new ResourceConfig(JsonResource.class);
if (jsonProviderFeature != null) {
client.register(jsonProviderFeature);
resourceConfig.register(jsonProviderFeature);
}
HttpServer server = null;
try {
server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final String result = client.target(baseUri).path("/json").request(MediaType.APPLICATION_JSON).get(String.class);
System.out.println("RESULT = " + result);
assertThat(result, containsString("Jim"));
} finally {
if (server != null) {
server.shutdownNow();
}
}
}
Aggregations