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


Java Request.setHandled方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.Request.setHandled方法的典型用法代码示例。如果您正苦于以下问题:Java Request.setHandled方法的具体用法?Java Request.setHandled怎么用?Java Request.setHandled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.Request的用法示例。


在下文中一共展示了Request.setHandled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
	// RPC调用
       RpcResponse rpcResponse = doInvoke(request);

       // 序列化响应结果
       byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
	
	response.setContentType("text/html;charset=utf-8");
	response.setStatus(HttpServletResponse.SC_OK);
	baseRequest.setHandled(true);
	
	OutputStream out = response.getOutputStream();
	out.write(responseBytes);
	out.flush();
	
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:18,代码来源:JettyServerHandler.java

示例2: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
	
	// invoke
       RpcResponse rpcResponse = doInvoke(request);

       // serialize response
       byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
	
	response.setContentType("text/html;charset=utf-8");
	response.setStatus(HttpServletResponse.SC_OK);
	baseRequest.setHandled(true);
	
	OutputStream out = response.getOutputStream();
	out.write(responseBytes);
	out.flush();
	
}
 
开发者ID:mmwhd,项目名称:stage-job,代码行数:19,代码来源:JettyServerHandler.java

示例3: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
public void handle(String target,
                   Request baseRequest,
                   HttpServletRequest request,
                   HttpServletResponse response) throws IOException, ServletException {
    String header = request.getHeader("Authorization");
    if(header == null || !header.equals(authenticationHeader)) {
        response.addHeader("WWW-Authenticate", "Basic");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        response.setContentType("text/plain; charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("Login to access API");

        baseRequest.setHandled(true);
    }
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:17,代码来源:AuthorizationHandler.java

示例4: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
public void handle(String target,
                   Request baseRequest,
                   HttpServletRequest request,
                   HttpServletResponse response) throws IOException, ServletException {
    if(baseRequest.getMethod().equals("OPTIONS")) {

        response.setStatus(HttpServletResponse.SC_OK);
        response.setHeader("Access-Control-Allow-Origin", "*");

        String methods = "POST, OPTIONS";
        if(allowGet) methods += ", GET";
        response.setHeader("Access-Control-Allow-Methods", methods);
        response.setHeader("Access-Control-Max-Age", "1000");
        String req = request.getHeader("Access-Control-Request-Headers");
        if(req != null) {
            response.setHeader("Access-Control-Allow-Headers", req);
        }

        baseRequest.setHandled(true);
    }
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:22,代码来源:AjaxHandler.java

示例5: isUserPermitted

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
/**
 * Determines if a request is permitted to be executed. The server may require authentication
 * and the login mechanism might have failed. This check verifies that only authenticated
 * users are permitted through when the server is requiring authentication. When a user
 * is disallowed, a status code and response will be automatically written to the provided
 * <code>response</code> and the caller should return immediately.
 *
 * @param serverConfig The server's configuration
 * @param request The user's request
 * @param response The response to the user's request
 * @return True if request can proceed, false otherwise.
 */
public boolean isUserPermitted(AvaticaServerConfiguration serverConfig, Request baseRequest,
    HttpServletRequest request, HttpServletResponse response) throws IOException {
  // Make sure that we drop any unauthenticated users out first.
  if (null != serverConfig) {
    if (AuthenticationType.SPNEGO == serverConfig.getAuthenticationType()) {
      String remoteUser = request.getRemoteUser();
      if (null == remoteUser) {
        response.setStatus(HttpURLConnection.HTTP_UNAUTHORIZED);
        response.getOutputStream().write(UNAUTHORIZED_ERROR.serialize().toByteArray());
        baseRequest.setHandled(true);
        return false;
      }
    }
  }

  return true;
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:30,代码来源:AbstractAvaticaHandler.java

示例6: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
                   final HttpServletResponse response) throws IOException, ServletException {

    final String[] parts = target.split("/");
    final String lastPart = parts[parts.length - 1];
    final int statusCode = Integer.parseInt(lastPart);

    response.setStatus(statusCode);
    baseRequest.setHandled(true);

}
 
开发者ID:galop-proxy,项目名称:galop,代码行数:13,代码来源:StatusCodeHandler.java

示例7: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
                   final HttpServletResponse response) throws IOException, ServletException {

    final String result = formatRequestLine(baseRequest) + formatRequestHeader(baseRequest);

    setHeader(response);
    setMessageBody(response, result);
    baseRequest.setHandled(true);

}
 
开发者ID:galop-proxy,项目名称:galop,代码行数:12,代码来源:RequestHandler.java

示例8: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
                   final HttpServletResponse response) throws IOException, ServletException {

    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader("transfer-encoding", "lorem, ipsum, chunked");
    baseRequest.setContentType("image/png");

    final OutputStream outputStream = response.getOutputStream();
    outputStream.write(image);
    outputStream.flush();

    baseRequest.setHandled(true);

}
 
开发者ID:galop-proxy,项目名称:galop,代码行数:16,代码来源:ChunkedHandler.java

示例9: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(
    String target,
    Request request,
    HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletResponse)
    throws IOException, ServletException {
  if ("/graphql".equals(target)) {
    request.setHandled(true);
    Map<String, Object> json = readJson(httpServletRequest);
    String query = (String) json.get("query");
    if (query == null) {
      httpServletResponse.setStatus(400);
      return;
    }
    String operationName = (String) json.get("operationName");
    Map<String, Object> variables = getVariables(json.get("variables"));

    ExecutionInput executionInput =
        ExecutionInput.newExecutionInput()
            .query(query)
            .operationName(operationName)
            .variables(variables)
            .context(new Object())
            .build();
    ExecutionResult executionResult = GRAPHQL.execute(executionInput);
    httpServletResponse.setContentType("application/json");
    httpServletResponse.setStatus(HttpServletResponse.SC_OK);
    GSON.toJson(executionResult.toSpecification(), httpServletResponse.getWriter());
  }
}
 
开发者ID:google,项目名称:rejoiner,代码行数:32,代码来源:GraphQlServer.java

示例10: writeResponse

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
private void writeResponse(Request baseRequest, HttpServletResponse response, Object data) throws IOException{
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json; charset=utf-8");

    String origin = baseRequest.getHeader("Origin");
    if(origin != null) {
        response.setHeader("Access-Control-Allow-Origin", origin);
    }

    PrintWriter out = response.getWriter();
    out.println(jparser.toJson(data));
    baseRequest.setHandled(true);
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:14,代码来源:BaseHandler.java

示例11: writeError

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
private void writeError(Request baseRequest, HttpServletResponse response, String message) throws IOException{
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.setContentType("application/json; charset=utf-8");
    ErrorResponse resp = new ErrorResponse();
    resp.errorMessage = message;
    PrintWriter out = response.getWriter();
    out.println(jparser.toJson(resp));
    baseRequest.setHandled(true);
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:10,代码来源:BaseHandler.java

示例12: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override public void handle(String target, Request baseRequest, HttpServletRequest request,
    HttpServletResponse response) throws IOException, ServletException {
  Authentication auth = baseRequest.getAuthentication();
  if (Authentication.UNAUTHENTICATED == auth) {
    throw new AssertionError("Unauthenticated users should not reach here!");
  }

  baseRequest.setHandled(true);
  UserAuthentication userAuth = (UserAuthentication) auth;
  UserIdentity userIdentity = userAuth.getUserIdentity();
  Principal userPrincipal = userIdentity.getUserPrincipal();

  response.getWriter().print("OK " + userPrincipal.getName());
  response.setStatus(200);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:16,代码来源:SpnegoTestUtil.java

示例13: handle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (!target.equals("/metrics")) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    tps.set(exporter.getAverageTPS());

    /*
    * Bukkit API calls have to be made from the main thread.
    * That's why we use the BukkitScheduler to retrieve the server stats.
    * */
    Future<Object> future = exporter.getServer().getScheduler().callSyncMethod(exporter, new Callable<Object>() {
        public Object call() throws Exception {
            players.labels("online").set(Bukkit.getOnlinePlayers().size());
            players.labels("offline").set(Bukkit.getOfflinePlayers().length);

            for (World world : Bukkit.getWorlds()) {
                loadedChunks.labels(world.getName()).set(world.getLoadedChunks().length);
                playersOnline.labels(world.getName()).set(world.getPlayers().size());
                entities.labels(world.getName()).set(world.getEntities().size());
                livingEntities.labels(world.getName()).set(world.getLivingEntities().size());
            }

            memory.labels("max").set(Runtime.getRuntime().maxMemory());
            memory.labels("free").set(Runtime.getRuntime().freeMemory());

            return null;
        }
    });

    try {
        future.get();

        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType(TextFormat.CONTENT_TYPE_004);

        TextFormat.write004(response.getWriter(), CollectorRegistry.defaultRegistry.metricFamilySamples());

        baseRequest.setHandled(true);
    } catch (InterruptedException | ExecutionException e) {
        exporter.getLogger().warning("Failed to read server statistics");
        e.printStackTrace();
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
开发者ID:sladkoff,项目名称:minecraft-prometheus-exporter,代码行数:49,代码来源:MetricsController.java

示例14: doNonErrorHandle

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
@Override
protected void doNonErrorHandle(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    jettyRequest.setHandled(true);
    service(target, jettyRequest, request, response);
}
 
开发者ID:jetty-project,项目名称:jetty-reactive-httpclient,代码行数:6,代码来源:EmptyHandler.java

示例15: setUp

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
/**
 * Set up server with handler
 *
 * @param handler
 * @return port
 * @throws Exception
 */
public static String setUp(final Handler handler) throws Exception {
  server = new Server();
  if (handler != null)
    server.setHandler(handler);
  Connector connector = new SelectChannelConnector();
  connector.setPort(0);
  server.setConnectors(new Connector[] { connector });
  server.start();

  proxy = new Server();
  Connector proxyConnector = new SelectChannelConnector();
  proxyConnector.setPort(0);
  proxy.setConnectors(new Connector[] { proxyConnector });

  ServletHandler proxyHandler = new ServletHandler();

  RequestHandler proxyCountingHandler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      proxyHitCount.incrementAndGet();
      String auth = request.getHeader("Proxy-Authorization");
      auth = auth.substring(auth.indexOf(' ') + 1);
      try {
        auth = B64Code.decode(auth, CHARSET_UTF8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      int colon = auth.indexOf(':');
      proxyUser.set(auth.substring(0, colon));
      proxyPassword.set(auth.substring(colon + 1));
      request.setHandled(false);
    }
  };

  HandlerList handlerList = new HandlerList();
  handlerList.addHandler(proxyCountingHandler);
  handlerList.addHandler(proxyHandler);
  proxy.setHandler(handlerList);

  ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
  proxyHolder.setAsyncSupported(true);

  proxy.start();

  proxyPort = proxyConnector.getLocalPort();

  return "http://localhost:" + connector.getLocalPort();
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:57,代码来源:ServerTestCase.java


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