本文整理匯總了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;
}
示例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;
}
示例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());
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}