How to use REST module to post/add an order?


(Daniel Kayiwa) #21

Is this on the demo server? Can you share the exact url?


(tendo kiiza Martyn) #22

@dkayiwa yes it is on the demo server. The url is still http://demo.openmrs.org


(tendo kiiza Martyn) #23

Also consider this.

After doing changes to the REST api in a watched module ,do i have to compile again in order to see the changes reflected under refapp Web services Module ?


(Daniel Kayiwa) #24

@tendomart did you see my question about the exact url that you are posting to?


(tendo kiiza Martyn) #25

@dkayiwa yes i did POST to /openmrs/ws/rest/v1/order at the demo server and on my local instance.


(Daniel Kayiwa) #26

@tendomart what is the exact data that you posted for that resource on the demo server? Did you also confirm that each of the uuids in your post exists on that server?


(tendo kiiza Martyn) #27

@dkayiwa i used

{
    "type": "testorder",
    "patient": "1681f4b7-7f4d-4227-9562-718ee347bbd8",
    "concept": "840AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "encounter": "8a32e7cb-0bbb-4c4e-8ed4-fc982443859f",
    "orderer": "9e28cb36-0df4-4972-b375-4a5ff88e39d9",
    "careSetting": "c365e560-c3ec-11e3-9c1a-0800200c9a66" 
} 

But i did not check to see wether those uuids exist on the server , i will check and get back.

(tendo kiiza Martyn) #28

Also one more thing , i still don’t understand why the demo server is still showing "No spec provided. " when i try to access the Swagger Documetation.


(Daniel Kayiwa) #29

@cintiadr is this in any way related to Nginx config? http://demo.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm


(Cintia Del Rio) #30

@dkayiwa, it’s a little bit hard to guess. Is that the configuration you wanted?

https://github.com/openmrs/openmrs-contrib-itsmresources/blob/master/ansible/host_vars/balaka.openmrs.org/vars#L46

Also, what happens when you run locally?


(Cintia Del Rio) #31

To investigate it further, I need the exact URL, parameters and data you are attempting to send. If it’s nginx or https, it should be a path that works locally with that docker compose file on http.


(Daniel Kayiwa) #32

What is displayed here https://uat-refapp.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm is what we would like here http://demo.openmrs.org/openmrs/module/webservices/rest/apiDocs.htm

It works very well locally.


(Cintia Del Rio) #33

The nginx configuration for uat-refapp and demo is identical.

https://uat-refapp.openmrs.org/openmrs/module/webservices/rest/swagger.json appears to have data. Demo doesn’t.

So I attempt to run a curl to localhost:

#demo
$ curl -vvv http://localhost:8080/openmrs/module/webservices/rest/swagger.json
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /openmrs/module/webservices/rest/swagger.json HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=????; Path=/openmrs; HttpOnly
< Content-Length: 0
< Date: Sun, 06 Jan 2019 06:04:45 GMT
<
* Connection #0 to host localhost left intact

Demo backend is returning empty. Nginx is returning exactly what the backend answered. That same url for uat-refapp returns correctly.

I also checked that uat-refapp and demo appear to be in different versions: https://ci.openmrs.org/browse/REFAPP-OMODDISTRO/deployments

I’m attempting to download the demo image locally to run it, but it doesn’t seem to be nginx at all.


(Daniel Kayiwa) #34

Good news is that i have been able to reproduce it locally by setting up a fresh instance of the reference application version 2.9.0-SNAPSHOT using the SDK. So let me now investigate.


(Cintia Del Rio) #35

When I run locally with the demo version/compose, I have:

