gpt4 book ai didi

java - JSF ViewExpiredExceptionHandler NullPointerException

转载 作者:行者123 更新时间:2023-12-02 00:17:20 26 4
gpt4 key购买 nike

我在 WebSphere Application Server 8 上使用 Apache MyFaces 2。我想实现一个处理 ViewExpiredException 的自定义 ExceptionHandler。

我使用BalusC posted的代码。工厂在正确的时间被调用,但是当在这里调用handleNavigation时我得到一个NullPointerException:

public class ViewExpiredExceptionHandler extends ExceptionHandlerWrapper {

private ExceptionHandler wrapped;

public ViewExpiredExceptionHandler(ExceptionHandler wrapped) {
this.wrapped = wrapped;
}


@Override
public void handle() throws FacesException {
FacesContext facesContext = FacesContext.getCurrentInstance();

for (Iterator<ExceptionQueuedEvent> iter = getUnhandledExceptionQueuedEvents()
.iterator(); iter.hasNext();) {
Throwable exception = iter.next().getContext().getException();

if (exception instanceof ViewExpiredException) {
facesContext
.getApplication()
.getNavigationHandler()
.handleNavigation(facesContext, null,
"/content/home?faces-redirect=true&expired=true");
facesContext.renderResponse();
iter.remove();
}
}

getWrapped().handle();
}

@Override
public ExceptionHandler getWrapped() {
return wrapped;
}

}

异常(exception)是:

com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [Faces Servlet] in application [My_App]. Exception created : [java.lang.NullPointerException
at org.apache.myfaces.application.NavigationHandlerImpl.getNavigationCase(NavigationHandlerImpl.java:203)
at org.apache.myfaces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:77)
at myapp.ViewExpiredExceptionHandler.handle(ViewExpiredExceptionHandler.java:33)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
at myapp.auth.RequestFilter.doFilter(RequestFilter.java:35)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:886)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
]

编辑:首先/content 是我的 WebContent 中的一个目录。它不是上下文路径。我更改了代码并使用了外部重定向,如下所示:

if (exception instanceof ViewExpiredException) {
String loc = facesContext.getExternalContext()
.getRequestServletPath();
try {
facesContext.getExternalContext().redirect(loc);
//facesContext.getExternalContext().redirect("/content/home.xhtml");
//facesContext.getExternalContext().redirect("/");
} catch (IOException e) {
e.printStackTrace();
}
}

但在 facesContext.getExternalContext().redirect 上仍然得到相同的 NullPointerException。但ExternalContext不为空。我得到了RequestServletPath。

那么我的代码有什么问题吗?

最诚挚的问候 - 投票

最佳答案

“/content/home?faces-redirect=true&expired=true” 显然未被识别为有效的导航案例。由于有关您的环境的详细信息尚不清楚,因此无法判断那里出了什么问题。 /content 是否是上下文路径?如果是这样,则应将其省略。真的有 /home.xhtml 文件吗?等等。

如果您仍然无法弄清楚,那么发送重定向可能会更容易,因为无论如何您似乎都在重定向之后。

externalContext.redirect("/content/home.xhtml?expired=true");

请注意,如果 URL 无效,这仍然会导致 404,但您可能更容易弄清楚。

关于java - JSF ViewExpiredExceptionHandler NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11665564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com