• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StatusCodes类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.undertow.util.StatusCodes的典型用法代码示例。如果您正苦于以下问题:Java StatusCodes类的具体用法?Java StatusCodes怎么用?Java StatusCodes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StatusCodes类属于io.undertow.util包,在下文中一共展示了StatusCodes类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleRequest

import io.undertow.util.StatusCodes; //导入依赖的package包/类
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        if(exchange.getResponseCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
            ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
            src.getOriginalResponse().sendError(exchange.getResponseCode());
        } else {
            exchange.endExchange();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ServletAuthenticationCallHandler.java


示例2: handleRequest

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletRequest request = servletRequestContext.getServletRequest();
    if (request.getDispatcherType() == DispatcherType.REQUEST) {
        List<SingleConstraintMatch> constraints = servletRequestContext.getRequiredConstrains();
        SecurityContext sc = exchange.getSecurityContext();
        if (!authorizationManager.canAccessResource(constraints, sc.getAuthenticatedAccount(), servletRequestContext.getCurrentServlet().getManagedServlet().getServletInfo(), servletRequestContext.getOriginalRequest(), servletRequestContext.getDeployment())) {

            HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
            response.sendError(StatusCodes.FORBIDDEN);
            return;
        }
    }
    next.handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ServletSecurityRoleHandler.java


示例3: BasicAuthHandler

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public BasicAuthHandler(HttpHandler next, String expectedUsername, String expectedPassword) {
    this.expectedCredential = "Basic " + Base64.getEncoder()
            .encodeToString((expectedUsername + ":" + expectedPassword).getBytes());
    this.authChecker = Handlers.predicate(exchange -> {
        String userCredential = getRequestHeader(exchange, new HttpString("Authorization"));
        if (userCredential == null) {
            return false;
        } else if (expectedCredential.equals(userCredential)) {
            return true;
        }
        return false;
    }, next, exchange -> {
        exchange.getResponseHeaders()
                .put(new HttpString("WWW-Authenticate"), "Basic realm=\"realm\"");
        exchange.setStatusCode(StatusCodes.UNAUTHORIZED)
                .endExchange();
    });
}
 
开发者ID:icha024,项目名称:spur,代码行数:19,代码来源:BasicAuthHandler.java


示例4: handleRequest

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (isConfidential(exchange) || !confidentialityRequired(exchange)) {
        next.handleRequest(exchange);
    } else {
        try {
            URI redirectUri = getRedirectURI(exchange);

            exchange.setResponseCode(StatusCodes.FOUND);
            exchange.getResponseHeaders().put(Headers.LOCATION, redirectUri.toString());
        } catch (Exception e) {
            UndertowLogger.REQUEST_LOGGER.exceptionProcessingRequest(e);
            exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
        }
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:AbstractConfidentialityHandler.java


示例5: sendRedirect

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void sendRedirect(final String location) throws IOException {
    if (responseStarted()) {
        throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
    }
    resetBuffer();
    setStatus(StatusCodes.FOUND);
    String realPath;
    if (location.contains("://")) {//absolute url
        exchange.getResponseHeaders().put(Headers.LOCATION, location);
    } else {
        if (location.startsWith("/")) {
            realPath = location;
        } else {
            String current = exchange.getRelativePath();
            int lastSlash = current.lastIndexOf("/");
            if (lastSlash != -1) {
                current = current.substring(0, lastSlash + 1);
            }
            realPath = CanonicalPathUtils.canonicalize(servletContext.getContextPath() + current + location);
        }
        String loc = exchange.getRequestScheme() + "://" + exchange.getHostAndPort() + realPath;
        exchange.getResponseHeaders().put(Headers.LOCATION, loc);
    }
    responseDone();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:HttpServletResponseImpl.java


示例6: getErrorLocation

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public String getErrorLocation(final Throwable exception) {
    if (exception == null) {
        return null;
    }
    //todo: this is kinda slow, but there is probably not a great deal that can be done about it
    String location = null;
    for (Class c = exception.getClass(); c != null && location == null; c = c.getSuperclass()) {
        location = exceptionMappings.get(c);
    }
    if (location == null && exception instanceof ServletException) {
        Throwable rootCause = ((ServletException) exception).getRootCause();
        if (rootCause != null) {
            for (Class c = rootCause.getClass(); c != null && location == null; c = c.getSuperclass()) {
                location = exceptionMappings.get(c);
            }
        }
    }
    if (location == null) {
        location = getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
    }
    return location;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ErrorPages.java


示例7: sendContinueResponseBlocking

import io.undertow.util.StatusCodes; //导入依赖的package包/类
/**
 * Sends a continue response using blocking IO
 *
 * @param exchange The exchange
 */
public static void sendContinueResponseBlocking(final HttpServerExchange exchange) throws IOException {
    if (!exchange.isResponseChannelAvailable()) {
        throw UndertowMessages.MESSAGES.cannotSendContinueResponse();
    }
    if(exchange.getAttachment(ALREADY_SENT) != null) {
        return;
    }
    HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange);
    exchange.putAttachment(ALREADY_SENT, true);
    newExchange.setResponseCode(StatusCodes.CONTINUE);
    newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
    newExchange.startBlocking();
    newExchange.getOutputStream().close();
    newExchange.getInputStream().close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:HttpContinue.java


示例8: transferTo

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public long transferTo(final long position, final long count, final FileChannel target) throws IOException {
    if (exchange.getResponseCode() == StatusCodes.EXPECTATION_FAILED) {
        //rejected
        return -1;
    }
    if (!sent) {
        sent = true;
        response = HttpContinue.createResponseSender(exchange);
    }
    if (response != null) {
        if (!response.send()) {
            return 0;
        }
        response = null;
    }
    return super.transferTo(position, count, target);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:HttpContinueReadHandler.java


示例9: read

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public int read(final ByteBuffer dst) throws IOException {
    if (exchange.getResponseCode() == StatusCodes.EXPECTATION_FAILED) {
        //rejected
        return -1;
    }
    if (!sent) {
        sent = true;
        response = HttpContinue.createResponseSender(exchange);
    }
    if (response != null) {
        if (!response.send()) {
            return 0;
        }
        response = null;
    }
    return super.read(dst);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:HttpContinueReadHandler.java


示例10: awaitReadable

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void awaitReadable() throws IOException {
    if (exchange.getResponseCode() == StatusCodes.EXPECTATION_FAILED) {
        //rejected
        return;
    }
    if (!sent) {
        sent = true;
        response = HttpContinue.createResponseSender(exchange);
    }
    if (response != null) {
        while (!response.send()) {
            response.awaitWritable();
        }
        response = null;
    }
    super.awaitReadable();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:HttpContinueReadHandler.java


示例11: build

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public HandlerWrapper build(Map<String, Object> config) {

    String[] acl = (String[]) config.get("acl");
    Boolean defaultAllow = (Boolean) config.get("default-allow");
    Integer failureStatus = (Integer) config.get("failure-status");

    List<Holder> peerMatches = new ArrayList<>();
    for(String rule :acl) {
        String[] parts = rule.split(" ");
        if(parts.length != 2) {
            throw UndertowMessages.MESSAGES.invalidAclRule(rule);
        }
        if(parts[1].trim().equals("allow")) {
            peerMatches.add(new Holder(parts[0].trim(), false));
        } else if(parts[1].trim().equals("deny")) {
            peerMatches.add(new Holder(parts[0].trim(), true));
        } else {
            throw UndertowMessages.MESSAGES.invalidAclRule(rule);
        }
    }
    return new Wrapper(peerMatches, defaultAllow == null ? false : defaultAllow, failureStatus == null ? StatusCodes.FORBIDDEN : failureStatus);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:IPAddressAccessControlHandler.java


示例12: cancel

import io.undertow.util.StatusCodes; //导入依赖的package包/类
void cancel(final HttpServerExchange exchange) {
    final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
    if (connectionAttachment != null) {
        ClientConnection clientConnection = connectionAttachment.getConnection();
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
        IoUtils.safeClose(clientConnection);
    } else {
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
    }
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(exchange.getConnection());
    } else {
        exchange.setResponseCode(StatusCodes.SERVICE_UNAVAILABLE);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ProxyHandler.java


示例13: handleException

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void handleException(Channel channel, IOException exception) {
    IoUtils.safeClose(channel);
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(clientConnection);
        UndertowLogger.REQUEST_IO_LOGGER.debug("Exception reading from target server", exception);
        if (!exchange.isResponseStarted()) {
            exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
            exchange.endExchange();
        } else {
            IoUtils.safeClose(exchange.getConnection());
        }
    } else {
        exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ProxyHandler.java


示例14: wrap

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) {
    if (exchange.getResponseHeaders().contains(Headers.CONTENT_ENCODING)) {
        //already encoded
        return factory.create();
    }
    //if this is a zero length response we don't want to encode
    if (exchange.getResponseContentLength() != 0
            && exchange.getResponseCode() != StatusCodes.NO_CONTENT
            && exchange.getResponseCode() != StatusCodes.NOT_MODIFIED) {
        EncodingMapping encoding = getEncoding();
        if (encoding != null) {
            exchange.getResponseHeaders().put(Headers.CONTENT_ENCODING, encoding.getName());
            if (exchange.getRequestMethod().equals(Methods.HEAD)) {
                //we don't create an actual encoder for HEAD requests, but we set the header
                return factory.create();
            } else {
                return encoding.getEncoding().getResponseWrapper().wrap(factory, exchange);
            }
        }
    }
    return factory.create();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:AllowedContentEncodings.java


示例15: signIn

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public void signIn(HttpServerExchange exchange) {
    String id = exchange.getRelativePath().substring(1);
    boolean redirect = exchange.getQueryParameters().get("redirect") != null;

    AuthService service = services.get(id);
    if (service != null) {
        String state = service.generateState();
        if (redirect) {
            exchange.setResponseCookie(new CookieImpl("pxls-auth-redirect", "1").setPath("/"));
            redirect(exchange, service.getRedirectUrl(state+"|redirect"));
        } else {
            respond(exchange, StatusCodes.OK, new SignInResponse(service.getRedirectUrl(state+"|json")));
        }
    } else {
        respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_service", "No auth method named " + id));
    }
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:18,代码来源:WebHandler.java


示例16: handleRequest

import io.undertow.util.StatusCodes; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    String ip = exchange.getAttachment(IPReader.IP);

    RequestBucket bucket = buckets.<String, RequestBucket>compute(ip, (key, old) -> {
        if (old == null) return new RequestBucket(System.currentTimeMillis(), 0);
        if (old.startTime + time * 1000 < System.currentTimeMillis())
            return new RequestBucket(System.currentTimeMillis(), 0);
        return old;
    });
    bucket.count++;
    if (bucket.count > count)
    {
        int timeSeconds = (int) ((bucket.startTime + time * 1000) - System.currentTimeMillis()) / 1000;
        exchange.setStatusCode(StatusCodes.TOO_MANY_REQUESTS);
        exchange.getResponseSender().send("You are doing that too much, try again in " + timeSeconds / 60 + " minutes");
    } else {
        next.handleRequest(exchange);
    }
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:21,代码来源:RateLimitingHandler.java


示例17: getUserByEmail

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public User getUserByEmail(String email) {
    HttpUrl route = HttpUrl.parse(host + "/users")
                           .newBuilder()
                           .addPathSegment(email)
                           .build();
    Request request = new Request.Builder().url(route).get().build();
    return Unchecked.supplier(() -> {
        try (Response response = client.newCall(request).execute()) {
            // The user exists
            if (response.isSuccessful()) {
                User user = Json.serializer().fromInputStream(response.body().byteStream(), User.typeRef());
                return user;
            }

            /*
             *  404 Not Found - Either return null or throw your own exception.
             *  We prefer nulls.
             */
            if (response.code() == StatusCodes.NOT_FOUND) {
                return null;
            }
            throw HttpClient.unknownException(response);
        }
    }).get();
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:26,代码来源:RestClient.java


示例18: deleteUserByEmail

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public boolean deleteUserByEmail(String email) {
    HttpUrl route = HttpUrl.parse(host + "/users")
                           .newBuilder()
                           .addPathSegment(email)
                           .build();
    Request request = new Request.Builder().url(route).delete().build();
    return Unchecked.booleanSupplier(() -> {
        try (Response response = client.newCall(request).execute()) {
            if (response.code() == StatusCodes.NO_CONTENT) {
                return true;
            }

            // Maybe you would throw an exception here? We don't feel the need to.
            if (response.code() == StatusCodes.NOT_FOUND) {
                return false;
            }
            throw HttpClient.unknownException(response);
        }
    }).getAsBoolean();
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:21,代码来源:RestClient.java


示例19: createUser

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public User createUser(User inputUser) {
    HttpUrl route = HttpUrl.parse(host + "/users");
    Request request = new Request.Builder()
        .url(route)
        .post(RequestBodies.jsonObj(inputUser))
        .build();
    return Unchecked.supplier(() -> {
        try (Response response = client.newCall(request).execute()) {
            if (response.code() == StatusCodes.CREATED) {
                User user = Json.serializer().fromInputStream(response.body().byteStream(), User.typeRef());
                return user;
            }

            if (response.code() == StatusCodes.BAD_REQUEST) {
                return null;
            }
            throw HttpClient.unknownException(response);
        }
    }).get();
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:21,代码来源:RestClient.java


示例20: updateUser

import io.undertow.util.StatusCodes; //导入依赖的package包/类
public User updateUser(User inputUser) {
    HttpUrl route = HttpUrl.parse(host + "/users");
    Request request = new Request.Builder()
            .url(route)
            .put(RequestBodies.jsonObj(inputUser))
            .build();
    return Unchecked.supplier(() -> {
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                User user = Json.serializer().fromInputStream(response.body().byteStream(), User.typeRef());
                return user;
            }

            if (response.code() == StatusCodes.NOT_FOUND) {
                return null;
            }
            throw HttpClient.unknownException(response);
        }
    }).get();
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:21,代码来源:RestClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AccessDescription类代码示例发布时间:2022-05-21
下一篇:
Java RegexMapper类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap