我尝试将请求从 WildFly 8.1 中的 Rest 方法转发到 JSP 页面,但这会引发异常:
Caused by: java.lang.IllegalArgumentException: UT010023: Request io.undertow.servlet.spec.HttpServletRequestImpl@88ad706 was not original or a wrapper
at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:103) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at my.domain.RestResource.myRestMethod(RestResource.java:525) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_51]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.8.Final.jar:]
... 31 more
编码:
@GET
@Path("/my-path")
public void myRestMethod(@Context final HttpServletResponse response,
@Context final HttpServletRequest request) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/path/to/jsp");
dispatcher.forward(request, response);
}
这段代码在 Jboss 7.1 中没有问题。
最佳答案
我没有足够的调试来理解为什么/何时添加这些检查(显然这是 Servlet 规范所要求的),但是 Undertow 中有一个选项可以禁用它:
在 standalone/configuration/standalone.xml
文件中,更改 servlet-container
XML 元素,使其具有 allow-non-standard-wrappers="true"
属性。
有关详细信息,请查看 the official documentation(Servlet container configuration
部分)。
关于rest - 请求 io.undertow.servlet.spec.HttpServletRequestImpl 不是原始的或包装器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25644007/