1

我在 WAS 7.0.0.13 update 1 服务器上遇到异常。我正在使用 Spring 3 框架开发 REST Web 服务。当spring框架试图获取输出流写入http响应体时,WAS正在抛出异常

Writer 已获得(在 com.ibm.ws.webcontainer.srt.SRTServletResponse.getOutputStream(SRTServletResponse.java:699))

这是调用堆栈。请指教。

[1/7/11 13:25:02:600 CST] 0000001a webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[terms]: java.lang.IllegalStateException: SRVE0209E: Writer already obtained
 at com.ibm.ws.webcontainer.srt.SRTServletResponse.getOutputStream(SRTServletResponse.java:699)
 at com.ibm.ws.cache.servlet.FragmentComposer.obtainOutputStream(FragmentComposer.java:689)
 at com.ibm.ws.cache.servlet.FragmentComposer.getOutputStream(FragmentComposer.java:753)
 at com.ibm.ws.cache.servlet.CacheProxyResponse.getOutputStream(CacheProxyResponse.java:215)
 at org.springframework.http.server.ServletServerHttpResponse.getBody(ServletServerHttpResponse.java:64)
 at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeInternal(AbstractXmlHttpMessageConverter.java:66)
 at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:975)
 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:933)
 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:882)
 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:428)
 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
 at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)
 at com.ibm.ws.cache.servlet.CacheHook.handleFragment(CacheHook.java:574)
 at com.ibm.ws.cache.servlet.CacheHook.handleServlet(CacheHook.java:250)
 at com.ibm.ws.cache.servlet.ServletWrapper.service(ServletWrapper.java:259)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
 at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
 at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3826)
 at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
 at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
 at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:445)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:504)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:301)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:275)
 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:1563)

谢谢,萨蒂亚。

4

2 回答 2

2

找到了一些事情让你继续:

是在 WebSphere 上的 Servlet 中使用编写器和输出流时出现的类似错误。稍微不一样。但它可能会给你一些东西继续下去。两个答案看起来都不错。

我还在IBM 的修复站点上找到了这个。它适用于旧版本的 WAS,但有时会出现问题,或者提供的解决方法仍然有助于故障排除。

最后,如果有帮助,我会在此处对错误名称进行 Google 搜索 。

但我想我会先尝试从堆栈溢出的第一个链接。它看起来最有希望。

于 2011-01-07T21:04:30.300 回答
2

我确实在 IBM 的 developerWorks 上开了一个类似的帖子,没有得到任何回应。

但我想我已经找到了这个问题的答案。虽然我不知道发生异常的确切原因,但我现在找到了解决方法。通过重置响应对象的缓冲区,我能够避免异常。这是我的控制器(spring 3)的示例代码。

@RequestMapping(value = "/codesystems", method = RequestMethod.GET)

public @ResponseBody
CodeSystemVersionDirectory getAllAvailableCodeSystems(HttpServletResponse response) throws Exception {

    response.resetBuffer();

    response.setHeader("Location", "/codeSystems");
    response.setContentType("application/xml");

    return codeSystemService_.getCodesystemVersionDirectory();
}
于 2011-01-10T16:54:18.773 回答