本文整理汇总了Java中com.sun.jersey.api.core.HttpRequestContext类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestContext类的具体用法?Java HttpRequestContext怎么用?Java HttpRequestContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestContext类属于com.sun.jersey.api.core包,在下文中一共展示了HttpRequestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRun
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
protected Run createRun(Sequence<Corpus> plan, HttpContext httpContext, MultivaluedMap<String,String> formParams, FormDataMultiPart formData, AlvisNLPExecutor executor, String... excludedParams) throws IOException {
Run result = new Run(rootProcessingDir, plan, executor);
if (formData != null) {
setFormParams(formData, result, excludedParams);
}
if (formParams != null) {
setMultivaluedMapParams(formParams, result, excludedParams);
}
if (httpContext != null) {
HttpRequestContext requestContext = httpContext.getRequest();
MultivaluedMap<String,String> params = requestContext.getQueryParameters();
setMultivaluedMapParams(params, result, excludedParams);
}
result.write();
return result;
}
示例2: getValue
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Override
public AuthenticationVO getValue(HttpContext c) {
// if (c.getRequest().getAuthenticationScheme() == HttpRequestContext.BASIC_AUTH) {
String authHeaderValue = c.getRequest().getHeaderValue(HttpRequestContext.AUTHORIZATION);
String[] credentials = null;
if (authHeaderValue != null) {
credentials = JsUtil.decodeBase64(authHeaderValue.replaceFirst("[B|b]asic ", "")).split(":", 2);
}
AuthenticationVO result;
if (credentials != null && credentials.length == 2) {
result = new AuthenticationVO(credentials[0], credentials[1], null, WebUtil.getRemoteHost(request));
} else {
result = new AuthenticationVO();
result.setHost(WebUtil.getRemoteHost(request));
}
return result;
}
示例3: createQuerySubstitution
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
/**
* Creates a substitution function for query param values, such as
* <code>@RequiresPermission("resource|update|{?id}")</code>
*/
private Function<HttpRequestContext, String> createQuerySubstitution(final String param) {
return new Function<HttpRequestContext, String>() {
@Override
public String apply(HttpRequestContext request) {
MultivaluedMap<String, String> params = request.getQueryParameters();
if (!params.containsKey(param)) {
throw new IllegalStateException("Parameter required for authentication is missing: " + param);
}
List<String> values = params.get(param);
if (values.size() != 1) {
throw new IllegalStateException("Exactly one parameter expected for authentication: " + param);
}
return values.get(0);
}
};
}
示例4: resolvePermissions
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的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;
}
示例5: principalUser
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void principalUser() {
MDC.remove("user");
HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
Mockito.when(request.getUserPrincipal()).thenReturn(new Principal() {
@Override
public String getName() {
return "bar";
}
});
HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider();
assertEquals(up.getValue(context).getName(), "bar");
assertEquals(MDC.get("user"), "bar");
}
示例6: getToken
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
private Optional<String> getToken(HttpRequestContext request) {
// Token in an Authorization header
final String header = request.getHeaderValue(HttpHeaders.AUTHORIZATION);
if (!Strings.isNullOrEmpty(header) && header.startsWith(TokenAuthProvider.SCHEMA)) {
return Optional.of(header.replace(TokenAuthProvider.SCHEMA, "").trim());
}
// Token in URL
final MultivaluedMap<String, String> query = request.getQueryParameters();
final Optional<String> queryToken = Optional.fromNullable(query.getFirst("token"));
if (queryToken.isPresent()) {
return queryToken;
}
// No token provided
return Optional.absent();
}
示例7: safelyGetContent
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
/**
* Under normal circumstances, the body of the request can only be read once, because it is
* backed by an {@code InputStream}, and thus is not easily consumed multiple times. This
* method gets the request content and resets it so it can be read again later if necessary.
*/
private byte[] safelyGetContent(HttpRequestContext request) {
ContainerRequest containerRequest = (ContainerRequest) request;
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = containerRequest.getEntityInputStream();
try {
ReaderWriter.writeTo(in, out);
byte[] content = out.toByteArray();
// Reset the input stream so that it can be read again by another filter or resource
containerRequest.setEntityInputStream(new ByteArrayInputStream(content));
return content;
} catch (IOException ex) {
throw new ContainerException(ex);
}
}
示例8: testFailedEvaluatePreconditions
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Test
public void testFailedEvaluatePreconditions() throws Exception {
injector.setOauthAuthenticationWithEducationRole();
mockApplicationEntity();
mockBulkExtractEntity(null);
HttpRequestContext context = new HttpRequestContextAdapter() {
@Override
public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
return Responses.preconditionFailed();
}
};
Response res = bulkExtract.getEdOrgExtractResponse(context, null, null);
assertEquals(412, res.getStatus());
}
示例9: createSubstitutionMap
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
/**
* Returns a mapping from permissions found in the annotations to functions which can perform any necessary
* substitutions based on actual values in the request.
*/
private Map<String,Function<HttpRequestContext, String>> createSubstitutionMap(String[] permissions, AbstractMethod am) {
Map<String, Function<HttpRequestContext, String>> map = Maps.newLinkedHashMap();
for (String permission : permissions) {
Matcher matcher = SUBSTITUTION_MATCHER.matcher(permission);
while (matcher.find()) {
String match = matcher.group();
if (map.containsKey(match)) {
continue;
}
String param = matcher.group("param");
Function<HttpRequestContext, String> substitution;
if (param.startsWith("?")) {
substitution = createQuerySubstitution(param.substring(1));
} else {
substitution = createPathSubstitution(param, am);
}
map.put(match, substitution);
}
}
return map;
}
示例10: createPathSubstitution
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
/**
* Creates a substitution function for path values, such as
* <code>@RequiresPermission("resource|update|{id}")</code>
*/
private Function<HttpRequestContext, String> createPathSubstitution(final String param, final AbstractMethod am) {
int from = 0;
int segment = -1;
// Get the path from resource then from the method
Path[] annotations = new Path[] { am.getResource().getAnnotation(Path.class), am.getAnnotation(Path.class) };
for (Path annotation : annotations) {
if (annotation == null) {
continue;
}
int index = getSubstitutionIndex(param, annotation.value());
if (index >= 0) {
segment = from + index;
} else {
from += -index;
}
}
if (segment == -1) {
throw new IllegalArgumentException("Param not found in path: " + param);
}
final int validatedSegment = segment;
return new Function<HttpRequestContext, String>() {
@Override
public String apply(HttpRequestContext request) {
return request.getPathSegments().get(validatedSegment).getPath();
}
};
}
示例11: createToken
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Override
public ApiKeyAuthenticationToken createToken(HttpRequestContext context) {
String apiKey = context.getHeaderValue(ApiKeyRequest.AUTHENTICATION_HEADER);
if (Strings.isNullOrEmpty(apiKey)) {
apiKey = context.getQueryParameters().getFirst(ApiKeyRequest.AUTHENTICATION_PARAM);
if (Strings.isNullOrEmpty(apiKey)) {
return null;
}
}
return new ApiKeyAuthenticationToken(apiKey);
}
示例12: noUser
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void noUser() {
MDC.remove("user");
HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
Mockito.when(request.getUserPrincipal()).thenReturn(null);
MultivaluedMap map = Mockito.mock(MultivaluedMap.class);
Mockito.when(map.getFirst(UserProvider.USER_NAME_PARAM)).thenReturn(null);
Mockito.when(request.getQueryParameters()).thenReturn(map);
HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider();
assertNull(up.getValue(context));
assertNull(MDC.get("user"));
}
示例13: queryStringUser
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void queryStringUser() {
MDC.remove("user");
HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
Mockito.when(request.getUserPrincipal()).thenReturn(null);
MultivaluedMap map = Mockito.mock(MultivaluedMap.class);
Mockito.when(map.getFirst(UserProvider.USER_NAME_PARAM)).thenReturn("foo");
Mockito.when(request.getQueryParameters()).thenReturn(map);
HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider();
assertEquals(up.getValue(context).getName(), "foo");
assertEquals(MDC.get("user"), "foo");
}
示例14: RequestProvidesResource
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
@Inject
public RequestProvidesResource(HttpContext httpContext, UriInfo uriInfo, ExtendedUriInfo extendedUriInfo,
HttpRequestContext httpRequestContext, HttpHeaders httpHeaders,
Request request, SecurityContext securityContext,
HttpResponseContext httpResponseContext) {
assertNotNull(httpContext);
assertNotNull(uriInfo);
assertNotNull(extendedUriInfo);
assertNotNull(httpRequestContext);
assertNotNull(httpHeaders);
assertNotNull(request);
assertNotNull(securityContext);
assertNotNull(httpResponseContext);
}
示例15: decode
import com.sun.jersey.api.core.HttpRequestContext; //导入依赖的package包/类
public Credentials decode(HttpRequestContext request) {
return Credentials.builder()
.withApiKey(getApiKey(request))
.withSignature(getSignature(request))
.withPath(getPath(request))
.withTimestamp(getTimestamp(request))
.withContent(getContent(request))
.withMethod(getMethod(request))
.withVersion(Version.V1)
.build();
}