當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerRequest.setHeaders方法代碼示例

本文整理匯總了Java中com.sun.jersey.spi.container.ContainerRequest.setHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerRequest.setHeaders方法的具體用法?Java ContainerRequest.setHeaders怎麽用?Java ContainerRequest.setHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.jersey.spi.container.ContainerRequest的用法示例。


在下文中一共展示了ContainerRequest.setHeaders方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: mutateURI

import com.sun.jersey.spi.container.ContainerRequest; //導入方法依賴的package包/類
/**
 * Mutates the URI based on who the user is (provided in Authentication object) and what they're
 * requesting (provided in Container Request object).
 *
 * @param auth
 *            OAuth2Authentication object (contains principal for user).
 * @param request
 *            Container Request (contains path and query parameters).
 */
public void mutateURI(Authentication auth, ContainerRequest request) {

    /*
     * Don't mutate POSTs.
     */
    if (request.getMethod().equals(POST)) {
        return;
    }

    SLIPrincipal user = (SLIPrincipal) auth.getPrincipal();
    String clientId = ((OAuth2Authentication) auth).getClientAuthentication().getClientId();
    List<PathSegment> segments = sanitizePathSegments(request);
    String parameters = request.getRequestUri().getQuery();
    

    if (segments.size() == 0) {
        throw new NotFoundException();
    }

    if (usingVersionedApi(segments)) {
        if (!request.getProperties().containsKey(REQUESTED_PATH)) {
            request.getProperties().put(REQUESTED_PATH, request.getPath());
        }
        MutatedContainer mutated = uriMutator.mutate(segments, parameters, user, clientId);

        if (mutated != null && mutated.isModified()) {

            String version = getResourceVersion(segments, mutated);

            if (mutated.getHeaders() != null) {
                InBoundHeaders headers = new InBoundHeaders();
                headers.putAll(request.getRequestHeaders());
                for (String key : mutated.getHeaders().keySet()) {
                    headers.putSingle(key, mutated.getHeaders().get(key));
                }
                request.setHeaders(headers);
            }

            if (mutated.getPath() != null) {
                if (mutated.getQueryParameters() != null && !mutated.getQueryParameters().isEmpty()) {
                    LOG.info("URI Rewrite: {}?{} --> {}?{}", new Object[] { request.getPath(), parameters, mutated.getPath(),
                            mutated.getQueryParameters() });
                    request.setUris(request.getBaseUri(),
                            request.getBaseUriBuilder().path(version).path(mutated.getPath())
                                .replaceQuery(mutated.getQueryParameters()).build());
                } else {
                    LOG.info("URI Rewrite: {} --> {}", new Object[] { request.getPath(), mutated.getPath() });
                    request.setUris(request.getBaseUri(),
                            request.getBaseUriBuilder().path(version).path(mutated.getPath()).build());
                }
            }
        }
    }
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:64,代碼來源:EndpointMutator.java


注:本文中的com.sun.jersey.spi.container.ContainerRequest.setHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。