org.glassfish.grizzly.http.server.Request类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中org.glassfish.grizzly.http.server.Request类的一些代码示例,展示了Request类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request类的具体详情如下:
包路径:org.glassfish.grizzly.http.server.Request
类名称:Request

Request介绍

[英]Wrapper object for the Coyote request.
[中]Coyote请求的包装器对象。

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

String[] pathComponents = request.getPathInfo().split("/");
  if (request.getMethod() == Method.HEAD) {
    mapper.readTree(request.getInputStream());
  } else if (request.getMethod() == Method.GET && "status".equals(pathComponents[1])) {
  } else if (request.getMethod() == Method.POST) {
      request.getRequest().getConnection()
          .addCloseListener((closeable, iCloseType) -> {
            broker.removeSuspendedResponse(graphAffinity, response);
        AnalystClusterRequest task = mapper.readValue(request.getInputStream(),
            AnalystClusterRequest.class);
        broker.enqueuePriorityTask(task, response);
        request.getRequest().getConnection()
            .addCloseListener((closeable, iCloseType) -> {
              broker.deletePriorityTask(task.taskId);
            .readValue(request.getInputStream(),
                new TypeReference<List<AnalystClusterRequest>>() {
                });
        ByteStreams.copy(request.getInputStream(),
      request.getRequest().getConnection().addCloseListener((c, i) -> {

代码示例来源:origin: opentripplanner/OpenTripPlanner

public OTPRequest (Request req, Graph graph) {
  this.graph = graph;
  for (String key : req.getParameterNames()) {
    params.put(key, req.getParameter(key));
  }
  String path = req.getPathInfo();
  sfmt = SerializeFormat.JSON;
  if (req.getHeader("Accept").contains("application/xml")) {
    sfmt = SerializeFormat.XML;
  }
  if (req.getHeader("Accept").contains("application/json")) {
    sfmt = SerializeFormat.JSON;
  }
  if (path.endsWith(".xml")) {
    path = path.substring(0, path.length() - 4);
    sfmt = SerializeFormat.XML;
  };
  if (path.endsWith(".json")) {
    path = path.substring(0, path.length() - 5);
    sfmt = SerializeFormat.JSON;
  };
  parts = path.split("/");
  // path always begins with a slash, so part 0 is empty
  if (parts.length > 1) action = parts[1];
  if (parts.length > 2) id = parts[2];
}

代码示例来源:origin: jersey/jersey

@Override
public void service(Request request, Response response) throws Exception {
  String uri = request.getRequestURI();
    response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
    return;
  final String resourcesContextPath = request.getContextPath();
  System.out.println("context: " + resourcesContextPath);
  if (resourcesContextPath != null && !resourcesContextPath.isEmpty()) {
    if (!uri.startsWith(resourcesContextPath)) {
      response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
      return;
    response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
  } else {
    response.setStatus(HttpStatus.OK_200);

代码示例来源:origin: jersey/jersey

private String getServerAddress(final Request request) throws URISyntaxException {
  return new URI(request.getScheme(), null,  request.getServerName(), request.getServerPort(), null, null, null).toString();
}

代码示例来源:origin: Graylog2/graylog2-server

/**
 * If X-Forwarded-For request header is set, and the request came from a trusted source,
 * return the value of X-Forwarded-For. Otherwise return {@link Request#getRemoteAddr()}.
 */
public static String getRemoteAddrFromRequest(Request request, Set<IpSubnet> trustedSubnets) {
  final String remoteAddr = request.getRemoteAddr();
  final String XForwardedFor = request.getHeader("X-Forwarded-For");
  if (XForwardedFor != null) {
    for (IpSubnet s : trustedSubnets) {
      try {
        if (s.contains(remoteAddr)) {
          // Request came from trusted source, trust X-Forwarded-For and return it
          return XForwardedFor;
        }
      } catch (UnknownHostException e) {
        // ignore silently, probably not worth logging
      }
    }
  }
  // Request did not come from a trusted source, or the X-Forwarded-For header was not set
  return remoteAddr;
}

代码示例来源:origin: javaee/grizzly

request.setRequestExecutorProvider(getRequestExecutorProvider());
request.setSessionCookieName(getSessionCookieName());
request.setSessionManager(getSessionManager(request));
response.setErrorPageGenerator(getErrorPageGenerator(request));
if (request.requiresAcknowledgement()) {
  if (!sendAcknowledgment(request, response)) {
    return true;
  final HttpRequestPacket httpRequestPacket = request.getRequest();
  final RequestURIRef requestURIRef = httpRequestPacket.getRequestURIRef();
  requestURIRef.setDefaultURIEncoding(requestURIEncoding);
      requestURIRef.getDecodedRequestURIBC(allowEncodedSlash);
    } catch (CharConversionException e) {
      response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
      response.setDetailMessage("Invalid URI: " + e.getMessage());
      return true;
  response.getResponse().setAllowCustomReasonPhrase(
      allowCustomStatusMessage);
  request.parseSessionId();
  return runService(request, response);

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

public static void writeTraceMessage(final Request request,
    final Response response) throws IOException {
  response.setStatus(HttpStatus.OK_200);
  response.setContentType("message/http");
  final Writer writer = response.getWriter();
  writer.append(request.getMethod().toString()).append(' ')
      .append(request.getRequest().getRequestURIRef().getOriginalRequestURIBC().toString())
      .append(' ').append(request.getProtocol().getProtocolString())
      .append("\r\n");
  for (String headerName : request.getHeaderNames()) {
    for (String headerValue : request.getHeaders(headerName)) {
      writer.append(headerName).append(": ").append(headerValue).append("\r\n");
    }
  }
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server-core

throws IOException {
final HttpContext context = request.getRequest()
    .getProcessingState().getHttpContext();
response.finish();
request.onAfterService();
final HttpRequestPacket httpRequest = request.getRequest();
final boolean isBroken = httpRequest.isContentBroken();
  response.recycle();
  request.recycle();
  final NextAction suspendNextAction = ctx.getSuspendAction();
  ctx.completeAndRecycle();
  return suspendNextAction;
return ctx.getStopAction();

代码示例来源:origin: javaee/grizzly

@Override
public String resolve(final Request request) {
  try {
    final RequestURIRef uriRef = request.getRequest().getRequestURIRef();
    uriRef.setDefaultURIEncoding(httpHandler.getRequestURIEncoding());
    final DataChunk decodedURI = uriRef.getDecodedRequestURIBC(
        httpHandler.isAllowEncodedSlash());
    
    final int pos = decodedURI.indexOf(';', 0);
    return pos < 0 ? decodedURI.toString() : decodedURI.toString(0, pos);
  } catch (CharConversionException e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: eclipse-ee4j/tyrus

@Override
  public void service(Request request, Response response) throws Exception {
    if (request.getMethod().equals(Method.GET) && request.getRequestURI().endsWith("application.wsadl")) {
      getWsadlJaxbContext().createMarshaller().marshal(engine.getWsadlApplication(), response.getWriter());
      response.setStatus(200);
      response.setContentType(ContentType.newContentType("application/wsadl+xml"));
      return;
    }
    if (staticHttpHandler != null) {
      staticHttpHandler.service(request, response);
    } else {
      response.sendError(404);
    }
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

if (!response.getRequest().getRequest().getConnection().isOpen()) {
  LOG.debug("Consumer connection was closed. It will be removed.");
  return false;
  response.setStatus(HttpStatus.OK_200);
  OutputStream out = response.getOutputStream();
  mapper.writeValue(out, tasks);
  response.resume();

代码示例来源:origin: javaee/grizzly

boolean doHandle(final Request request, final Response response)
    throws Exception {
  response.setErrorPageGenerator(getErrorPageGenerator(request));
      final HttpHandler rh = rootHttpHandlerLocal.httpHandler;
      rootHttpHandlerLocal.pathUpdater.update(this, rh, request);
      return rh.doHandle(request, response);
    final RequestURIRef uriRef = request.getRequest().getRequestURIRef();
    uriRef.setDefaultURIEncoding(getRequestURIEncoding());
    final DataChunk decodedURI = uriRef.getDecodedRequestURIBC(
        isAllowEncodedSlash());
    final MappingData mappingData = request.obtainMappingData();
    mapper.mapUriWithSemicolon(request.getRequest(),
                  decodedURI,
                  mappingData,
      return httpHandler.doHandle(request, response);
    } else {
      response.sendError(404);
      response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Internal server error", t);

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

private boolean checkChunkedMaxPostSize() {
    if (serverRequest.getRequest().isChunked()) {
      final long maxPostSize = serverRequest.getHttpFilter().getConfiguration().getMaxPostSize();
      return maxPostSize < 0 || maxPostSize > totalReadContentInBytes;
    }
    
    return true;
  }
}

代码示例来源:origin: javaee/grizzly

public void updateUserPrincipal(Request grizzlyRequest) {
  final GlassfishSession gfSession = doGetSession(false);
  if (gfSession != null) {
    grizzlyRequest.setUserPrincipal(gfSession.getPrincipal());
    grizzlyRequest.getRequest().authType().setString(gfSession.getAuthType());
  }
}

代码示例来源:origin: jersey/jersey

@Override
public void service(final Request request, final Response response) {
  final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
  try {
    logger.debugLog("GrizzlyHttpContainer.service(...) started");
    URI baseUri = getBaseUri(request);
    URI requestUri = getRequestUri(request);
    final ContainerRequest requestContext = new ContainerRequest(baseUri,
        requestUri, request.getMethod().getMethodString(),
        getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request));
    requestContext.setEntityStream(request.getInputStream());
    for (final String headerName : request.getHeaderNames()) {
      requestContext.headers(headerName, request.getHeaders(headerName));
    }
    requestContext.setWriter(responseWriter);
    requestContext.setRequestScopedInitializer(injectionManager -> {
      injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request);
      injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response);
    });
    appHandler.handle(requestContext);
  } finally {
    logger.debugLog("GrizzlyHttpContainer.service(...) finished");
  }
}

代码示例来源:origin: miltonio/milton2

@Override
public Map<String, String> getHeaders() {
  if( mapOfHeaders == null ) {
    mapOfHeaders = new HashMap<String, String>();
    for( String headerName : wrapped.getHeaderNames() ) {
      String s = wrapped.getHeader(headerName);
      mapOfHeaders.put(headerName, s);
    }
  }
  return mapOfHeaders;
}

代码示例来源:origin: javaee/grizzly

static @NotNull
String getBaseAddress(Request request) {
  StringBuilder buf = new StringBuilder();
  buf.append(request.getScheme());
  buf.append("://");
  buf.append(request.getServerName());
  buf.append(':');
  buf.append(request.getServerPort());
  buf.append(request.getContextPath());
  return buf.toString();
}

代码示例来源:origin: apache/incubator-pinot

@Override
 public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
   throws IOException {
  final String method = requestContext.getMethod();
  final String uri = requestContext.getUriInfo().getRequestUri().toString();
  final int respStatus = responseContext.getStatus();
  final String reasonPhrase = responseContext.getStatusInfo().getReasonPhrase();
  final String srcIpAddr = request.get().getRemoteAddr();
  final String contentType = requestContext.getHeaderString(HttpHeaders.CONTENT_TYPE);
  LOGGER.info("Handled request from {} {} {}, content-type {} status code {} {}", srcIpAddr, method, uri, contentType,
    respStatus, reasonPhrase);
 }
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server

@Override
  StringBuilder format(StringBuilder builder, Request request, Response response, Date timeStamp, long responseNanos) {
    final String uri = request.getRequestURI();
    return builder.append(uri == null ? "-" : uri);
  }
}

代码示例来源:origin: javaee/grizzly

private String composeReferrerHeader(final Request request) {
  final StringBuilder sb = new StringBuilder(64);
  final String queryString = request.getQueryString();
  sb.append(request.getRequestURL());
  if (queryString != null) {
    sb.append('?').append(queryString);
  }
  return sb.toString();
}

相关文章

Request类方法