0
votes

I am trying to publish a json message using the Amazonsns connector in WSO2 ESB 4.9. I am able to successfully publish a simple string message however when I set the messagestructure to json in order to send different messages to different platforms and attempting to send json as the value of message it will not work. I am using a simple transaction that looks almost exactly like the documentation sample. My Transaction:

content-type: application/json;charset=UTF-8

{
  "region":"us-west-2",
  "accessKeyId":"MyAccessKey",
  "secretAccessKey":"MySecretAccessKey",
  "version":"",
  "messageStructure":"json",
  "subject":"Test",
  "message": {"default":"mess","email":"message"},
  "targetArn":"arn:aws:sns:us-west-2:977102061874:endpoint/APNS_SANDBOX/mobile_iOS_Sandbox/34ed4324e6-1119-67sd-b7dd-f413c88e4e25",
  "topicArn":""
  }

My result is an unexpected error sending message out.

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,73]Message: Illegal character: <d>

My service is also like the example:

<amazonsns.init>
        <region>{$ctx:region}</region>
        <accessKeyId>{$ctx:accessKeyId}</accessKeyId>
        <secretAccessKey>{$ctx:secretAccessKey}</secretAccessKey>
        <version>{$ctx:version}</version>
     </amazonsns.init>
     <amazonsns.publish>
        <message>{$ctx:message}</message>
        <subject>{$ctx:subject}</subject>
        <messageStructure>{$ctx:messageStructure}</messageStructure>
        <topicArn>{$ctx:topicArn}</topicArn>
        <targetArn>{$ctx:targetArn}</targetArn>
     </amazonsns.publish>

I did not expect much success but just started trying different things....I attempted xml encoding the json message and get the same message on '&'. Using wire logs I found the content type of the successful messages going to Amazon were application/x-www-form-urlencoded so I also tried url encoding and get same message on the '%'.

I'm running out of ideas. I double checked the connector documentation to make sure I did not miss anything. It does say you can use a JSON transaction for Publish and gives a sample transaction however it does not discuss anything special/different that you would need to set up in order to make this work. Is there something I am missing?

UPDATE: Can see it is using the Builder for application/x-www-form-urlencoded which is stumbling on the json. Have tried setting messageType and ContentType properties to application/json. JSON Builder is enabled. It just seems the connector wants to send it out as application/x-www-form-urlencoded, is there something I am not setting properly to tell the connector this is JSON?

UPDATE: The publish template that comes with the connector is setting the messagetype to applicaiton/x-www-form-urlencoded which is overriding any of the settings I am making in my proxy service. Going to look at changing the template in the connector to use a different messagetype and/or allow me to set it in the proxy dynamically then will be trying again.

Joe

2

2 Answers

1
votes

We have created a public JIRA for this issue. Please follow that.

0
votes

You need to enable message builders for the content types you are sending. make sure following is done.

  1. Enable relevent Message builder for each content-type.

    < messageBuilder contentType="application/json" class="org.apache.synapse.commons.json.JsonStreamBuilder"/>

  2. Make sure Content-Type header property is parsing with the message.

  3. Make sure your Json is wellformed.