IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

JSON request and response as part of REST service

webMethods Community Member

webMethods Community MemberThu September 17, 2015 03:42 PM

webMethods Community Member

webMethods Community MemberThu September 17, 2015 03:43 PM

  • 1.  JSON request and response as part of REST service

    Posted Mon July 27, 2015 09:48 AM

    Hi All,

    Hope you all are doing good.

    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.

    I am using wM8.2 environment.

    Thanks,
    Anil.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 2.  RE: JSON request and response as part of REST service

    Posted Mon July 27, 2015 01:53 PM

    If upgrading to 9.0 is an option, I’d suggest that you upgrade. JSON is supported natively in 9.0 and higher.

    if not, there are many open source tools you can use to parse/construct JSON, for example Jackson, Gson.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 3.  RE: JSON request and response as part of REST service

    Posted Mon July 27, 2015 06:24 PM

    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)

    HTH,
    RMG


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 4.  RE: JSON request and response as part of REST service

    Posted Mon July 27, 2015 06:32 PM

    Thanks Wang, rmg for your suggestions. Can you kindly share the pkg if available or the URL from where I can download the same.

    Thanks,
    Anil.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 5.  RE: JSON request and response as part of REST service

    Posted Tue July 28, 2015 12:07 PM

    Can someone help me on this topic …

    Thanks,
    Anil.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 6.  RE: JSON request and response as part of REST service

    Posted Tue July 28, 2015 01:16 PM

    Anil,

    You have to search on this tech community you will definitely find some threads and also on internet. Anyways I am doing it for you:

    http://tech.forums.softwareag.com/techjforum/posts/list/25483.page

    http://agollakota.blogspot.in/2013/08/handling-json-in-esb.html

    If you want to build your own code, see the jars that I have mentioned in the above thread.

    More questions?


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: JSON request and response as part of REST service

    Posted Tue September 15, 2015 12:47 PM

    Dear All,

    I thank you for reading this post.

    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

    Thanks,
    Anil.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 8.  RE: JSON request and response as part of REST service

    Posted Wed September 16, 2015 04:24 PM

    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

    Thanks,


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 9.  RE: JSON request and response as part of REST service

    Posted Thu September 17, 2015 09:12 AM

    Thanks MR as173d, it resolved my issue.

    Thanks,
    Anil.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 10.  RE: JSON request and response as part of REST service

    Posted Thu September 17, 2015 03:42 PM


  • 11.  RE: JSON request and response as part of REST service

    Posted Thu September 17, 2015 03:43 PM


  • 12.  RE: JSON request and response as part of REST service

    Posted Thu October 08, 2015 07:04 AM

    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?


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 13.  RE: JSON request and response as part of REST service

    Posted Thu October 08, 2015 05:31 PM

    Ajay - Can you share your code to review.

    Thanks,


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 14.  RE: JSON request and response as part of REST service

    Posted Fri October 09, 2015 11:46 AM

    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.

    Percio


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 15.  RE: JSON request and response as part of REST service

    Posted Fri October 09, 2015 12:05 PM

    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?


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 16.  RE: JSON request and response as part of REST service

    Posted Fri October 09, 2015 12:21 PM

    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.

    Percio


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 17.  RE: JSON request and response as part of REST service

    Posted Fri October 09, 2015 12:24 PM

    Thank you “Percio Castro”

    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.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 18.  RE: JSON request and response as part of REST service



  • 19.  RE: JSON request and response as part of REST service

    Posted Thu December 07, 2017 01:42 PM

    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)

    please suggest some code example…


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB