本文整理汇总了Java中org.glassfish.grizzly.http.server.HttpServer.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.addListener方法的具体用法?Java HttpServer.addListener怎么用?Java HttpServer.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.HttpServer
的用法示例。
在下文中一共展示了HttpServer.addListener方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: main
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) {
OSM osm = new OSM(args[0]);
if (args.length > 1 && args[1].startsWith("--load")) {
osm.intersectionDetection = true;
osm.tileIndexing = true;
if (args[1].equalsIgnoreCase("--loadurl")) {
osm.readFromUrl(args[2]);
} else {
osm.readFromFile(args[2]);
}
// TODO catch writing exceptions here and shut down properly, closing OSM database.
LOG.info("Done populating OSM database.");
osm.close();
return;
}
Thread updateThread = Updater.spawnUpdateThread(osm);
LOG.info("Starting VEX HTTP server on port {} of interface {}", PORT, BIND_ADDRESS);
HttpServer httpServer = new HttpServer();
httpServer.addListener(new NetworkListener("vanilla_extract", BIND_ADDRESS, PORT));
// Bypass Jersey etc. and add a low-level Grizzly handler.
// As in servlets, * is needed in base path to identify the "rest" of the path.
httpServer.getServerConfiguration().addHttpHandler(new VexHttpHandler(osm), "/*");
try {
httpServer.start();
LOG.info("VEX server running.");
Thread.currentThread().join();
updateThread.interrupt();
} catch (BindException be) {
LOG.error("Cannot bind to port {}. Is it already in use?", PORT);
} catch (IOException ioe) {
LOG.error("IO exception while starting server.");
} catch (InterruptedException ie) {
LOG.info("Interrupted, shutting down.");
}
httpServer.shutdown();
}
示例4: start
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
@PostConstruct
public void start() {
server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", "localhost", new PortRange(port));
server.addListener(listener);
try {
server.start();
logger.info("Test server running on {}", port);
} catch (final Throwable e) {
logger.error("Error with test server", e);
}
}
示例5: startServer
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
/**
* Starts Grizzly HTTP server exposing static content, JAX-RS resources
* and web sockets defined in this application.
*
* @param webRootPath static content root path.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer(String webRootPath)
{
final HttpServer server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", BASE_URI, PORT);
server.addListener(listener);
final ServerConfiguration config = server.getServerConfiguration();
// add handler for serving static content
config.addHttpHandler(new StaticContentHandler(webRootPath), APP_PATH);
// add handler for serving JAX-RS resources
config.addHttpHandler( RuntimeDelegate
.getInstance()
.createEndpoint(new ResourceConfig().packages("it.unito.geosummly.api"),
GrizzlyHttpContainer.class),
API_PATH
);
try {
// Start the server.
server.start();
} catch (Exception ex) {
throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
}
return server;
}
示例6: addSSL
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
private void addSSL(HttpServer httpServer) {
SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class);
if (sslProperties != null) {
httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties));
}
}
示例7: startEmbeddedServer
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
static void startEmbeddedServer() throws IOException {
// Create test web application context.
WebappContext webappContext = new WebappContext("Test Context");
webappContext
.addContextInitParameter("contextClass",
"org.springframework.web.context.support.XmlWebApplicationContext");
webappContext.addContextInitParameter("contextConfigLocation",
"classpath*:spring-context.xml");
webappContext
.addListener("org.springframework.web.context.ContextLoaderListener");
// Create a servlet registration for the web application in order to wire up Spring managed collaborators to Jersey resources.
ServletRegistration servletRegistration = webappContext.addServlet(
"jersey-servlet", ServletContainer.class);
// The logging filters for server logging.
servletRegistration
.setInitParameter(
"com.sun.jersey.spi.container.ContainerResponseFilters",
"com.sun.jersey.api.container.filter.LoggingFilter");
servletRegistration.setInitParameter(
"com.sun.jersey.spi.container.ContainerRequestFilters",
"com.sun.jersey.api.container.filter.LoggingFilter");
servletRegistration.setInitParameter("javax.ws.rs.Application",
"com.test.MyDemoApplication");
servletRegistration.setInitParameter(
"com.sun.jersey.config.property.packages", "com.test");
servletRegistration.setInitParameter(
"com.sun.jersey.api.json.POJOMappingFeature", "true");
servletRegistration.addMapping("/*");
HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2", "localhost",
3388);
server.addListener(listener);
webappContext.deploy(server);
try {
server.start();
System.out.println("Press enter to stop the server...");
System.in.read();
} finally {
server.shutdownNow();
}
}
示例8: Server
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
public Server(PropertiesConfiguration properties) throws IOException {
m_properties = properties;
m_httpServer = new HttpServer();
int port = properties.getInt(PROPERTY_PORT, DEFAULT_PORT);
String host = properties.getString(PROPERTY_HOST, DEFAULT_HOST);
final NetworkListener networkListener = new NetworkListener(
NET_LISTENER_NAME,
host,
port);
// Enable SSL on the listener
networkListener.setSecure(true);
networkListener.setSSLEngineConfig(makeSSLConfig(m_properties));
CompressionConfig compressionConfig =
networkListener.getCompressionConfig();
compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); // the mode
compressionConfig.setCompressionMinSize(100); // the min amount of bytes to compress
compressionConfig.setCompressableMimeTypes("text/plain", "text/html", "application/x-protobuf", "application/pdf"); // the mime types to compress
m_httpServer.addListener(networkListener);
// Create a concurrent, nonblocking, asynchronous, batching JPA-based store for persistence
// of request data. Async is OK, as persistence failures do not need to be handled by the client.
m_store = new JPABatchStore(ConfigurationConverter.getMap(m_properties));
m_batchPersister = new AsyncConcurrentBatchingProcessor<PersistEntityEvent>(
m_store,
PersistEntityEvent::new,
PersistEntityEvent::translate
);
final ServerConfiguration config = m_httpServer.getServerConfiguration();
config.setMaxPostSize(MAX_POST_SIZE);
AsyncPostHandler.ErrorHandler errorHandler =
(ByteBuffer postBytes, Response resp, Throwable t) -> {
LogManager.getLogger(this).warn("Invalid submission.", t);
resp.sendError(300);
resp.finish();
};
AsyncPostHandler certHandler =
new AsyncPostHandler(new CertificateHandler(m_batchPersister, CERT_TEMPLATE_PATH, errorHandler),
errorHandler);
AsyncPostHandler versionHandler =
new AsyncPostHandler(new VersionCheckHandler(m_batchPersister, properties), errorHandler);
config.addHttpHandler(certHandler, PATH_SUBMIT);
config.addHttpHandler(versionHandler, PATH_VERSION_CHECK);
}
示例9: createServer
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
private HttpServer createServer(URI uri, ResourceConfig configuration) {
GrizzlyHttpContainer handler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, configuration);
boolean secure = false;
SSLEngineConfigurator sslEngineConfigurator = null;
boolean start = false;
final String host = (uri.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST
: uri.getHost();
final int port = (uri.getPort() == -1) ? 80 : uri.getPort();
final HttpServer server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", host, port);
listener.setSecure(secure);
if (sslEngineConfigurator != null) {
listener.setSSLEngineConfig(sslEngineConfigurator);
}
// insert
// listener.
CompressionConfig cg = listener.getCompressionConfig();
cg.setCompressionMode(CompressionConfig.CompressionMode.ON);
// cg.setCompressableMimeTypes("text","application/json");
// end insert
server.addListener(listener);
// Map the path to the processor.
final ServerConfiguration config = server.getServerConfiguration();
if (handler != null) {
config.addHttpHandler(handler, uri.getPath());
}
config.setPassTraceRequest(true);
if (start) {
try {
// Start the server.
server.start();
} catch (IOException ex) {
throw new ProcessingException("IOException thrown when trying to start grizzly server", ex);
}
}
return server;
}
示例10: execute
import org.glassfish.grizzly.http.server.HttpServer; //导入方法依赖的package包/类
public void execute() throws MojoExecutionException, MojoFailureException {
HttpServer server = new HttpServer();
final String mainDir = rootDir + SystemUtils.FILE_SEPARATOR + "gatf-config-tool";
InputStream resourcesIS = GatfConfigToolMojo.class.getResourceAsStream("/gatf-config-tool.zip");
if (resourcesIS != null)
{
ReportHandler.unzipZipFile(resourcesIS, rootDir);
}
final GatfConfigToolMojo mojo = this;
createConfigFileIfNotExists(mojo, true, null);
createConfigFileIfNotExists(mojo, false, null);
createServerApiAndIssueTrackingApiFilesIfNotExists();
server.addListener(new NetworkListener("ConfigServer", ipAddress, port));
handleRootContext(server, mainDir, mojo);
server.getServerConfiguration().addHttpHandler(new GatfConfigurationHandler(mojo, project), "/configure");
server.getServerConfiguration().addHttpHandler(new GatfReportsHandler(mojo, project), "/reports");
server.getServerConfiguration().addHttpHandler(new GatfMiscHandler(mojo), "/misc");
server.getServerConfiguration().addHttpHandler(new GatfTestCaseFilesHandler(mojo), "/testcasefiles");
server.getServerConfiguration().addHttpHandler(new GatfTestCaseHandler(mojo), "/testcases");
server.getServerConfiguration().addHttpHandler(new GatfPluginExecutionHandler(mojo, project), "/execute");
server.getServerConfiguration().addHttpHandler(new GatfProfileHandler(mojo, project), "/profile");
try {
server.start();
System.out.println("Press any key to stop the server...");
System.in.read();
} catch (Exception e) {
System.err.println(e);
}
}