2

I am getting an exception on WAS 7.0.0.13 update 1 server. I am working on the development of REST web services using spring 3 framework. When the spring framework is trying to get the output stream to write the http response body, WAS is throwing an exception

Writer already obtained (at com.ibm.ws.webcontainer.srt.SRTServletResponse.getOutputStream(SRTServletResponse.java:699))

Here is the call stack. Please advise.

[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)

Thanks, Satya.

skaffman
  • 398,947
  • 96
  • 818
  • 769
user567426
  • 43
  • 1
  • 1
  • 5

2 Answers2

2

Found a few things for you to go on:

Here is a similar error with working with the writer and output streams in a Servlet on WebSphere. Slightly different. But it might give you something to go on. Both answers looked good.

I also found this on IBM's fix site. It is for an older version of WAS, but sometimes things break, or the work arounds presented are still helpful with troubleshooting.

Lastly, if it is helpful I have a Google search on the error name here .

But I think I'd try the first link from stack over flow first. It looked the most promising.

Community
  • 1
  • 1
Chris Aldrich
  • 1,904
  • 1
  • 22
  • 37
  • Thanks for the response. Since all the work of writting response has been done by the spring framework, there is hardly anything that is there in my hand to tweek the code. Also, I would like to update that, I tried the same code in tomcat server and it works just fine. So your second suggestion looks most likely reason. – user567426 Jan 07 '11 at 23:05
  • Did you open a PMR with IBM? Did you find a similar APAR for WAS 7 yet? Just curious. – Chris Aldrich Jan 10 '11 at 13:46
2

I did open a similar thread on IBM's developerWorks, didnt get any response.

But I think I have found an answer to this issue. although I do not know the exact reason for the occurrence of exception I have found a work around for now. I was able to avoid the exception by resetting the buffer of the response object. Here is the sample code of my controller (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();
}
skaffman
  • 398,947
  • 96
  • 818
  • 769
user567426
  • 43
  • 1
  • 1
  • 5