本文整理匯總了Java中javax.ws.rs.container.ContainerRequestContext.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerRequestContext.getHeaders方法的具體用法?Java ContainerRequestContext.getHeaders怎麽用?Java ContainerRequestContext.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.container.ContainerRequestContext
的用法示例。
在下文中一共展示了ContainerRequestContext.getHeaders方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
MultivaluedMap<String, String> headers = ctx.getHeaders();
if(headers == null) {
handleError(ctx);
}
if(!headers.containsKey("X-Username")) {
handleError(ctx);
}
String username = headers.getFirst("X-Username");
if(username == null) {
handleError(ctx);
}
// Set the Username in the current Request Scope:
RequestContextHolder
.currentRequestAttributes()
.setAttribute("Username", username, SCOPE_REQUEST);
}
示例2: apply
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public Response apply(ContainerRequestContext arg0) {
SwaggerSpecFilter filter = FilterFactory.getFilter();
if (filter != null) {
Map<String, Cookie> cookiesvalue = arg0.getCookies();
Map<String, String> cookies = new HashMap<>();
if (cookiesvalue != null) {
for (String key : cookiesvalue.keySet()) {
cookies.put(key, cookiesvalue.get(key).getValue());
}
}
MultivaluedMap<String, String> headers = arg0.getHeaders();
return Response.ok().entity(new VendorSpecFilter().filter(getSwagger(), filter, null, cookies, headers)).build();
}
return Response.ok().entity(getSwagger()).build();
}
示例3: equalsRequestHeader
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
private boolean equalsRequestHeader(ContainerRequestContext containerRequestContext) {
MultivaluedMap<String, String> requestHeader = containerRequestContext.getHeaders();
MultivaluedMap<String, Object> desiredHeader = endpoint.getHeader().getContent();
if (!StringUtils.isEmpty(desiredHeader)) {
if (!requestHeader.isEmpty()) {
for (Map.Entry<String, List<Object>> map : desiredHeader.entrySet()) {
if (!requestHeader.containsKey(map.getKey()) || !requestHeader.get(map.getKey()).containsAll(map.getValue()))
return false;
}
} else
return false;
}
return true;
}
示例4: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
this.lastReceivedHeaders = requestContext.getHeaders();
}
示例5: filter
import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext) {
Method method = resourceInfo.getResourceMethod();
if (!method.isAnnotationPresent(PermitAll.class)) {
if (method.isAnnotationPresent(DenyAll.class)) {
requestContext.abortWith(ACCESS_FORBIDDEN);
return;
}
//Get request headers
final MultivaluedMap<String, String> headers = requestContext.getHeaders();
//Fetch authorization header
final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
//If no authorization information present; block access
if (authorization == null || authorization.isEmpty()) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
//Get encoded username and password
final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");
//Decode username and password
String usernameAndPassword = new String(Base64.decode(encodedUserPassword.getBytes()));
;
//Split username and password tokens
final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
final String username = tokenizer.nextToken();
final String password = tokenizer.nextToken();
//Verify user access
if (method.isAnnotationPresent(RolesAllowed.class)) {
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
Set<String> rolesSet = new HashSet<String>(Arrays.asList(rolesAnnotation.value()));
//Is user valid?
if (!isUserAllowed(username, password, rolesSet)) {
requestContext.abortWith(ACCESS_DENIED);
return;
}
}
}
}