Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Copyright 2016 Laird Nelson. Released under the terms of the MIT license: https://opensource.org/licenses/MIT
*/
package serverco;
import java.net.URI;
import java.net.URISyntaxException;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.CreationException;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.ws.rs.core.Application;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ContainerFactory;
@ApplicationScoped
class Producers {
private Producers() {
super();
}
@Produces
@Dependent
private static final GrizzlyHttpContainer produceGrizzlyHttpContainer(final Instance<Application> applicationInstance) {
final GrizzlyHttpContainer returnValue;
if (applicationInstance == null || applicationInstance.isUnsatisfied()) {
returnValue = null;
} else {
returnValue = ContainerFactory.createContainer(GrizzlyHttpContainer.class, applicationInstance.get());
}
return returnValue;
}
@Produces
@Dependent
private static final HttpServer produceHttpServer(final Instance<GrizzlyHttpContainer> handlerInstance) {
final HttpServer returnValue;
if (handlerInstance == null || handlerInstance.isUnsatisfied()) {
returnValue = null;
} else {
URI uri = null;
try {
uri = new URI("ignored", null /* no userInfo */, "localhost", 80, null, null /* no query */, null /* no fragment */);
} catch (final URISyntaxException uriSyntaxException) {
throw new CreationException(uriSyntaxException);
}
returnValue = GrizzlyHttpServerFactory.createHttpServer(uri, handlerInstance.get(), false, null, false);
}
return returnValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment