本文整理匯總了Java中org.glassfish.grizzly.http.server.HttpServer.start方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServer.start方法的具體用法?Java HttpServer.start怎麽用?Java HttpServer.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.glassfish.grizzly.http.server.HttpServer
的用法示例。
在下文中一共展示了HttpServer.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
* @param serverURI
*/
public static HttpServer startServer(URI serverURI) throws IOException {
// create a resource config that scans for JAX-RS resources and providers
// in org.esa.pfa.ws package
final ResourceConfig resourceConfig = new ResourceConfig()
.packages("org.esa.pfa.ws")
.property("jersey.config.server.tracing.type ", "ALL");
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(serverURI, resourceConfig, false);
ServerConfiguration serverConfiguration = httpServer.getServerConfiguration();
final AccessLogBuilder builder = new AccessLogBuilder("access.log");
builder.instrument(serverConfiguration);
httpServer.start();
return httpServer;
}
示例2: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public void startServer() throws TelegramApiException {
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE); // contains server keypair
sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
ResourceConfig rc = new ResourceConfig();
rc.register(restApi);
rc.register(JacksonFeature.class);
rc.property(JSONConfiguration.FEATURE_POJO_MAPPING, true);
final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(
getBaseURI(),
rc,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
try {
grizzlyServer.start();
} catch (IOException e) {
throw new TelegramApiException("Error starting webhook server", e);
}
}
示例3: main
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
/**
* 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));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Stopping server..");
server.stop();
}, "shutdownHook"));
// run
try {
server.start();
System.out.println("Press CTRL^C to exit..");
Thread.currentThread().join();
} catch (Exception e) {
System.out.println(String.format("There was an error while starting Grizzly HTTP server.\n%s", e.getLocalizedMessage()));
}
}
示例4: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public void startServer() throws TelegramApiRequestException {
ResourceConfig rc = new ResourceConfig();
rc.register(restApi);
rc.register(JacksonFeature.class);
final HttpServer grizzlyServer;
if (keystoreServerFile != null && keystoreServerPwd != null) {
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
sslContext.setKeyStoreFile(keystoreServerFile); // contains server keypair
sslContext.setKeyStorePass(keystoreServerPwd);
grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
} else {
grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
}
try {
grizzlyServer.start();
} catch (IOException e) {
throw new TelegramApiRequestException("Error starting webhook server", e);
}
}
示例5: init
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
@EventHandler
public void init(FMLInitializationEvent event) throws Exception
{
if(event.getSide().isServer())
modpack = new Modpack(logger, solderConfig, gson);
if(event.getSide().isServer() && solderConfig.isEnabled()) {
logger.info("Loading mod MinecraftSolder");
ResourceConfig config = new ResourceConfig()
.packages("it.admiral0")
.register(new AbstractBinder() {
@Override
protected void configure() {
bind(solderConfig);
bind(Loader.instance());
bind(modpack);
bind(gson);
}
});
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(solderConfig.getBaseUri(), config);
server.getServerConfiguration().addHttpHandler(
new StaticHttpHandler(modpack.getSolderCache().toAbsolutePath().toString()), "/download"
);
server.start();
logger.info("Server running on " + solderConfig.getBaseUri().toString());
}else{
logger.info("Mod is disabled.");
}
}
示例6: registerWebsocket
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
private void registerWebsocket() throws IOException {
Configuration configuration = ConfigurationReader.INSTANCE.readConfiguration("core-site.xml");
websocketServicePort = Integer
.parseInt(configuration.get("events.server.websocket.port", "8082"));
try {
ServerSocket s = new ServerSocket(websocketServicePort);
websocketServicePort = s.getLocalPort();
s.close();
waitTillSocketIsClosed(s);
String webSocketserviceHost = java.net.InetAddress.getLocalHost().getHostAddress();
final HttpServer server = HttpServer.createSimpleServer(null, webSocketserviceHost,
websocketServicePort);
for (NetworkListener listener : server.getListeners()) {
listener.registerAddOn(new WebSocketAddOn());
}
WebSocketEngine.getEngine().register("", "/event-stream", new EventsSocketApplication());
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
}, "Server-Showdown-Thread"));
} catch (IOException | InterruptedException e) {
throw new IllegalStateException("Failed to start api-service. name = events.service", e);
}
}
示例7: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public static HttpServer startServer() {
HttpServer server = new HttpServer();
server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080));
final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
//transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
server.getListener("grizzly").setTransport(transportBuilder.build());
final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey");
rc.register(JacksonFeature.class);
final ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/");
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
return server;
}
示例8: start
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public static void start(final ApplicationContext applicationConfig, final int port, String path) {
try {
// Logging settings
InputStream loggingStream = GrizzlyServer.class.getResourceAsStream("/logging.properties");
if (nonNull(loggingStream)) {
LogManager.getLogManager().readConfiguration(loggingStream);
}
HttpServer server = HttpServer.createSimpleServer(null, port);
server.getServerConfiguration().addHttpHandler(
new GrizzlyApplicationHandler(applicationConfig), path);
Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
server.start();
LOG.info("Grizzly Server started. Stop the application using ^C.");
Thread.currentThread().join();
} catch (IOException | InterruptedException e) {
LOG.log(Level.SEVERE, null, e);
}
}
示例9: main
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// Start server and wait for user input to stop
final HttpServer server = startServer();
try {
server.start();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\n", BASE_URI));
// Wait forever (i.e. until the JVM instance is terminated externally)
Thread.currentThread().join();
} catch (Exception ioe) {
System.out.println("Error running Luzzu Communications service: " + ioe.toString());
} finally {
if(server != null && server.isStarted()) {
server.shutdownNow();
}
}
}
示例10: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public static HttpServer startServer() throws IOException {
String baseUri = ConfigProperties.getInstance().getProperty("BASE_URI");
if(baseUri != null) {
BASE_URI = baseUri;
LOG.info("base uri set to: "+baseUri);
}
final ResourceConfig rc = new ResourceConfig().packages("org.eu.eark.hsink");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
URI.create(BASE_URI), rc, false);
ServerConfiguration serverConfig = server.getServerConfiguration();
NetworkListener nL = server.getListener(server.getListeners().iterator()
.next().getName()); // grizzly
// disable server timeouts
nL.setChunkingEnabled(true);
nL.setDisableUploadTimeout(true);
nL.getKeepAlive().setIdleTimeoutInSeconds(-1); // 256
// server.getServerConfiguration();
server.start();
return server;
}
示例11: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
private HttpServer startServer(URI uri) throws IOException {
ResourceConfig rc = new RallyeApplication();
HttpServer serv = createServer(uri, rc); // Do NOT start the server just yet
logger.info("Starting Grizzly server at " + uri);
//Register Websocket Stuff
WebSocketAddOn addon = new WebSocketAddOn();
for(org.glassfish.grizzly.http.server.NetworkListener listener : serv.getListeners()) {
logger.info("Registering websocket on "+listener);
listener.registerAddOn(addon);
}
PushWebsocketApp.setData(RallyeBinder.data); //TODO: Remove this ugliness.
AdminWebsocketApp.setData(RallyeBinder.data); //TODO: Remove this ugliness.
WebSocketEngine.getEngine().register("/rallye", "/push", PushWebsocketApp.getInstance());
WebSocketEngine.getEngine().register("/rallye","/admin", AdminWebsocketApp.getInstance());
serv.start();
return serv;
}
示例12: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
/**
* Starts Grizzly HTTP server exposing SMAPH JAX-RS resources.
*
* @throws URISyntaxException
* @throws ProcessingException
*/
public static void startServer(String serverUri, Path storageBase, String watGcubeToken) throws ProcessingException, URISyntaxException {
LOG.info("Initializing SMAPH services.");
LOG.info("Storage path: {}", storageBase.toAbsolutePath());
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(new URI(serverUri));
httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("src/main/webapp/"), "/*");
WebappContext context = new WebappContext("smaph");
ResourceConfig rc = new ResourceConfig().packages("it.unipi.di.acube.smaph.servlet");
ServletRegistration registration = context.addServlet("ServletContainer", new ServletContainer(rc));
registration.addMapping("/smaph/*");
context.addListener(SmaphContextListener.class);
context.setInitParameter(SmaphContextListener.WIKI_PAGES_DB, storageBase.resolve("mapdb/wikipedia_pages.db").toString());
context.setInitParameter(SmaphContextListener.FREEBASE_DIR, storageBase.resolve("mapdb/freebase.db").toString());
context.setInitParameter(SmaphContextListener.ENTITY_TO_ANCHORS_DB, storageBase.resolve("mapdb/e2a.db").toString());
context.setInitParameter(SmaphContextListener.WAT_GCUBE_TOKEN, watGcubeToken);
context.deploy(httpServer);
try {
httpServer.start();
LOG.info("Smaph started with WADL available at " + "{}application.wadl\nPress CTRL^C (SIGINT) to terminate.",
serverUri);
Thread.currentThread().join();
LOG.info("Shutting server down..");
} catch (Exception e) {
LOG.error("There was an error while starting Grizzly HTTP server.", e);
}
}
示例13: startServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public HttpServer startServer() throws IOException {
HttpServer theServer;
// String[] packages = { "streams.prometheus.exporter.rest.resources",
// "streams.prometheus.exporter.rest.errorhandling",
// "streams.prometheus.exporter.rest.serializers" };
//final ResourceConfig rc = new ResourceConfig().packages(packages);
// Enable JSON media conversions
//rc.register(JacksonFeature.class);
WebappContext context = new WebappContext("WebappContext","");
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter("jersey.config.server.provider.packages",
"streams.metric.exporter.rest.resources;streams.metric.exporter.rest.errorhandling;streams.metric.exporter.rest.serializers");
registration.addMapping("/*");
//if (this.serverProtocol.equalsIgnoreCase("https")) {
if (this.serverProtocol == Protocol.HTTPS) {
LOGGER.debug("Using https protocol");
theServer = createHttpsServer();
} else {
LOGGER.debug("Using http protcol");
theServer = createHttpServer();
}
// Prometheus servlet
// FUTURE: if we go with plugin this needs to be variant if it is created or not
//ServletRegistration prometheus = context.addServlet("PrometheusContainer",new MetricsServlet());
//prometheus.addMapping("/prometheus");
context.deploy(theServer);
theServer.start();
return theServer;
}
示例14: main
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
// register the endpoint resource
final ResourceConfig config = new ResourceConfig().register(ProductEndpoint.class);
// create and start Grizzly server
final HttpServer grizzlyServer = GrizzlyHttpServerFactory
.createHttpServer(URI.create("http://localhost:8080/api/"), config);
grizzlyServer.start();
// wait for a key press to shutdown
System.in.read();
grizzlyServer.shutdown();
}
示例15: TintServer
import org.glassfish.grizzly.http.server.HttpServer; //導入方法依賴的package包/類
public TintServer(String host, Integer port, @Nullable File configFile,
@Nullable Properties additionalProperties) {
LOGGER.info("starting " + host + "\t" + port + " (" + new Date() + ")...");
int timeoutInSeconds = -1;
try {
// Load the pipeline
TintPipeline pipeline = new TintPipeline();
pipeline.loadDefaultProperties();
pipeline.loadPropertiesFromFile(configFile);
pipeline.addProperties(additionalProperties);
// todo: parametrize this!
// pipeline.loadSerializers();
pipeline.load();
LOGGER.info("Pipeline loaded");
final HttpServer httpServer = new HttpServer();
NetworkListener nl = new NetworkListener("tint-server", host, port);
httpServer.addListener(nl);
TintHandler tintHandler = new TintHandler(pipeline);
tintHandler.setRequestURIEncoding(Charset.forName("UTF-8"));
httpServer.getServerConfiguration().setSessionTimeoutSeconds(timeoutInSeconds);
httpServer.getServerConfiguration().setMaxPostSize(4194304);
httpServer.getServerConfiguration().addHttpHandler(tintHandler, "/tint");
httpServer.start();
Thread.currentThread().join();
} catch (Exception e) {
LOGGER.error("error running " + host + ":" + port);
e.printStackTrace();
}
}