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("Jersey Entity Data Filtering Example.");
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new EntityFilteringApplication(), false);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}));
server.start();
System.out.println("Application started.\nTry out one of these URIs:");
for (final String path : new String[] { "projects", "projects/detailed", "users", "users?detailed=true", "tasks", "tasks/detailed" }) {
System.out.println(BASE_URI + path);
}
System.out.println("Stop the application using CTRL+C");
Thread.currentThread().join();
} catch (IOException | InterruptedException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, "I/O error occurred during reading from an system input stream.", ex);
}
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class Server method start.
/**
* Start SSL-secured HTTP test server.
*
* @throws IOException in case there is an error while reading server key store or trust store.
* @return an instance of the started SSL-secured HTTP test server.
*/
public static Server start(String keystore) throws IOException {
final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
final InputStream keyStore = Server.class.getResourceAsStream(keystore);
// Grizzly ssl configuration
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
// contains server key pair
sslContext.setKeyStoreBytes(ByteStreams.toByteArray(keyStore));
sslContext.setKeyStorePass("asdfgh");
// contains client certificate
sslContext.setTrustStoreBytes(ByteStreams.toByteArray(trustStore));
sslContext.setTrustStorePass("asdfgh");
ResourceConfig rc = new ResourceConfig();
rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
// start Grizzly embedded server //
LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
grizzlyServer.start();
return new Server(grizzlyServer);
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class Main method main.
/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.
the class JsonProcessingTest method testJsonObject.
@Test
public void testJsonObject() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(Resource.class);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final JsonObject jsonObject = Json.createObjectBuilder().add("foo", "bar").build();
final Client client = ClientBuilder.newClient();
final JsonObject entity = client.target(baseUri).request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonObject), JsonObject.class);
System.out.println("RESULT = " + entity);
assertEquals(jsonObject, entity);
server.shutdownNow();
}
use of org.glassfish.grizzly.http.server.HttpServer 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();
}
Aggregations