当前位置: 首页>>代码示例>>Java>>正文


Java AbstractHandler类代码示例

本文整理汇总了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);
}
 
开发者ID:codahale,项目名称:grpc-proxy,代码行数:24,代码来源:LegacyHttpServer.java

示例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();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:AlternatingRemoteMetaTest.java

示例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;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:24,代码来源:ConfigIntegrationTest.java

示例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;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:23,代码来源:UrlTestingUtils.java

示例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();
}
 
开发者ID:xuerong,项目名称:MMServerEngine,代码行数:19,代码来源:PlayerRequestJettyEntrance.java

示例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);
        }
    };
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:25,代码来源:FilePartLargeFileTest.java

示例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");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:25,代码来源:RedirectTest.java

示例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");
}
 
开发者ID:danielflower,项目名称:app-runner,代码行数:27,代码来源:WebServerTest.java

示例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();
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:20,代码来源:Counter.java

示例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();
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:19,代码来源:WebDemo.java

示例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();
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:ProxyServletMain.java

示例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;
}
 
开发者ID:caelum,项目名称:mamute,代码行数:21,代码来源:VRaptorServer.java

示例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;
}
 
开发者ID:smartsheet-platform,项目名称:smartsheet-java-sdk,代码行数:28,代码来源:HttpTestServer.java

示例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);
      }
    }
  };
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:18,代码来源:AdminWebServer.java

示例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;
}
 
开发者ID:edwardcapriolo,项目名称:nibiru,代码行数:27,代码来源:HttpJsonTransport.java


注:本文中的org.eclipse.jetty.server.handler.AbstractHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。