IllegalStateException while trying to retrieve a Patient resource

460 views
Skip to first unread message

bhavik gujarati

unread,
Feb 10, 2016, 3:20:47 AM2/10/16
to HAPI FHIR
Hello, Thanks for this awesome API. I am new to healthcare domain and HAPI-FHIR. I am trying to learn using HAPI-FHIR and trying to set up a simple client-server system using the example described in https://github.com/jamesagnew/hapi-fhir/tree/master/restful-server-example . I am getting following error while retrieving Patient with id=1. Can anyone help?


java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:679)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
    at ca.uhn.fhir.rest.server.servlet.ServletRestfulResponse.getResponseWriter(ServletRestfulResponse.java:74)
    at ca.uhn.fhir.rest.server.RestfulServerUtils.streamResponseAsResource(RestfulServerUtils.java:662)
    at ca.uhn.fhir.rest.server.RestfulResponse.streamResponseAsResource(RestfulResponse.java:46)
    at ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.handleException(ExceptionHandlingInterceptor.java:82)
    at ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.handleException(ExceptionHandlingInterceptor.java:52)
    at ca.uhn.fhir.rest.server.RestfulServer.handleRequest(RestfulServer.java:704)
    at ca.uhn.fhir.rest.server.RestfulServer.doGet(RestfulServer.java:259)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:208)
    at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:274)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

James Agnew

unread,
Feb 10, 2016, 6:56:50 AM2/10/16
to bhavik gujarati, HAPI FHIR
Hi Bhavik,

Interesting..

Are there any other exceptions in the server log before this one? Which version of Tomcat are you using?

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/0edcb52b-20d9-4061-8076-69358f33d8b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Agnew

unread,
Feb 10, 2016, 7:09:13 AM2/10/16
to bhavik gujarati, HAPI FHIR
Actually, one other question- What is the full URL you're trying to retrieve from the server?

-James

bhavik gujarati

unread,
Feb 10, 2016, 8:34:50 AM2/10/16
to HAPI FHIR, bhavikgu...@gmail.com
Hi James,

Thanks for replying on such a short notice.


This is one Warning that I am getting while starting the Tomcat:

Feb 10, 2016 6:48:36 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HAPI-FHIR-Server' did not find a matching property.

(HAPI-FHIR-Server) is my project/display name.



While running the servlet (which is essentially the server), I am getting following warning:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.


And finally, When I try to access Patient resourse, I get following error:

Feb 10, 2016 6:56:45 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [servlet.ExampleRestfulServlet] in context with path [/HAPI-FHIR-Server] threw exception

java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:679)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
    at ca.uhn.fhir.rest.server.servlet.ServletRestfulResponse.getResponseWriter(ServletRestfulResponse.java:74)
    at ca.uhn.fhir.rest.server.RestfulServerUtils.streamResponseAsResource(RestfulServerUtils.java:662)
    at ca.uhn.fhir.rest.server.RestfulResponse.streamResponseAsResource(RestfulResponse.java:46)
    at ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.handleException(ExceptionHandlingInterceptor.java:82)
    at ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.handleException(ExceptionHandlingInterceptor.java:52)
    at ca.uhn.fhir.rest.server.RestfulServer.handleRequest(RestfulServer.java:704)
    at ca.uhn.fhir.rest.server.RestfulServer.doGet(RestfulServer.java:259)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.ebaysf.web.cors.CORSFilter.handleNonCORS(CORSFilter.java:437)
    at org.ebaysf.web.cors.CORSFilter.doFilter(CORSFilter.java:172)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)


I have also attached screenshot and highlighted the line (in blue) where I am getting this error. I am not sure where "getWriter()" is getting multiple times (as that is the cause of this error, usually).

I am planning to use HAPI-FHIR client for android once I understand how things work in HAPI. I would also like to know if the android client is stable now.
HAPI-FHIR.png

bhavik gujarati

unread,
Feb 10, 2016, 8:36:44 AM2/10/16
to HAPI FHIR, bhavikgu...@gmail.com
This is the URL I am using:

http://localhost:8080/HAPI-FHIR-Server/fhir/Patient/1

"HAPI-FHIR-Server" is display name and "fhir" is URL-Pattern for the servlet.

bhavik gujarati

unread,
Feb 10, 2016, 9:30:05 AM2/10/16
to HAPI FHIR, bhavikgu...@gmail.com
Here is an update:

Creating new Patient and updating patients are working fine. Read and Search are not working. I guess "POST" type operations are working but "GET" type operations are not. I believe that in read and search operations, client is being returned a resource object which the server can't properly write to response because of the error that I am getting (getWriter() being called more than once).

bhavik gujarati

unread,
Feb 10, 2016, 9:48:01 AM2/10/16
to HAPI FHIR, bhavikgu...@gmail.com
My Tomcat version is 7.0.67

James Agnew

unread,
Feb 16, 2016, 9:20:17 PM2/16/16
to bhavik gujarati, HAPI FHIR
This is a mystery to me... I don't see any reason why this wouldn't work.

Can you try grabbing a completely fresh copy of the example project from Git and seeing if it works in that case? I'm stumped as to what could be causing this for you, as this example typically works for people...

Cheers,
James

Keith Boone

unread,
Aug 22, 2018, 12:35:52 PM8/22/18
to HAPI FHIR
What I suspect is happening here is that an exception is being thrown during or after sending the output (quite likely where the request is asking for output to be returned in GZIP compressed format), and the default exception handling mechanism is then trying to WRITE a response based on that exception having been thrown using a Writer instead of an OutputStream, and this is then causing the IllegalStateException.

We are having a similar problem that we have NOT yet tracked down the cause of, but that's what I've determined seems to be the root cause THUS FAR.

   Keith

Boone, Keith W. (VBC NewCo non-GE)

unread,
Aug 23, 2018, 10:16:37 PM8/23/18
to HAPI FHIR

My suspicions are now Confirmed.

 

What was happening for us was that an exception was thrown in the processingCompletedNormally() method of one of our interceptors, AFTER the response had been sent.  This was causing a call to httpServletResponse.getWriter() method, and since the response writing had already called getOutputStream(), our exception was then hidden by the IllegalStateException thrown by JBoss.

 

I suspect there is a similar problem in your example, because the error is happening in nearly the identical place: ExceptionHandlingInterceptor

 

                Keith

Reply all
Reply to author
Forward
0 new messages