本文整理汇总了Java中org.eclipse.jetty.server.handler.AbstractHandler类的典型用法代码示例。如果您正苦于以下问题:Java AbstractHandler类的具体用法?Java AbstractHandler怎么用?Java AbstractHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractHandler类属于org.eclipse.jetty.server.handler包,在下文中一共展示了AbstractHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LegacyHttpServer
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
private LegacyHttpServer(int port, int threads) {
this.server = new Server(new QueuedThreadPool(threads));
server.setHandler(
new AbstractHandler() {
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException {
final String method = baseRequest.getParameter("method");
if ("helloworld.Greeter/SayHello".equals(method)) {
baseRequest.setHandled(true);
sayHello(baseRequest, response);
}
}
});
final ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
}
示例2: beforeClass
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
final String[] mainArgs = new String[] { FullyRemoteJdbcMetaFactory.class.getName() };
// Bind to '0' to pluck an ephemeral port instead of expecting a certain one to be free
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 2; i++) {
if (sb.length() > 0) {
sb.append(",");
}
HttpServer jsonServer = Main.start(mainArgs, 0, new HandlerFactory() {
@Override public AbstractHandler createHandler(Service service) {
return new AvaticaJsonHandler(service);
}
});
ACTIVE_SERVERS.add(jsonServer);
sb.append("http://localhost:").append(jsonServer.getPort());
}
url = AlternatingDriver.PREFIX + "url=" + sb.toString();
}
示例3: mockConfigServerHandler
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
private ContextHandler mockConfigServerHandler(final int statusCode, final ApolloConfig result,
final boolean failedAtFirstTime) {
ContextHandler context = new ContextHandler("/configs/*");
context.setHandler(new AbstractHandler() {
AtomicInteger counter = new AtomicInteger(0);
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
if (failedAtFirstTime && counter.incrementAndGet() == 1) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
baseRequest.setHandled(true);
return;
}
response.setContentType("application/json;charset=UTF-8");
response.setStatus(statusCode);
response.getWriter().println(gson.toJson(result));
baseRequest.setHandled(true);
}
});
return context;
}
示例4: getFileServer
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
public static Server getFileServer(ApplicationContext context) {
Resource resource = context.getResource("classpath:templates");
Server server = new Server(UrlTestingUtils.TEST_FILE_SERVER_PORT);
server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String uri = baseRequest.getRequestURI();
LOGGER.info(uri);
File file = new File(resource.getFile().getAbsolutePath() + uri);
MultipartFileSender fileSender = MultipartFileSender.fromFile(file);
try {
fileSender.with(request).with(response).serveResource();
} catch (IOException e) {
e.printStackTrace();
}
}
});
return server;
}
示例5: start
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
@Override
public void start() throws Exception {
sessionService = BeanHelper.getServiceBean(SessionService.class);
requestService = BeanHelper.getServiceBean(RequestService.class);
accountSysService = BeanHelper.getServiceBean(AccountSysService.class);
Handler entranceHandler = new AbstractHandler(){
@Override
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response) throws IOException {
fire(request,response,"EntranceJetty");
}
};
server = new Server(this.port);
server.setHandler(entranceHandler);
server.start();
}
示例6: configureHandler
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
@Override
public AbstractHandler configureHandler() throws Exception {
return new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
ServletInputStream in = req.getInputStream();
byte[] b = new byte[8192];
int count = -1;
int total = 0;
while ((count = in.read(b)) != -1) {
b = new byte[8192];
total += count;
}
resp.setStatus(200);
resp.addHeader("X-TRANFERED", String.valueOf(total));
resp.getOutputStream().flush();
resp.getOutputStream().close();
baseRequest.setHandled(true);
}
};
}
示例7: setUpGlobal
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
@BeforeClass
@Override
public void setUpGlobal() throws Exception {
port1 = findFreePort();
port2 = findFreePort();
server = newJettyHttpServer(port1);
addHttpConnector(server, port2);
HandlerList list = new HandlerList();
list.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
if (request.getLocalPort() == port2) {
httpServletResponse.sendRedirect(getTargetUrl());
}
}
});
list.addHandler(getWebSocketHandler());
server.setHandler(list);
server.start();
logger.info("Local HTTP server started successfully");
}
示例8: TestServer
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
TestServer() throws Exception {
jettyServer = new Server(0);
jettyServer.setHandler(new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (target.equals("/test-app")) {
response.sendRedirect("/test-app/");
} else if (target.equalsIgnoreCase("/test-app/slow")) {
try {
Thread.sleep(Long.parseLong(request.getParameter("millis")));
} catch (InterruptedException e) {
Thread.interrupted();
}
response.getWriter().append("This was slow");
} else {
response.setHeader("Server", "Test-Server");
response.getWriter().append("Hello from test server").close();
}
baseRequest.setHandled(true);
}
});
jettyServer.start();
int port = ((ServerConnector) jettyServer.getConnectors()[0]).getLocalPort();
url = new URL("http://localhost:" + port + "/test-app");
}
示例9: run
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
public static void run() throws Exception {
server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
target = target.substring(1);
if (isHandled(target)) {
count(target);
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println(target);
} else {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
baseRequest.setHandled(true);
}
}
});
server.start();
}
示例10: main
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
final Server server = new Server(Integer.valueOf(args[0]));
final SRLParser parser = makeParser(args[1]);
server.setHandler(new AbstractHandler() {
@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException {
final String sentence = baseRequest.getParameter("sentence");
response.setContentType("text/html; charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
doParse(parser, sentence, response.getWriter());
baseRequest.setHandled(true);
}
});
server.start();
server.join();
}
示例11: main
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// http://docs.codehaus.org/display/JETTY/Embedding+Jetty
int port = 8887;
Server server = new Server(port);
final ProxyServlet servlet = new ProxyServlet();
server.setHandler(new AbstractHandler() {
public void handle(
String target, Request baseRequest, HttpServletRequest req,
HttpServletResponse resp)
throws ServletException {
try {
servlet.service(req, resp);
} catch (IOException e) {
throw (ServletException) new ServletException().initCause(e);
}
}
});
server.start();
}
示例12: systemRestart
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
private ContextHandler systemRestart() {
AbstractHandler system = new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
restartContexts();
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>Done</h1>");
}
};
ContextHandler context = new ContextHandler();
context.setContextPath("/vraptor/restart");
context.setResourceBase(".");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.setHandler(system);
return context;
}
示例13: getMockHandler
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
/**
* Creates an {@link AbstractHandler handler} returning an arbitrary String as a response.
*
* @return never <code>null</code>.
*/
public Handler getMockHandler() {
Handler handler = new AbstractHandler() {
//@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
setRequestBody(IOUtils.toString(baseRequest.getInputStream()));
response.setStatus(getStatus());
response.setContentType(getContentType());
byte[] body = getResponseBody();
response.setContentLength(body.length);
IOUtils.write(body, response.getOutputStream());
baseRequest.setHandled(true);
}
};
return handler;
}
示例14: buildSettingsHandler
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
private Handler buildSettingsHandler() {
final String responseTemplate = "var Gobblin = window.Gobblin || {};" + "Gobblin.settings = {restServerUrl:\"%s\", hideJobsWithoutTasksByDefault:%s, refreshInterval:%s}";
return new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
if (request.getRequestURI().equals("/js/settings.js")) {
response.setContentType("application/javascript");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(String.format(responseTemplate, AdminWebServer.this.restServerUri.toString(),
AdminWebServer.this.hideJobsWithoutTasksByDefault, AdminWebServer.this.refreshInterval));
baseRequest.setHandled(true);
}
}
};
}
示例15: getHandler
import org.eclipse.jetty.server.handler.AbstractHandler; //导入依赖的package包/类
private Handler getHandler(){
AbstractHandler handler = new AbstractHandler() {
@Override
public void handle(String target, Request request, HttpServletRequest servletRequest,
HttpServletResponse response) throws IOException, ServletException {
//String url = request.getRequestURI();
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/json;charset=utf-8");
try {
BaseMessage message = MAPPER.readValue(request.getInputStream(), BaseMessage.class);
MAPPER.writeValue(response.getOutputStream(), coordinator.handle(message));
} catch (Exception ex){
ex.printStackTrace();
LOGGER.debug(ex);
Response r = new Response();
r.put("exception", ex.getMessage());
MAPPER.writeValue(response.getOutputStream(), r);
}
response.getOutputStream().close();
request.setHandled(true);
}
};
return handler;
}