IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 4 replies
  • Latest Post - ‏2013-07-03T12:59:18Z by d.m.spice
d.m.spice
d.m.spice
52 Posts

Pinned topic MPG for REST and XML

‏2013-07-03T12:40:27Z |

Hello,

I've developed an MPG for a REST service that needs to accept both JSON and XML.  I've set the request and response types to non-xml.  I need to copy the INPUT to a new context variable.  For the JSON, I use a convert query params action to create JSONX.  However, I do not know how to get the INPUT to the new variable is it's XML. A "copy all" stylesheet doesn't seem to work - I'm suspecting because DP sees the input as binary.  Any ideas?

Thanks!

  • d.m.spice
    d.m.spice
    52 Posts
    ACCEPTED ANSWER

    Re: MPG for REST and XML

    ‏2013-07-03T12:59:18Z  
    • d.m.spice
    • ‏2013-07-03T12:54:41Z

    Actually, I wonder if a dp:parse in the xsl will work, I'll try that now.

    Nevermind, extreme user error.  The INPUT to my copy action was NULL.

    I guess I haven't had enough coffee.

     

  • kenhygh
    kenhygh
    1480 Posts

    Re: MPG for REST and XML

    ‏2013-07-03T12:45:20Z  

    I generally solve this by using multiple rules: one rule which catches incoming JSON, does a convert query params, and then calls another rule that expects only XML. This second rule also catches anything that comes in as XML.

    You'll need to figure out, based on your payloads and their metadata, how to differentiate between calls in JSON and calls in XML.

     

    Ken

  • d.m.spice
    d.m.spice
    52 Posts

    Re: MPG for REST and XML

    ‏2013-07-03T12:50:01Z  
    • kenhygh
    • ‏2013-07-03T12:45:20Z

    I generally solve this by using multiple rules: one rule which catches incoming JSON, does a convert query params, and then calls another rule that expects only XML. This second rule also catches anything that comes in as XML.

    You'll need to figure out, based on your payloads and their metadata, how to differentiate between calls in JSON and calls in XML.

     

    Ken

    Thanks.  Here's a bit more information.  I have 1 rule that, as the first step, converts all input to XML.  I do this by using a conditional that looks at the content type.  If its JSON, I use the convert action to JSONX and put the results in the new OUTPUT variable.  If the content type is XML, I execute a stylesheet to copy all to the same OUTPUT variable - so the end result is that output variable will have XML - whether it be the original XML or JSONX.

    However, the xsl doesn't appear to work since I believe DP sees the input as binary. I'm looking to see if I have a bug somewhere....but haven't found one yet.

  • d.m.spice
    d.m.spice
    52 Posts

    Re: MPG for REST and XML

    ‏2013-07-03T12:54:41Z  
    • d.m.spice
    • ‏2013-07-03T12:50:01Z

    Thanks.  Here's a bit more information.  I have 1 rule that, as the first step, converts all input to XML.  I do this by using a conditional that looks at the content type.  If its JSON, I use the convert action to JSONX and put the results in the new OUTPUT variable.  If the content type is XML, I execute a stylesheet to copy all to the same OUTPUT variable - so the end result is that output variable will have XML - whether it be the original XML or JSONX.

    However, the xsl doesn't appear to work since I believe DP sees the input as binary. I'm looking to see if I have a bug somewhere....but haven't found one yet.

    Actually, I wonder if a dp:parse in the xsl will work, I'll try that now.

  • d.m.spice
    d.m.spice
    52 Posts

    Re: MPG for REST and XML

    ‏2013-07-03T12:59:18Z  
    • d.m.spice
    • ‏2013-07-03T12:54:41Z

    Actually, I wonder if a dp:parse in the xsl will work, I'll try that now.

    Nevermind, extreme user error.  The INPUT to my copy action was NULL.

    I guess I haven't had enough coffee.