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


Java ContainerRequest类代码示例

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


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

示例1: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
    // only if the query parameters contain the configured name
    // and one of the values from "fromValues"
    if (request.getQueryParameters() != null
            && !request.getQueryParameters().isEmpty()
            && request.getQueryParameters().containsKey(queryParamToModify)
            && ArrayUtils.contains(fromValues,
              request.getQueryParameters().getFirst(queryParamToModify))) {

        URI modifiedUri = getModifiedUri(request.getRequestUri());

        request.setUris(request.getBaseUri(), modifiedUri);
    }
    return request;
}
 
开发者ID:cvent,项目名称:pangaea,代码行数:17,代码来源:EnvironmentModifierFilter.java

示例2: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
/**
 * リクエスト全体に対してかけるフィルター.
 * @param request フィルタ前リクエスト
 * @return フィルタ後リクエスト
 */
@Override
public ContainerRequest filter(ContainerRequest request) {
    requestLog(request);

    // リクエストの時間を記録する
    long requestTime = System.currentTimeMillis();
    // リクエストの時間をセッションに保存する
    this.httpServletRequest.setAttribute("requestTime", requestTime);

    methodOverride(request);
    headerOverride(request);
    uriOverride(request);
    responseOptionsMethod(request);

    // リクエストヘッダーの不正値をチェックする
    checkRequestHeader(request);

    // PersoniumCoreConfig.setUnitRootIfNotSet(this.httpServletRequest);

    // PCSの動作モードがReadDeleteOnlyモードの場合は、参照系リクエストのみ許可する
    // 許可されていない場合は例外を発生させてExceptionMapperにて処理する
    PersoniumReadDeleteModeManager.checkReadDeleteOnlyMode(request.getMethod(), request.getPathSegments());

    return request;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:31,代码来源:PersoniumCoreContainerFilter.java

示例3: addResponseHeaders

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
/**
 * 全てのレスポンスに共通するレスポンスヘッダーを追加する.
 * Access-Control-Allow-Origin, Access-Control-Allow-Headers<br/>
 * X-Personium-Version<br/>
 * @param request
 * @param response
 */
private void addResponseHeaders(final ContainerRequest request, final ContainerResponse response) {
    MultivaluedMap<String, Object> mm = response.getHttpHeaders();
    String acrh = request.getHeaderValue(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
    if (acrh != null) {
        mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, acrh);
    } else {
        mm.remove(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS);
    }
    mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeaders.Value.ASTERISK);
    // X-Personium-Version
    mm.putSingle(HttpHeaders.X_PERSONIUM_VERSION, PersoniumUnitConfig.getCoreVersion());
}
 
开发者ID:personium,项目名称:personium-core,代码行数:20,代码来源:PersoniumCoreContainerFilter.java

示例4: responseOptionsMethod

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
/**
 * 認証なしOPTIONメソッドのレスポンスを返却する.
 * @param request フィルタ前リクエスト
 */
