org.glassfish.grizzly.http.server.Request.getHeader()方法的使用及代码示例

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

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

Request.getHeader介绍

[英]Return the first value of the specified header, if any; otherwise, return null
[中]返回指定标头的第一个值(如果有);否则,返回null

代码示例

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

public WrappedResponse(Request request, Response response) {
  this.response = response;
  this.machineId = request.getHeader(AnalystWorker.WORKER_ID_HEADER);
}

代码示例来源: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: opentripplanner/OpenTripPlanner

/** Consumer long-poll operations are enqueued here. */
public synchronized void registerSuspendedResponse(String graphId, Response response) {
  // Add this worker to our catalog, tracking its graph affinity and the last time it was seen.
  String workerId = response.getRequest().getHeader(AnalystWorker.WORKER_ID_HEADER);
  if (workerId != null && !workerId.isEmpty()) {
    workerCatalog.catalog(workerId, graphId);
  } else {
    LOG.error("Worker did not supply a unique ID for itself . Ignoring it.");
    return;
  }
  // Shelf this suspended response in a queue grouped by graph affinity.
  Deque<Response> deque = consumersByGraph.get(graphId);
  if (deque == null) {
    deque = new ArrayDeque<>();
    consumersByGraph.put(graphId, deque);
  }
  deque.addLast(response);
  nWaitingConsumers += 1;
  // Wake up the delivery thread if it's waiting on consumers.
  // This is whatever thread called wait() while holding the monitor for this Broker object.
  notify();
}

代码示例来源:origin: org.glassfish.main.admin/admin-util

private static Map<String,String> headers(final Request req) {
  final Map<String,String> result = new HashMap<String,String>();
  for (String headerName : req.getHeaderNames()) {
    result.put(headerName(headerName), req.getHeader(headerName));
  }
  return result;
}

代码示例来源: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: com.sun.jersey/jersey-grizzly2

private InBoundHeaders getHeaders(final Request request) {
    final InBoundHeaders rh = new InBoundHeaders();
    for (final String name : request.getHeaderNames()) {
      rh.add(name, request.getHeader(name));
    }

    return rh;
  }
}

代码示例来源: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: jersey/jersey-1.x

private InBoundHeaders getHeaders(final Request request) {
    final InBoundHeaders rh = new InBoundHeaders();
    for (final String name : request.getHeaderNames()) {
      rh.add(name, request.getHeader(name));
    }

    return rh;
  }
}

代码示例来源:origin: org.glassfish.main.web/web-core

/**
 * Return the first value of the specified header, if any; otherwise,
 * return <code>null</code>
 *
 * @param name Name of the requested header
 */
@Override
public String getHeader(String name) {
  return coyoteRequest.getHeader(name);
}

代码示例来源:origin: org.glassfish.main.web/web-core

/**
 * Return the authorization credentials sent with this request.
 */
@Override
public String getAuthorization() {
  return coyoteRequest.getHeader(Constants.AUTHORIZATION_HEADER);
}

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

@Override
public String getRequestHeader(Header header) {
  return wrapped.getHeader(header.code);
}

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

@Override
public String getRequestHeader(String headerName) {
  return request.getHeader(headerName);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

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

/**
 * {@inheritDoc}
 */
@Override
public String getHeader(String name) {
  if (request == null) {
    throw new IllegalStateException("Null request object");
  }
  return request.getHeader(name);
}

代码示例来源:origin: org.glassfish.main.admin/admin-util

private Subject consumeTokenIfPresent(final Request req) {
  Subject result = null;
  final String token = req.getHeader(SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME);
  if (token != null) {
    result = authTokenManager.consumeToken(token);
  }
  return result;
}

代码示例来源:origin: org.glassfish.main.admin/admin-util

private String restToken() {
  final Cookie[] cookies = request.getCookies();
  String result = null;
  if (cookies != null) {
    for (Cookie cookie : cookies) {
      if (COOKIE_REST_TOKEN.equals(cookie.getName())) {
        result = cookie.getValue();
      }
    }
  }
  
  if (result == null) {
    result = request.getHeader(HEADER_X_AUTH_TOKEN);
  }
  return result;
}

相关文章

Request类方法