Uploaded image for project: 'Webservices REST Module'
  1. Webservices REST Module
  2. RESTWS-306

POST to /obs with "value" in the beginning throws error

    XMLWordPrintable

    Details

    • Complexity:
      Undetermined

      Description

      As per the JSON spec. a JSON object is an unordered set of elements. But incase of an observation object, if the "value" field appears at the beginning of the JSON message, the Obs resource throws an error. If I move the "value" field towards the end, then the POST works fine.

      So the following does not work:

      echo '
      {"value":98.5,"concept":"e334bc08-c3c7-407c-b761-13c714dfcd1e","person":"22bcd6c9-18fc-43b0-9ba6-446bb467d512","encounter":"68dcc5d2-8cc4-46bb-a4bd-54541968918b","obsDatetime":"2012-10-09T19:02:37.613+0530","location":"8d6c993e-c2cc-11de-8d13-0010c6dffd0f"}
      }
      ' | curl -i -H "Content-type: application/json" -X POST -d @- https://localhost:8443/openmrs191/ws/rest/v1/obs -k -b cookies.txt -3
      

      Error:

      {"error":{"message":"Unable to convert object into response content","code":"org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource:685","detail":"org.openmrs.module.webservices.rest.web.response.ConversionException: value on class org.openmrs.Obs\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:685)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setConvertedProperties(BaseDelegatingResource.java:543)\n\tat org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource.create(DelegatingCrudResource.java:90)\n\tat org.openmrs.module.webservices.rest.web.v1_0.controller.BaseCrudController.create(BaseCrudController.java:83)\n\tat sun.reflect.GeneratedMethodAccessor918.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:616)\n\tat org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:637)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n\tat org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:65)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:76)\n\tat org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:100)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74)\n\tat org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:58)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74)\n\tat org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:58)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n\tat org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:111)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\n\tat org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)\n\tat org.apache.catalina.core.Ap
      

      Whereas the following works:

      echo '
      {"concept":"e334bc08-c3c7-407c-b761-13c714dfcd1e","person":"22bcd6c9-18fc-43b0-9ba6-446bb467d512","encounter":"68dcc5d2-8cc4-46bb-a4bd-54541968918b","obsDatetime":"2012-10-09T19:02:37.613+0530","location":"8d6c993e-c2cc-11de-8d13-0010c6dffd0f","value":98.5}
      }
      ' | curl -i -H "Content-type: application/json" -X POST -d @- https://localhost:8443/openmrs191/ws/rest/v1/obs -k -b cookies.txt -3
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jkondrat Jakub Kondrat
                Reporter:
                kavuri Sateesh Kavuri
                Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:

                    Time Tracking

                    Estimated:
                    Original Estimate - 1 day, 4 hours
                    1d 4h
                    Remaining:
                    Remaining Estimate - 0 minutes
                    0m
                    Logged:
                    Time Spent - 1 day, 4 hours
                    1d 4h