openmrs-referenceapplication_1 | com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: io.swagger.models.Swagger[“definitions”]->java.util.LinkedHashMap[“ExtensionGet”]->io.swagger.models.ModelImpl[“properties”]->java.util.LinkedHashMap[“belongsTo”]->io.swagger.models.properties.RefProperty["$ref"]) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:353) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:727) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:778) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:635) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:778) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:635) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1396) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1120) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:993) openmrs-referenceapplication_1 | at io.swagger.util.Json.pretty(Json.java:23) openmrs-referenceapplication_1 | at org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator.createJSON(SwaggerSpecificationCreator.java:868) openmrs-referenceapplication_1 | at org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator.getJSON(SwaggerSpecificationCreator.java:150) openmrs-referenceapplication_1 | at org.openmrs.module.webservices.rest.web.controller.SwaggerSpecificationController.getSwaggerSpecification(SwaggerSpecificationController.java:42) openmrs-referenceapplication_1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) openmrs-referenceapplication_1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) openmrs-referenceapplication_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) openmrs-referenceapplication_1 | at java.lang.reflect.Method.invoke(Method.java:498) openmrs-referenceapplication_1 | at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177) openmrs-referenceapplication_1 | at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446) openmrs-referenceapplication_1 | at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434) openmrs-referenceapplication_1 | at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) openmrs-referenceapplication_1 | at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) openmrs-referenceapplication_1 | at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) openmrs-referenceapplication_1 | at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) openmrs-referenceapplication_1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) openmrs-referenceapplication_1 | at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) openmrs-referenceapplication_1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:64) openmrs-referenceapplication_1 | at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:72) openmrs-referenceapplication_1 | at org.openmrs.module.owa.filter.OwaFilter.doFilter(OwaFilter.java:64) openmrs-referenceapplication_1 | at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70) openmrs-referenceapplication_1 | at org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:54) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:108) openmrs-referenceapplication_1 | at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150) openmrs-referenceapplication_1 | at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) openmrs-referenceapplication_1 | at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) openmrs-referenceapplication_1 | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) openmrs-referenceapplication_1 | at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) openmrs-referenceapplication_1 | at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) openmrs-referenceapplication_1 | at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494) openmrs-referenceapplication_1 | at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) openmrs-referenceapplication_1 | at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) openmrs-referenceapplication_1 | at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) openmrs-referenceapplication_1 | at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) openmrs-referenceapplication_1 | at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) openmrs-referenceapplication_1 | at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137) openmrs-referenceapplication_1 | at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) openmrs-referenceapplication_1 | at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2511) openmrs-referenceapplication_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) openmrs-referenceapplication_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) openmrs-referenceapplication_1 | at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) openmrs-referenceapplication_1 | at java.lang.Thread.run(Thread.java:748) openmrs-referenceapplication_1 | Caused by: java.lang.NullPointerException openmrs-referenceapplication_1 | at io.swagger.models.properties.RefProperty.get$ref(RefProperty.java:52) openmrs-referenceapplication_1 | at sun.reflect.GeneratedMethodAccessor900.invoke(Unknown Source) openmrs-referenceapplication_1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) openmrs-referenceapplication_1 | at java.lang.reflect.Method.invoke(Method.java:498) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687) openmrs-referenceapplication_1 | at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) openmrs-referenceapplication_1 | … 87 more

Which is exactly the stack I have on demo logs when attempting to call that URL.


(Daniel Kayiwa) #36

Thanks for the update! Let me investigate it further. Will share my findings.


(Daniel Kayiwa) #37

It turns out that the commit for this ticket is the source of the no spec provided error: https://issues.openmrs.org/browse/RESTWS-721


(Samuel Male) #38

Thanks for hunting down this issue. I think and believe that the way these methods are overriden is the cause of the error https://github.com/openmrs/openmrs-module-webservices.rest/blob/4652b1e7ba7f8ee0e35cc306b517da53061c360c/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java#L42-L58


(Daniel Kayiwa) #39

On further investigation, what i reported above was not the cause. It just exposed a bug in the appframework module which i have fixed at https://github.com/openmrs/openmrs-module-appframework/commit/b86994c918b273260775afb1bdcbeb9e93b9839b

Which was caused by: https://issues.openmrs.org/browse/AF-54


(tendo kiiza Martyn) #40

@dkayiwa the UUID’S do not exist on the demo server