use of org.glassfish.grizzly.http.server.HttpServer 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.grizzly.http.server.HttpServer 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.grizzly.http.server.HttpServer in project jersey by jersey.
the class JerseyApp method main.
public static void main(final String[] args) throws Exception {
System.out.println("Jersey performance test web service application");
final URI baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, createResourceConfig());
System.out.println(String.format("Application started.\nTry out %s%s\nHit Ctrl-C to stop it...", baseUri, ROOT_PATH));
while (server.isStarted()) {
Thread.sleep(600000);
}
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class TestDataGeneratorApp method main.
public static void main(final String[] args) throws Exception {
baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, createApp());
LOG.info("Jersey performance test data generation - application started.");
try {
// generate text files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
generateFile("simple/text", 1024, FILE_PATH + "custom-1kb.text");
generateFile("simple/text", 5 * 1024, FILE_PATH + "custom-5kb.text");
generateFile("simple/text", 10 * 1024, FILE_PATH + "custom-10kb.text");
generateFile("simple/text", 1024 * 1024, FILE_PATH + "custom-1MB.text");
if (GENERATE_ALSO_GIGABYTE_DATASETS) {
generateFile("text", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.text");
}
// generate json files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
generateFile("simple/json", 1024, FILE_PATH + "custom-1kb.json");
generateFile("simple/json", 5 * 1024, FILE_PATH + "custom-5kb.json");
generateFile("simple/json", 10 * 1024, FILE_PATH + "custom-10kb.json");
generateFile("simple/json", 1024 * 1024, FILE_PATH + "custom-1MB.json");
if (GENERATE_ALSO_GIGABYTE_DATASETS) {
generateFile("simple/json", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.json");
}
// generate xml files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
generateFile("simple/xml", 1024, FILE_PATH + "custom-1kb.xml");
generateFile("simple/xml", 5 * 1024, FILE_PATH + "custom-5kb.xml");
generateFile("simple/xml", 10 * 1024, FILE_PATH + "custom-10kb.xml");
generateFile("simple/xml", 1024 * 1024, FILE_PATH + "custom-1MB.xml");
if (GENERATE_ALSO_GIGABYTE_DATASETS) {
generateFile("simple/xml", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.json");
}
} catch (final IOException e) {
LOG.log(Level.SEVERE, "An error occurred during test data generation. ", e);
}
server.shutdown();
}
use of org.glassfish.grizzly.http.server.HttpServer 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