當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerRequestContext.getHeaders方法代碼示例

本文整理匯總了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);
}
 
開發者ID:bytefish,項目名稱:VersioningWithEnvers,代碼行數:25,代碼來源:UserNameFilter.java

示例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();
}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:19,代碼來源:SwaggerInflector.java

示例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;
    }
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:21,代碼來源:APIxInflector.java

示例4: filter

import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext)
		throws IOException {
	this.lastReceivedHeaders = requestContext.getHeaders();
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:6,代碼來源:TestRequestFilter.java

示例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;
            }
        }
    }
}
 
開發者ID:faizan-ali,項目名稱:full-javaee-app,代碼行數:47,代碼來源:AuthenticationFilter.java


注:本文中的javax.ws.rs.container.ContainerRequestContext.getHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。