use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class App method main.
public static void main(String[] args) {
try {
System.out.println("\"Async resources\" Jersey Example App");
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}));
server.start();
System.out.println(String.format("Application started.\n" + "To test simple, non-blocking asynchronous messaging resource, try %s%s\n" + "To test blocking version of asynchronous messaging resource, try %s%s\n" + "To test long-running asynchronous operation resource, try %s%s\n" + "Stop the application using CTRL+C", BASE_URI, ASYNC_MESSAGING_FIRE_N_FORGET_PATH, BASE_URI, ASYNC_MESSAGING_BLOCKING_PATH, BASE_URI, ASYNC_LONG_RUNNING_OP_PATH));
Thread.currentThread().join();
} catch (IOException | InterruptedException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class PackageScanningTest method testSimpleResourceInitParameters.
@Test
public void testSimpleResourceInitParameters() throws Exception {
Map<String, String> initParams = new HashMap<String, String>();
initParams.put(ServerProperties.PROVIDER_PACKAGES, SimpleResource.class.getPackage().getName());
// TODO - temporary workaround
// This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
// classloader set
ClassLoader myClassLoader = getClass().getClassLoader();
ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
HttpServer server = null;
try {
Thread.currentThread().setContextClassLoader(myClassLoader);
server = GrizzlyWebContainerFactory.create(baseUri, ServletContainer.class, initParams);
} finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
// END of workaround - when grizzly updated to more recent version, only the inner line of try clause should remain:
_testScannedResources(server);
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class ApacheOsgiIntegrationTest method testSimpleResource.
@Test
public void testSimpleResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(ApacheOsgiTestResource.class);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final ClientConfig clientConfig = new ClientConfig();
clientConfig.connectorProvider(new ApacheConnectorProvider());
final Client c = ClientBuilder.newClient(clientConfig);
final Response response = c.target(baseUri).path("/apacheOsgiTest").request().buildGet().invoke();
final String result = response.readEntity(String.class);
assertEquals("OK", result);
server.shutdownNow();
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class BasicOsgiIntegrationTest method testSimpleResource.
@Test
public void testSimpleResource() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(SuperSimpleResource.class);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
Client c = ClientBuilder.newClient();
final Response response = c.target(baseUri).path("/super-simple").request().buildGet().invoke();
String result = response.readEntity(String.class);
System.out.println("RESULT = " + result);
assertEquals("OK", result);
server.shutdownNow();
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class BeanValidationTest method _test.
protected void _test(final int expectedResponseCode, final boolean registerFeature, final boolean disableMetainfServicesLookup) {
final ResourceConfig resourceConfig = new ResourceConfig(BeanValidationResource.class);
if (registerFeature) {
resourceConfig.register(ValidationFeature.class);
}
if (disableMetainfServicesLookup) {
resourceConfig.property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, Boolean.TRUE);
resourceConfig.register(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider.class);
}
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final Form form = new Form();
final String formValue = "formValue";
form.asMap().add("formParam", formValue);
final Client client = ClientBuilder.newClient();
final String entity = client.target(baseUri).path("/bean-validation").request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
assertEquals(formValue, entity);
final Response response = client.target(baseUri).path("/bean-validation").request().post(Entity.entity(new Form(), MediaType.APPLICATION_FORM_URLENCODED_TYPE));
assertEquals(expectedResponseCode, response.getStatus());
server.shutdownNow();
}
Aggregations