Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpHandler相关问题_Java_Wildfly_Undertow - Fatal编程技术网

Java HttpHandler相关问题

Java HttpHandler相关问题,java,wildfly,undertow,Java,Wildfly,Undertow,我有一个像下面这样的HttpHandler @Override public void handleRequest(HttpServerExchange exchange) throws Exception { System.out.println("In the handler"); SecurityContext securityContext = exchange.getSecurityContext(); if(securityC

我有一个像下面这样的HttpHandler

@Override
    public void handleRequest(HttpServerExchange exchange) throws Exception {
        System.out.println("In the handler");

        SecurityContext securityContext = exchange.getSecurityContext();
        if(securityContext != null){
            if(securityContext.isAuthenticated()){
                if(somechecks() ) {
                    //redirect to login error page
                }
                }
            }
        }

        next.handleRequest(exchange);
    }
如何从处理程序重定向到错误页面?

试试这个

public static void redirectTo(HttpServerExchange exchange, String uri) {
    exchange.getResponseHeaders().add(HttpString.tryFromString("Location"), uri);
    exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT);
    exchange.getResponseSender().close();
}

对于我使用的处理程序重定向,RedirectHandelr:

RedirectHandler redirectHandler = new RedirectHandler("yourErrorPageURL");
redirectHandler.handleRequest(exchange);

您可能需要解释将代码放在何处以及之后返回的位置,否则可能会出现对已关闭响应的访问,并创建不必要的错误。它会引发以下异常。java.lang.NoSuchMethodError:io.undertow.server.HttpServerExchange.setStatusCode(I)Lio/undertow/server/HttpServerExchange;我已经用undertow 1.3.9.Final版本对其进行了测试。如果它成功编译但在运行时出现异常。您在运行时可能有不同的版本。你能告诉我实际的代码和堆栈跟踪我怎么能在我的wildfly上找到undertow的版本?你可以从这里更新你的wildfly版本