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


Java ContainerRequest.getRequestHeaders方法代码示例

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


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

示例1: checkRequestHeader

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
/**
 * リクエストヘッダーの値をチェックする.
 * 現在は、Acceptヘッダーのみ(US-ASCII文字以外かどうか)をチェックする
 * @param request フィルター前リクエスト
 */
private void checkRequestHeader(ContainerRequest request) {
    // ヘッダーのキー名に全角文字が含まれる場合は、その文字を含めたキー名となるため、実際にはこの指定は無視される。
    // Jersey1.10では、Acceptヘッダーのキー名と値にUS-ASCII文字以外が含まれる場合に異常終了するため以下を対処
    // (Acceptを含む他のヘッダーにも同様の処理が行われるが、上記理由により動作上は問題ないと判断)
    // -キー名に含まれる場合は、その指定を無効(Accept:*/*)とする(Jerseryで組み込み済み)。
    // -値に含まれる場合は、400エラーとする。
    InBoundHeaders newHeaders = new InBoundHeaders();
    MultivaluedMap<String, String> headers = request.getRequestHeaders();
    for (String header : headers.keySet()) {
        if (header.contains(org.apache.http.HttpHeaders.ACCEPT)
                && !acceptHeaderValueRegex.matcher(header).matches()) {
            continue;
        } else {
            newHeaders.put(header, request.getRequestHeader(header));
        }
    }
    request.setHeaders(newHeaders);
    String acceptValue = request.getHeaderValue(org.apache.http.HttpHeaders.ACCEPT);
    if (acceptValue != null && !acceptHeaderValueRegex.matcher(acceptValue).matches()) {
        PersoniumCoreException exception = PersoniumCoreException.OData.BAD_REQUEST_HEADER_VALUE.params(
                org.apache.http.HttpHeaders.ACCEPT, acceptValue);
        throw exception;
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:30,代码来源:PersoniumCoreContainerFilter.java

示例2: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
  MultivaluedMap<String, String> headers = request.getRequestHeaders();
  if (headers.containsKey(HttpHeaders.ACCEPT_LANGUAGE)) {
    List<String> acceptLanguageValues = headers.remove(HttpHeaders.ACCEPT_LANGUAGE);

    for (int i = 0; i < acceptLanguageValues.size(); i++) {
      final String acceptLanguageValue = acceptLanguageValues.get(i);

      // replace es-419 (invalid) with es_ES (valid, hopefully good enough.)
      if (acceptLanguageValue.contains(ES_419)) {
        acceptLanguageValues.set(i, acceptLanguageValue.replace(ES_419, ES_ES));
      }
    }

    headers.put(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguageValues);

    request.setHeaders((InBoundHeaders) headers);
  }

  return request;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:23,代码来源:ReplaceES419LanguageFilter.java

示例3: adjustHeader

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
private void adjustHeader(ContainerRequest request, String path, String suffix) {
  String mime = SUFFIXES.get(suffix);
  
  // change accept header
  InBoundHeaders headers = (InBoundHeaders) request.getRequestHeaders();
  headers.put(HttpHeaders.ACCEPT, Collections.singletonList(mime));
  request.setHeaders(headers);
  
  // remove suffix from the URL
  String newPath = path.substring(0, path.length() - suffix.length());
  URI requestUri = request.getRequestUri();
  URI newURI = UriBuilder.fromUri(requestUri).replacePath(newPath).build();
  request.setUris(request.getBaseUri(), newURI);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:15,代码来源:UrlSuffixFilter.java

示例4: addRequestHeaders

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
private void addRequestHeaders(ContainerRequest cReq) {
	
	MultivaluedMap<String, String> headers = cReq.getRequestHeaders();
	for (Entry<String, List<String>> e : headers.entrySet()) {
		StaashRequestContext.addContext("H__" + e.getKey(), e.getValue().toString());
	}
}
 
开发者ID:Netflix,项目名称:staash,代码行数:8,代码来源:StaashAuditFilter.java

示例5: build

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
public static CacheRequestContext build(ContainerRequest request, Set<String> vary, boolean includeBody) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");

        for (String header : vary) {
            List<String> headerValues = request.getRequestHeader(header);

            if (headerValues != null && headerValues.size() > 0) {
                digest.update(header.getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                for (String value : headerValues) {
                    digest.update(value.getBytes(Charsets.UTF_8));
                    digest.update((byte) 0xFE);
                }

                digest.update((byte) 0xFF);
            }
        }

        if (includeBody) {
            byte[] requestBody = request.getEntity(byte[].class);

            if (requestBody == null) {
                requestBody = new byte[0];
            }

            if (requestBody.length > 0) {
                digest.update("Body".getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                digest.update(requestBody);
                digest.update((byte) 0xFF);
            }

            request.setEntityInputStream(new ByteArrayInputStream(requestBody));
        }

        String hash = new String(Base64.encode(digest.digest()), Charsets.US_ASCII);
        return new CacheRequestContext(request.getMethod(), request.getRequestUri(), request.getRequestHeaders(), hash);
    } catch (NoSuchAlgorithmException ex) {
        // This error should not occur since SHA-1 must be included with every java distribution
        throw Throwables.propagate(ex);
    }
}
 
开发者ID:bazaarvoice,项目名称:dropwizard-caching-bundle,代码行数:46,代码来源:CacheRequestContext.java

示例6: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
    LOG.debug(String.format("Authenticating request to %s", request.getRequestUri().toString()));
    LOG.debug("headers: " + request.getRequestHeaders());

    LOG.debug(request.getQueryParameters());

    // validate the user
    String accessKey = getAccessKey(request);

    if (null == accessKey || accessKey.length() == 0) {
        LOG.debug("Request received with no accesskey to " + request.getAbsolutePath());
        request.getRequestHeaders().add(PI_USER_ID_KEY, ANONYMOUS_USER);
        request.getRequestHeaders().add(PI_ACCESS_KEY_ID, ANONYMOUS_USER);
    } else {
        if (!userManager.userExists(accessKey)) {
            LOG.debug("Rejecting request from inexistent access key " + accessKey);
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        User user = null;

        for (AuthenticationHandler handler : authHandlers) {
            if (handler.canHandle(request)) {
                try {
                    user = handler.authenticate(request);
                } catch (AuthenticationException e) {
                    LOG.debug("Authentication handler did not like request from user with access key " + accessKey, e);
                    throw new WebApplicationException(e, Status.UNAUTHORIZED);
                }
            }
        }

        if (null != user) {
            request.getRequestHeaders().add(PI_USER_ID_KEY, user.getUsername());
            request.getRequestHeaders().add(PI_ACCESS_KEY_ID, user.getApiAccessKey());
        } else {
            LOG.debug("Unable to handle request for " + request.getAbsolutePath() + " with headers: " + request.getRequestHeaders());
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
    }

    // massive hack to make various clients work - maybe factor out into another filter?
    String contentType = request.getHeaderValue(HttpHeaders.CONTENT_TYPE);
    LOG.debug(String.format("%s: %s", HttpHeaders.CONTENT_TYPE, contentType));
    if ("".equals(contentType)) {
        LOG.info(String.format("Setting content type for request without one..."));
        MultivaluedMap<String, String> requestHeaders = request.getRequestHeaders();
        requestHeaders.remove(HttpHeaders.CONTENT_TYPE);
        requestHeaders.add(HttpHeaders.CONTENT_TYPE, ObjectMetaData.DEFAULT_OBJECT_CONTENT_TYPE);
    }

    return request;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:54,代码来源:AuthenticationFilter.java


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