本文整理汇总了Java中org.glassfish.grizzly.http.server.StaticHttpHandler类的典型用法代码示例。如果您正苦于以下问题:Java StaticHttpHandler类的具体用法?Java StaticHttpHandler怎么用?Java StaticHttpHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StaticHttpHandler类属于org.glassfish.grizzly.http.server包,在下文中一共展示了StaticHttpHandler类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的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.");
}
}
示例2: startServer
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的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);
}
}
示例3: FileHandlerProvider
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的package包/类
public FileHandlerProvider(File documentRoot, HttpHandlerPath path) {
this.path = notNull(path, "Null path").value();
try {
final File directory = notNull(documentRoot, "Document root not specified").getCanonicalFile();
if (directory.isDirectory()) {
handler = new StaticHttpHandler(directory.getAbsolutePath());
} else {
throw new IllegalArgumentException("Document root \"" + directory + "\" is not a directory");
}
} catch (IOException exception) {
throw new IllegalStateException("I/O error resolving document root \"" + documentRoot + "\"", exception);
}
}
示例4: setUp
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String httpRoot = URLDecoder.decode(new File(getClass().getResource("/").getFile()).getAbsolutePath(), "utf-8");
httpServer = HttpServer.createSimpleServer(httpRoot, "localhost", 9997);
// Disable file cache to fix https://java.net/jira/browse/GRIZZLY-1350
((StaticHttpHandler) httpServer.getServerConfiguration().getHttpHandlers().keySet().iterator().next()).setFileCacheEnabled(false);
httpServer.start();
}
示例5: start
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的package包/类
public boolean start() throws IOException {
if (!server.isPresent()) {
if (secure) {
log.debug("RestServer: Creating secure server.");
server = Optional.of(GrizzlyHttpServerFactory.createHttpServer(
getServerURI(), getResourceConfig(), true,
new SSLEngineConfigurator(sslContext.get())
.setNeedClientAuth(true).setClientMode(false)));
}
else {
log.debug("RestServer: Creating server.");
server = Optional.of(GrizzlyHttpServerFactory.createHttpServer(
getServerURI(), getResourceConfig()));
}
NetworkListener listener = server.get().getListener("grizzly");
server.get().getServerConfiguration().setMaxBufferedPostSize(server.get().getServerConfiguration().getMaxBufferedPostSize()*10);
if (staticPath.isPresent()) {
StaticHttpHandler staticHttpHandler = new StaticHttpHandler(staticPath.get());
server.get().getServerConfiguration().addHttpHandler(staticHttpHandler, relativePath.get());
if (listener != null) {
listener.getFileCache().setSecondsMaxAge(fileCacheMaxAge);
}
}
}
if (!server.get().isStarted()) {
try {
log.debug("RestServer: starting server.");
server.get().start();
} catch (IOException ex) {
log.error("Failed to start HTTP Server", ex);
throw ex;
}
}
return true;
}
示例6: loadMasterList
import org.glassfish.grizzly.http.server.StaticHttpHandler; //导入依赖的package包/类
@Test
public void loadMasterList() {
System.setProperty(CONFIG_PATH, CONFIG_DIR);
System.setProperty(DDS_CONFIG_FILE_ARGNAME, DEFAULT_DDS_FILE);
// Initialize the Spring context to load our dependencies.
SpringContext sc = SpringContext.getInstance();
ApplicationContext context = sc.initContext("src/test/resources/config/AgoleManifestReaderTest.xml");
AgoleManifestReader reader = (AgoleManifestReader) context.getBean("agoleManifestReader");
reader.setTarget("http://localhost:8401/www/master.xml");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create("http://localhost:8401"));
StaticHttpHandler staticHttpHandler = new StaticHttpHandler("src/test/resources/config/www/");
server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/www");
try {
server.start();
// Retrieve a copy of the centralized master topology list.
TopologyManifest master = reader.getManifest();
assertTrue(master != null);
System.out.println("Master id: " + master.getId() + ", version=" + master.getVersion());
// Test to see if the Netherlight entry is present.
assertTrue(master.getTopologyURL("urn:ogf:network:netherlight.net:2013:topology:a-gole:testbed") != null);
// We should not see a change in version.
master = reader.getManifestIfModified();
assertTrue(master == null);
}
catch (IOException | NotFoundException | JAXBException ex) {
System.err.println("Failed to load master topology list from: " + reader.getTarget());
ex.printStackTrace();
fail();
}
finally {
server.shutdownNow();
}
}