本文整理汇总了Java中org.glassfish.grizzly.http.server.HttpServer类的典型用法代码示例。如果您正苦于以下问题:Java HttpServer类的具体用法?Java HttpServer怎么用?Java HttpServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpServer类属于org.glassfish.grizzly.http.server包,在下文中一共展示了HttpServer类的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: createHttpsServer
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
private HttpServer createHttpsServer() {
SSLContextConfigurator sslContextConfig = new SSLContextConfigurator();
// set up security context
sslContextConfig.setKeyStoreFile(this.serverKeystore); // contains server cert and key
sslContextConfig.setKeyStorePass(this.serverKeystorePwd);
// Create context and have exceptions raised if anything wrong with keystore or password
SSLContext sslContext = sslContextConfig.createSSLContext(true);
// Create server but do not start it
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(this.baseUri),false);
//LOGGER.debug("About to loop through listeners");
//for (NetworkListener listener : server.getListeners()) {
// LOGGER.debug("About to setSecure on listener name: " + listener.getName());
//}
// grizzly is the default listener name
server.getListener("grizzly").setSecure(true);
// One way authentication
server.getListener("grizzly").setSSLEngineConfig(new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
return server;
}
示例3: httpBuilder
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
public static HttpServer httpBuilder (String connectionUrl, String profileName) {
try {
URL url = new URL(connectionUrl);
System.setProperty("spring.profiles.active", profileName);
AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringAnnotationConfig.class);
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(RequestContextFilter.class);
resourceConfig.property("contextConfig", annotationConfigApplicationContext);
resourceConfig.register(RestSupport.class);
URI baseUri = URI.create(url.getProtocol() + "://" + url.getAuthority());
return GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
} catch (Exception e) {
Assert.fail("Could'n parse configfile." + e.getMessage());
}
return null;
}
示例4: 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);
}
}
示例5: 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()));
}
}
示例6: main
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Logger log = Logger.getLogger(Main.class.getName());
log.log(Level.WARNING,"Starting server .....");
Logger log2 = Logger.getLogger("org.glassfish");
log2.setLevel(Level.ALL);
log2.addHandler(new java.util.logging.ConsoleHandler());
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();
}
示例7: 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);
}
}
示例8: 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.");
}
}
示例9: 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);
}
}
示例10: 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;
}
示例11: shutDown
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
/**
* Gracefully stop REST service.
*/
@Override
protected void shutDown() throws Exception {
long traceId = LoggerHelpers.traceEnterWithContext(log, this.objectId, "shutDown");
try {
log.info("Stopping REST server listening on port: {}", this.restServerConfig.getPort());
final GrizzlyFuture<HttpServer> shutdown = httpServer.shutdown(30, TimeUnit.SECONDS);
log.info("Awaiting termination of REST server");
shutdown.get();
log.info("REST server terminated");
} finally {
LoggerHelpers.traceLeave(log, this.objectId, "shutDown", traceId);
}
}
示例12: httpServer
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
@Bean
public HttpServer httpServer()
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException,
FileNotFoundException, CertificateException, UnrecoverableEntryException, ConfigurationException {
HttpServer server = HttpServer.createSimpleServer("./", 8080);
WebSocketAddOn addon = new WebSocketAddOn();
server.getListeners().stream().forEach((listen) -> {
listen.registerAddOn(addon);
listen.setSecure(true);
listen.setSSLEngineConfig(
new SSLEngineConfigurator(this.sslConf()).setClientMode(false).setNeedClientAuth(false));
});
String messengerPath = configuration().getString(GlobalConfig.MESSENGER_PATH);
if (messengerPath == null) {
messengerPath = GlobalConfig.MESSENGER_PATH_DEFAULT;
}
ChatApplication application = this.chatApplication();
WebSocketEngine.getEngine().register("", messengerPath, application);
return server;
}
示例13: testMain
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
@Test
public void testMain() throws IOException, InterruptedException {
HttpServerFactory serverFactory = mock(HttpServerFactory.class);
HttpServer server = mock(HttpServer.class);
when(serverFactory.provide()).thenReturn(server);
HttpServerFactory defaultServerFactory = Main.serverFactory;
Main.serverFactory = serverFactory;
Main.main(new String[] { "-port", "9876", "-dynamodb_endpoint", "dynamodb_endpoint_value",
"-dynamodb_table_prefix", "dynamodb_table_prefix_value", "-bucket_name_picture",
"bucket_name_picture_value", "-cloudsearch_domain_prefix", "cloudsearch_domain_prefix_value", });
Main.serverFactory = defaultServerFactory;
verify(server).start();
assertEquals("9876", Env.instance.get("PORT").get());
assertEquals("dynamodb_endpoint_value", Env.instance.get("DYNAMODB_ENDPOINT").get());
assertEquals("dynamodb_table_prefix_value", Env.instance.get("DYNAMODB_TABLE_PREFIX").get());
assertEquals("bucket_name_picture_value", Env.instance.get("BUCKET_NAME_PICTURE").get());
assertEquals("cloudsearch_domain_prefix_value", Env.instance.get("CLOUDSEARCH_DOMAIN_PREFIX").get());
}
示例14: run
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
private void run() throws IOException {
URI uri = getBaseURI();
final HttpServer httpServer = startServer(uri);
LOG.info("Jersey app started with WADL available at {}/application.wadl\n", uri);
System.out.println("-----------------------------");
System.out.println("Antioch server started at " + uri);
System.out.println("press Ctrl-c to stop");
System.out.println("-----------------------------");
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown(httpServer)));
while (true) {
try {
Thread.sleep(ONE_HOUR);
} catch (InterruptedException e) {
System.out.println("-----------------------------");
System.out.println("Stopping Antioch server...");
System.out.println("-----------------------------");
shutdown(httpServer);
System.out.println("bye!");
}
}
}
示例15: PullServer
import org.glassfish.grizzly.http.server.HttpServer; //导入依赖的package包/类
public PullServer(PushSerConfig config) {
this.wsContext = new PushContext(config);
this.center = new MessageCenter();
PreCheckListener check = new PreCheckListener(center);
ProtocolManager instance = ProtocolManager.getInstance();
instance.addCodec(new RFC6455CodecImpl());
this.wsContext.setProtocolManager(instance);
this.wsContext.addConnListener(check);
this.wsContext.setMessageCenter(center);
this.port = config.getPort();
String base = config.getResourceBase();
server = HttpServer.createSimpleServer(base, port);
sercfg = server.getServerConfiguration();
sercfg.getMonitoringConfig().getWebServerConfig().addProbes(this);
doInit(center);
}