private void responseOptionsMethod(ContainerRequest request) {
    String authValue = request.getHeaderValue(org.apache.http.HttpHeaders.AUTHORIZATION);
    String methodName = request.getMethod();
    if (authValue == null && HttpMethod.OPTIONS.equals(methodName)) {
        Response res = PersoniumCoreUtils.responseBuilderForOptions(
                HttpMethod.GET,
                HttpMethod.POST,
                HttpMethod.PUT,
                HttpMethod.DELETE,
                HttpMethod.HEAD,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MERGE,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MKCOL,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.MOVE,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPFIND,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.PROPPATCH,
                io.personium.common.utils.PersoniumCoreUtils.HttpMethod.ACL
                ).build();

        // 例外を発行することでServletへ制御を渡さない
        throw new WebApplicationException(res);
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:27,代码来源:PersoniumCoreContainerFilter.java

示例5: 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

示例6: testFilterContainerRequestContainerResponse

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
/**
 * filter(ContainerRequest req, ContainerResponse res): ContainerResponseのテスト.
 * レスポンスフィルタとしてログ出力をしていることを確認。
 */
@Ignore
@Test
public void testFilterContainerRequestContainerResponse() {
    // 被テストオブジェクトを準備
    PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
    // ContainerRequiestモックを準備
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getAttribute("requestTime")).thenReturn(System.currentTimeMillis());
    containerFilter.setHttpServletRequest(mockServletRequest);

    // ContainerResponseモックを準備
    ContainerResponse mockResponse = mock(ContainerResponse.class);
    when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK);

    // 被テスト処理の実行
    ContainerResponse filteredResponse = containerFilter.filter(mockRequest, mockResponse);

    // 結果の検証。
    // ログ出力するだけなので、非Nullであることのみ検査.
    assertNotNull(filteredResponse);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:27,代码来源:PersoniumCoreContainerFilterTest.java

示例7: 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

示例8: resolvePermissions

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
/**
 * Resolves permissions based on the request.  For example, if the annotation's permission is
 * "get|{thing}" and the method's @Path annotation is "/resources/{thing}" then a request to
 * "/resources/table" will resolve to the permission "get|table".
 */
private String[] resolvePermissions(ContainerRequest request) {
    String[] values = _permissions;

    if (_substitutions.isEmpty()) {
        return values;
    }

    String[] permissions = new String[values.length];
    System.arraycopy(values, 0, permissions, 0, values.length);

    for (Map.Entry<String, Function<HttpRequestContext, String>> entry : _substitutions.entrySet()) {
        String key = Pattern.quote(entry.getKey());
        String substitution = Matcher.quoteReplacement(MatchingPermission.escape(entry.getValue().apply(request)));

        for (int i=0; i < values.length; i++) {
            permissions[i] = permissions[i].replaceAll(key, substitution);
        }
    }

    return permissions;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:27,代码来源:AuthorizationResourceFilter.java

示例9: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
    Subject subject = new Subject.Builder(_securityManager).buildSubject();
    ThreadContext.bind(subject);

    AuthenticationToken token = _tokenGenerator.createToken(request);
    if (token == null) {
        token = AnonymousToken.getInstance();
    }
    subject.login(token);

    // The user has been successfully logged in.  Update the container authentication.
    setJettyAuthentication(subject);

    return request;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:17,代码来源:AuthenticationResourceFilter.java

示例10: setUp

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    // Create a unique base path for each test so each tests ZooKeeper data is independent.
    _zkNamespace = "emodb/test" + (_nextBaseIndex++);
    _curator = _rootCurator.usingNamespace(_zkNamespace);

    _mapStore = new ZkMapStore<>(_curator, "adhoc-throttle", new ZkAdHocThrottleSerializer());
    _mapStore.start();

    _adHocThrottleManager = new AdHocThrottleManager(_mapStore);

    // Set up the regulator supplier provided to Jersey to defer an instance created specifically for this test.
    final AdHocConcurrentRequestRegulatorSupplier regulatorSupplier =
            new AdHocConcurrentRequestRegulatorSupplier(_adHocThrottleManager, new MetricRegistry());
    when(_deferringRegulatorSupplier.forRequest(any(ContainerRequest.class))).thenAnswer(
            new Answer<ConcurrentRequestRegulator>() {
                @Override
                public ConcurrentRequestRegulator answer(InvocationOnMock invocation) throws Throwable {
                    ContainerRequest request = (ContainerRequest) invocation.getArguments()[0];
                    return regulatorSupplier.forRequest(request);
                }
            });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:AdHocThrottleTest.java

示例11: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    if (response.getStatusType().getFamily() == Response.Status.Family.SERVER_ERROR) {
        switch (response.getStatus()) {
            case 500:
                _meter500.mark();
                break;
            case 503:
                _meter503.mark();
                break;
            default:
                _meterOther.mark();
                break;
        }
    }
    return response;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:ServerErrorResponseMetricsFilter.java

示例12: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
  if (request.getMethod().equalsIgnoreCase("POST") == false) {
    return request;
  }
  String methodFormParam = request.getFormParameters().getFirst("method");  // getFormParameters() returns empty when not a form
  if ("PUT".equals(methodFormParam)) {
    request.setMethod("PUT");
  } else if ("DELETE".equals(methodFormParam)) {
    request.setMethod("DELETE");
  } else if ("OPTIONS".equals(methodFormParam)) {
    request.setMethod("OPTIONS");
  } else if ("HEAD".equals(methodFormParam)) {
    request.setMethod("HEAD");
  } else if ("POST".equals(methodFormParam)) {
    request.setMethod("POST");  // for completeness
  } else if ("GET".equals(methodFormParam)) {
    request.setMethod("GET");  // for IE
  }
  return request;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:HttpMethodFilter.java

示例13: test_filter_noActionOnPostFormPut

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
public void test_filter_noActionOnPostFormPut() {
  ContainerRequest mock = Mockito.mock(ContainerRequest.class);
  when(mock.getMethod()).thenReturn("POST");
  Form form = new Form();
  form.put("method", Arrays.asList("PUT"));
  when(mock.getFormParameters()).thenReturn(form);
  
  HttpMethodFilter test = new HttpMethodFilter();
  ContainerRequest result = test.filter(mock);
  
  assertSame(mock, result);
  verify(mock).getMethod();
  verify(mock).getFormParameters();
  verify(mock).setMethod("PUT");
  verifyNoMoreInteractions(mock);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:HttpMethodFilterTest.java

示例14: test_filter_noActionOnPostFormDelete

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
public void test_filter_noActionOnPostFormDelete() {
  ContainerRequest mock = Mockito.mock(ContainerRequest.class);
  when(mock.getMethod()).thenReturn("POST");
  Form form = new Form();
  form.put("method", Arrays.asList("DELETE"));
  when(mock.getFormParameters()).thenReturn(form);
  
  HttpMethodFilter test = new HttpMethodFilter();
  ContainerRequest result = test.filter(mock);
  
  assertSame(mock, result);
  verify(mock).getMethod();
  verify(mock).getFormParameters();
  verify(mock).setMethod("DELETE");
  verifyNoMoreInteractions(mock);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:HttpMethodFilterTest.java

示例15: test_filter_noActionOnPostFormOptions

import com.sun.jersey.spi.container.ContainerRequest; //导入依赖的package包/类
public void test_filter_noActionOnPostFormOptions() {
  ContainerRequest mock = Mockito.mock(ContainerRequest.class);
  when(mock.getMethod()).thenReturn("POST");
  Form form = new Form();
  form.put("method", Arrays.asList("OPTIONS"));
  when(mock.getFormParameters()).thenReturn(form);
  
  HttpMethodFilter test = new HttpMethodFilter();
  ContainerRequest result = test.filter(mock);
  
  assertSame(mock, result);
  verify(mock).getMethod();
  verify(mock).getFormParameters();
  verify(mock).setMethod("OPTIONS");
  verifyNoMoreInteractions(mock);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:HttpMethodFilterTest.java


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