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


Java HttpRequestContext类代码示例

本文整理汇总了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;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:RunLauncher.java

示例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;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:18,代码来源:BasicAuthenticationProvider.java

示例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);
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:21,代码来源:AuthResourceFilterFactory.java

示例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;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:27,代码来源:AuthorizationResourceFilter.java

示例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");
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:18,代码来源:TestUserProvider.java

示例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();
}
 
开发者ID:yammer,项目名称:backups,代码行数:18,代码来源:TokenAuthInjectable.java

示例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);
    }
}
 
开发者ID:bazaarvoice,项目名称:jersey-hmac-auth,代码行数:23,代码来源:RequestDecoder.java

示例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());
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:17,代码来源:BulkExtractTest.java

示例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;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:31,代码来源:AuthResourceFilterFactory.java

示例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();
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:38,代码来源:AuthResourceFilterFactory.java

示例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);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:13,代码来源:ApiKeyAuthenticationTokenGenerator.java

示例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"));
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:16,代码来源:TestUserProvider.java

示例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");
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:16,代码来源:TestUserProvider.java

示例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);
}
 
开发者ID:johnlcox,项目名称:dagger-servlet,代码行数:15,代码来源:JerseyRequestModuleProvidesTest.java

示例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();
}
 
开发者ID:bazaarvoice,项目名称:jersey-hmac-auth,代码行数:12,代码来源:RequestDecoder.java


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