We have a couple of REST services which takes XML doc as request and generates XML doc response. Now client asked us to accept JSON request and generate JSON response as part of some of the REST services. I have gone through a couple of posts in techCommunity.
Can someone tell me what all different possibilities to achieve the same. Also if someone has implementation of this kindly share.
There is a JsonSupport package availble for 8.2 and probably this would be the work around for time being until you are on 9.x (it comes with standard jason* suppport)
I have a service which takes JSON string, converts to xml, performs business, generates response in xml which in-turn converts into JSON string. I tested this service which is working fine. Now I exposed this service as REST service (on post method) which is been invoked from Rest client by passing data as JSON string. As part of Post service, I called bytesToString and then invoked my actual service by passing the String. I am getting the below error message. Kindly help me if someone has R&D on this.
Error Message:
com.wm.app.b2b.server.ServiceException: jsonStringToDocument failed: null
at Sxxx.jsonStringToDocument(JsonUtils.java:89)
at sun.reflect.GeneratedMethodAccessor737.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:443)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:643)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:41)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:51)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:276)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:30)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:363)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:547)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:234)
at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:194)
at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:584)
at com.wm.lang.flow.FlowState.step(FlowState.java:444)
at com.wm.lang.flow.FlowState.invoke(FlowState.java:409)
at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:1063)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:643)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:41)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:51)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:276)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:30)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:363)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:547)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:234)
at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:194)
at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:584)
at com.wm.lang.flow.FlowState.step(FlowState.java:444)
at com.wm.lang.flow.FlowState.invoke(FlowState.java:409)
at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:1063)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:643)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor
String comes as stream in REST service. Please use an object namely contentStream as an input to REST service, call StreamToString service which converts input stream to String which then pass to your main service. There are many threads on this topic, please go through
i’m using wm9.6, i’m not sure if there are issues with WM IS
@IS server level, the setting i have is watt.server.http.jsonFormat=parsed
at each HTTP POST (rest) transaction level, i’m passing jsonFormat=stream
i just have savepipelinetofile in my HTTP POST rest service, unfortunately i dont see the jsonStream variable available in my pipeline file
but i’ve this variable jsonStream, i can process this variable using streamtodocument
why is it that my savepipelinetofile not showing the jsonStream variable.
same is scenario, when i have jsonFormat=bytes in the query string, i dont see the jsonBytes in my savepipeline file, but jsonBytes is available for processing it.
one more question, when would i have contentStream as variable in my pipeline?
Certain, non-serializable, objects cannot be saved to a file. If you think about it, how can you save a stream to a file? You can’t. However, if you use the savePipeline service instead, it will save the object to memory. You should then be able to access those objects with restorePipeline.
MR as173d
i dont have any code to share. its a simple rest service which invokes savepipelinetofile
Percio Castro
i agree stream or node or enhancednode objects can’t be serialized. but when we savepipelinetofile, it could atleast capture the object reference (just default implementation of toString)
more than that as described in my previous post, most of the time i’m not sure what object to expect in the pipeline, how to retrieve it
name of the object we create in rest service’s input specification must exactly match to either xmlStream or contentStream, node??
could you please let us me know about this
one more question, when would i have contentStream as variable in my pipeline?
Take a look at Content Handlers section of the IS Admin guide. It should help clear some of the confusions up. When in doubt, use savePipeline instead of savePipelineToFile. Also, the getTransportInfo service can prove handy if you want to make sure you’re getting the expected HTTP headers and etc.
I had gone through the Service development, IS admin guide, Built-in services. experimented with code.
After reading through the content handlers and their behavior, i started posting to the tech communities.
anyhow, thanks a lot for all your quick expert responses.
Hi,
I have a requirement that i need to expose post service and then inside that post service i have to consume rest service.
Here i am able to do second part but while exposing first service which takes json as a request body of post methods… i am getting following error…
“$errorDump”: "com.wm.app.b2b.server.ServiceException: [ISS.0086.9249] Missing Parameter: inputStream at pub.CommonUtils.getRequiredObjParam(CommonUtils.java:97) at pub.io.streamToString(io.java:590)