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


Java Result.with方法代码示例

本文整理汇总了Java中org.wisdom.api.http.Result.with方法的典型用法代码示例。如果您正苦于以下问题:Java Result.with方法的具体用法?Java Result.with怎么用?Java Result.with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wisdom.api.http.Result的用法示例。


在下文中一共展示了Result.with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrieveAndReturnResult

import org.wisdom.api.http.Result; //导入方法依赖的package包/类
protected Result retrieveAndReturnResult(RequestContext context, String originHeader) throws Exception {
    Result result = context.proceed();

    // Is it actually a CORS request?
    if (originHeader != null) {
        String allowedHosts = getAllowedHostsHeader(originHeader);
        result = result.with(ACCESS_CONTROL_ALLOW_ORIGIN, allowedHosts);
        if (getAllowCredentials()) {
            result = result.with(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
        }
        if (!getExposedHeaders().isEmpty()) {
            result = result.with(ACCESS_CONTROL_EXPOSE_HEADERS, getExposedHeadersHeader());
        }
    }

    return result;
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:18,代码来源:AbstractCorsFilter.java

示例2: call

import org.wisdom.api.http.Result; //导入方法依赖的package包/类
/**
 * Interception method.
 * It checks whether or not the request requires CORS support or not. It also checks whether the requests is allowed
 * or not.
 *
 * @param route   the router
 * @param context the filter context
 * @return the result, containing the CORS headers as defined in the recommendation
 * @throws Exception if the result cannot be handled correctly.
 */
public Result call(Route route, RequestContext context) throws Exception {
    // Is CORS required?
    String originHeader = context.request().getHeader(ORIGIN);

    if (originHeader != null) {
        originHeader = originHeader.toLowerCase();
    }

    // If not Preflight
    if (route.getHttpMethod() != HttpMethod.OPTIONS) {
        return retrieveAndReturnResult(context, originHeader);
    }
    // OPTIONS route exists, don't use filter! (might manually implement
    // CORS?)
    if (!route.isUnbound()) {
        return context.proceed();
    }

    // Try "Preflight"

    // Find existing methods for other routes
    Collection<Route> routes = router.getRoutes();
    List<String> methods = new ArrayList<>(4); // expect POST PUT GET DELETE
    for (Route r : routes) {
        if (r.matches(r.getHttpMethod(), route.getUrl())) {
            methods.add(r.getHttpMethod().name());
        }
    }

    // If there's none, proceed to 404
    if (methods.isEmpty()) {
        return context.proceed();
    }

    String requestMethod = context.request().getHeader(ACCESS_CONTROL_REQUEST_METHOD);

    // If it's not a CORS request, just proceed!
    if (originHeader == null || requestMethod == null) {
        return context.proceed();
    }

    Result res = Results.ok(); // setup result

    if (!methods.contains(requestMethod.toUpperCase())) {
        res = Results.unauthorized("No such method for this route");
    }

    Integer maxAge = getMaxAge();
    if (maxAge != null) {
        res = res.with(ACCESS_CONTROL_MAX_AGE, String.valueOf(maxAge));
    }

    // Otherwise we should be return OK with the appropriate headers.

    String exposedHeaders = getExposedHeadersHeader();
    String allowedHosts = getAllowedHostsHeader(originHeader);

    String allowedMethods = Joiner.on(", ").join(methods);

    Result result = res.with(ACCESS_CONTROL_ALLOW_ORIGIN, allowedHosts)
            .with(ACCESS_CONTROL_ALLOW_METHODS, allowedMethods).with(ACCESS_CONTROL_ALLOW_HEADERS, exposedHeaders);
    if (getAllowCredentials()) {
        result = result.with(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    }

    return result;
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:78,代码来源:AbstractCorsFilter.java

示例3: save

import org.wisdom.api.http.Result; //导入方法依赖的package包/类
@Override
public void save(Context context, Result result) {
    // Don't save the cookie nothing has changed, and if we're not expiring
    // or we are expiring but we're only updating if the session changes
    if (!sessionDataHasBeenChanged && sessionSendOnlyIfChanged) {
        // Nothing changed and no cookie-expire, consequently send nothing
        // back.
        return;
    }

    if (isEmpty()) {
        // It is empty, but there was a session coming in, therefore clear
        // it
        if (context.hasCookie(applicationCookiePrefix
                + SESSION_SUFFIX)) {

            Cookie.Builder expiredSessionCookie = Cookie.builder(
                    applicationCookiePrefix + SESSION_SUFFIX,
                    "");
            expiredSessionCookie.setPath("/");
            expiredSessionCookie.setMaxAge(0);

            result.with(expiredSessionCookie.build());
        }
        return;

    }

    // Make sure if has a timestamp, if it needs one
    if (!data.containsKey(TIMESTAMP_KEY)) {
        data.put(TIMESTAMP_KEY, Long.toString(System.currentTimeMillis()));
    }

    try {
        String sessionData = CookieDataCodec.encode(data);

        String sign = crypto.sign(sessionData);

        Cookie.Builder cookie = Cookie.builder(applicationCookiePrefix
                + SESSION_SUFFIX, sign + "-" + sessionData);
        cookie.setPath("/");

        cookie.setMaxAge(sessionExpireTimeInMs / 1000);
        if (sessionTransferredOverHttpsOnly != null) {
            cookie.setSecure(sessionTransferredOverHttpsOnly);
        }
        if (sessionHttpOnly != null) {
            cookie.setHttpOnly(sessionHttpOnly);
        }

        result.with(cookie.build());

    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        LOGGER.error("Encoding exception - this must not happen", unsupportedEncodingException);
    }

}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:58,代码来源:SessionCookieImpl.java


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