Created
November 16, 2016 23:53
-
-
Save ljnelson/ca5d3d501cee37cfc88aff16784ae26e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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