當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServer類代碼示例

本文整理匯總了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;
}
 
開發者ID:bcdev,項目名稱:esa-pfa,代碼行數:24,代碼來源:ServerMain.java

示例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;
}
 
開發者ID:IBMStreams,項目名稱:streamsx.jmxclients,代碼行數:26,代碼來源:RestServer.java

示例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;
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:20,代碼來源:WebServiceClientHelper.java

示例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);
    }
}
 
開發者ID:gomgomdev,項目名稱:telegram-bot_misebot,代碼行數:23,代碼來源:Webhook.java

示例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()));
    }
}
 
開發者ID:YMonnier,項目名稱:docker-restful-java,代碼行數:27,代碼來源:Main.java

示例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();
}
 
開發者ID:Fiware,項目名稱:NGSI-LD_Wrapper,代碼行數:21,代碼來源:Main.java

示例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);
    }
}
 
開發者ID:samurayrj,項目名稱:rubenlagus-TelegramBots,代碼行數:26,代碼來源:DefaultWebhook.java

示例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.");
    }
}
 
開發者ID:admiral0,項目名稱:MinecraftSolder,代碼行數:30,代碼來源:MinecraftSolder.java

示例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);
  }
}
 
開發者ID:DataRPM-Labs,項目名稱:sigma-events,代碼行數:30,代碼來源:EventEngineAPIServiceStarter.java

示例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;
}
 
開發者ID:n1try,項目名稱:http-server-benchmarks,代碼行數:22,代碼來源:Main.java

示例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);
    }
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:17,代碼來源:RESTServer.java

示例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;
}
 
開發者ID:shilongdai,項目名稱:LSChatServer,代碼行數:23,代碼來源:ApplicationRootContext.java

示例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());
}
 
開發者ID:coding4people,項目名稱:mosquito-report-api,代碼行數:25,代碼來源:MainTest.java

示例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!");
    }
  }
}
 
開發者ID:HuygensING,項目名稱:antioch,代碼行數:24,代碼來源:Server.java

示例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);
	}
 
開發者ID:coderczp,項目名稱:HtmlSocket,代碼行數:19,代碼來源:PullServer.java


注:本文中的org.glassfish.grizzly.http.server.HttpServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。