本文整理汇总了Java中org.glassfish.grizzly.http.server.HttpHandler类的典型用法代码示例。如果您正苦于以下问题:Java HttpHandler类的具体用法?Java HttpHandler怎么用?Java HttpHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpHandler类属于org.glassfish.grizzly.http.server包,在下文中一共展示了HttpHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebServer
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
public WebServer(URI endpoint) throws IOException {
this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
rspns.getWriter().write("404: not found");
}
});
WebappContext context = new WebappContext("WebappContext", BASE_PATH);
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
StringJoiner sj = new StringJoiner(",");
for (String s : PACKAGES) {
sj.add(s);
}
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
registration.addMapping(BASE_PATH);
context.deploy(server);
}
示例2: startManagementHttpServer
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
private void startManagementHttpServer() throws Exception {
final String httpManagementServerUrl = _properties.getProperty("managementurl", HTTP_MANAGEMENTSERVER_URL);
final ResourceConfig config = new ResourceConfig().register(RaqetService.class).register(new RaqetBinder(_raqetControll));
final CLStaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(this.getClass().getClassLoader(), "/static/");
_httpManagementServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(httpManagementServerUrl), config);
_httpManagementServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/gui/");
/* Redirect users to the GUI */
_httpManagementServer.getServerConfiguration().addHttpHandler(new HttpHandler() {
@Override
public void service(final Request request, final Response response) throws Exception {
response.sendRedirect("/gui/");
}
}, "/index.html");
_httpManagementServer.start();
}
示例3: onMessage
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Override
public void onMessage(BlaubotMessage blaubotMessage) {
eu.hgross.blaubot.blaubotcam.server.model.ImageMessage imageMessage = new eu.hgross.blaubot.blaubotcam.server.model.ImageMessage(blaubotMessage.getPayload());
final String uniqueDeviceId = imageMessage.getUniqueDeviceId();
CamDevice camDevice = mCamDevices.get(uniqueDeviceId);
final boolean added;
if (camDevice == null) {
added = mCamDevices.putIfAbsent(uniqueDeviceId, new CamDevice(uniqueDeviceId)) == null;
} else {
added = false;
}
camDevice = mCamDevices.get(uniqueDeviceId);
camDevice.putImageMessage(imageMessage);
if (added) {
// add the handler to the server
HttpHandler httpHandler = new LiveVideoHttpHandler(camDevice);
final String encodedDeviceId = EncodingUtil.encodeURIComponent(camDevice.getDeviceId());
final String mjpegUri = URI_PATTERN.replace(URI_PATTERN_PARAM_ID, encodedDeviceId);
final String singleJpegUri = URI_PATTERN.replace(URI_PATTERN_PARAM_ID, encodedDeviceId) + URI_ENDING_SINGLE_IMAGE;
server.getServerConfiguration().addHttpHandler(httpHandler, mjpegUri, singleJpegUri);
}
}
示例4: startServer
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
public <T extends DaggerServletContextListener> void startServer(Class<T> listenerClass) {
LOGGER.info("Starting test server");
WebappContext context = new WebappContext("Test", getUri().getRawPath());
context.addListener(listenerClass);
daggerFilter = new DaggerFilter();
FilterRegistration filterRegistration = context.addFilter("daggerFilter", daggerFilter);
filterRegistration.addMappingForUrlPatterns(null, "/*");
ServletRegistration servletRegistration = context.addServlet("TestServlet", new HttpServlet() {
});
servletRegistration.addMapping("/dagger-jersey/*");
try {
httpServer = GrizzlyServerFactory.createHttpServer(getUri(), (HttpHandler) null);
context.deploy(httpServer);
httpServer.start();
LOGGER.info("Test server started");
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
示例5: addHandler
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
public void addHandler(final String data, final String path) {
final HttpHandler httpHandler = new HttpHandler() {
@Override
public void service(final Request request, final Response response)
throws Exception {
response.getWriter().write(data);
}
};
server.getServerConfiguration().addHttpHandler(httpHandler, "/" + path);
}
示例6: configureHttpServer
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
private void configureHttpServer() {
NetworkListener listener = new NetworkListener(config.getName(), config.getServerHost(), config.getServerPort());
httpServer.addListener(listener);
httpServer.getServerConfiguration().addHttpHandler(new HttpHandler() {
@Override
public void service(Request request, Response response) throws Exception {
response.suspend();
rootActor.tell(new GrizzlyHTTPRequest(request, response), ActorRef.noSender());
}
});
}
示例7: handleRootContext
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
private void handleRootContext(HttpServer server, final String mainDir, final GatfConfigToolMojo mojo) {
server.getServerConfiguration().addHttpHandler(
new HttpHandler() {
public void service(Request request, Response response) throws Exception {
new CacheLessStaticHttpHandler(mainDir).service(request, response);
}
}, "/");
server.getServerConfiguration().addHttpHandler(new GatfProjectZipHandler(mojo), "/projectZip");
}
示例8: get
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Override
protected HttpHandler get(Injector injector, Configurations configurations) {
/* Setup our object mapper (could be qualified with path) */
final ObjectMapper mapper = getInstance(injector, ObjectMapper.class, path);
final Map<Class<?>, Integer> contractPriorities = new HashMap<>();
contractPriorities.put(MessageBodyWriter.class, Integer.MIN_VALUE);
contractPriorities.put(MessageBodyReader.class, Integer.MIN_VALUE);
config.register(new JacksonJsonProvider(mapper,
new Annotations[] { Annotations.JACKSON, Annotations.JAXB }),
Collections.unmodifiableMap(contractPriorities));
/* Create a ServiceLocator parent of all locators and inject the configurations */
final ServiceLocator locator = ServiceLocatorFactory.create(injector, path);
/* Set up the ObjectMapper that will be used by this application */
ServiceLocatorUtilities.addOneConstant(locator, mapper, null, ObjectMapper.class);
/* Create a brand new Grizzly HTTP container from Jersey */
log.debug("Jersey application at \"%s\" initializing", path.value());
GrizzlyHttpContainer container = GrizzlyHttpContainerFactory.create(config, locator);
log.info("Jersey application at \"%s\" initialized successfully", path.value());
/* Create our handler and add it to our server configuration */
final HttpServer server = injector.getInstance(HttpServer.class);
server.getServerConfiguration().addHttpHandler(container, path.value());
log.info("Serving \"%s\" using Jersey application \"%s\"", path.value(), config.getApplicationName());
/* All done! */
return container;
}
示例9: setup
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Inject
private void setup(Injector injector, HttpServer server) {
final HttpHandler httpHandler;
if (handler == null) {
httpHandler = injector.getInstance(key);
} else {
injector.injectMembers(handler);
httpHandler = handler;
}
server.getServerConfiguration().addHttpHandler(httpHandler, path);
log.info("Serving \"%s\" using handler %s", path, httpHandler.getClass().getName());
}
示例10: publishService
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Override
public void publishService(SoapWebService soapWebService) {
String path = transportInfo.getBasePath() + soapWebService.getServicePath();
log.info("Publishing soap web service "+soapWebService.getClass().getName()+" as: " + transportInfo.toUriString() + soapWebService.getServicePath() + "?wsdl");
HttpHandler jaxwsHandler = new JaxwsHandler(soapWebService, false);
httpServer.getServerConfiguration().addHttpHandler(jaxwsHandler,
//see https://java.net/projects/grizzly/lists/users/archive/2014-11/message/7 for why this is done.
HttpHandlerRegistration.bulder()
.contextPath(path)
.urlPattern("")
.build());
}
示例11: createContainer
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Override
public <T> T createContainer(Class<T> type, Application application) throws ProcessingException {
if (HttpHandler.class == type || GrizzlyHttpContainer.class == type) {
return type.cast(new GrizzlyHttpContainer(application));
}
return null;
}
示例12: init
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
public void init(String[] context) {
logger.trace("Init-ing DiscoDJ");
DiscoDjContainerLifecycleListener lifecycleListener = new DiscoDjContainerLifecycleListener();
ResourceConfig rc = new ResourceConfig();
rc.packages("com.totalchange.discodj.ws");
rc.register(lifecycleListener);
server = GrizzlyHttpServerFactory.createHttpServer(
URI.create("http://0.0.0.0:58008/discodj/resources/api"), rc);
HttpHandler mediaHandler = lifecycleListener.getInjector().getInstance(
DiscoDjMediaHttpHandler.class);
server.getServerConfiguration().addHttpHandler(mediaHandler,
"/discodj/resources/media");
}
示例13: addHandler
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
public void addHandler(HttpHandler handler, String url) {
sercfg.addHttpHandler(handler, url);
}
示例14: addHandler
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
private void addHandler(HttpHandlerPath path, Provider<HttpHandler> provider) {
binder().bind(HttpHandler.class)
.annotatedWith(path)
.toProvider(provider)
.asEagerSingleton();
}
示例15: get
import org.glassfish.grizzly.http.server.HttpHandler; //导入依赖的package包/类
@Override
public HttpHandler get() {
return handler;
}