I'm using wso2 integration studio (version 7.2). I'm trying to post a JSON payload factory to an endpoint. This JSON message has a JSON array with a square bracket but wso2 keeps removing that before sending it out. The receiver API doesn't accept it in this format.
See my code below:
<api context="/test" name="testAPi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="setCharacterEncoding" value="false" scope="axis2"/>
<payloadFactory media-type="json">
<format>{"field1": 5,"field2": 2022,"field3": "22","contacts": [{"id":1014,"surname": "N"}],"applicants": [{"nameId": 111111}]}
</format>
<args/>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/json"/>
<property name="contentType" scope="axis2" type="STRING" value="application/json"/>
<log level="full"/>
<header name="Accept" scope="transport" value="*/*"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<header name="Connection" scope="transport" value="keep-alive"/>
<header name="Accept-Encoding" scope="transport" value="gzip, deflate, br"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<call blocking="true">
<endpoint key="tcpmon"/>
</call>
<log level="full"/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
I used the tcpmon to see what is sending out. and I can see wso2 just remove the [] from the message and send it out.
Do you know how can I fix this?
Related
I created proxy service in WSO EI 6.4.0, which send email. In the flow I use properties: AttachmentFile, transport.mail.bodyWhenAttached, senderAddress and Subject. How to create custom wsdl with input parameters sender_address, subject, mail_text, attachment_file. or what other solution can you use?
I want to call this proxy server via API and send the parameters.
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="transport.mail.Format" scope="axis2" type="STRING" value="Attachment"/>
<property name="AttachmentFile" scope="axis2" type="STRING" value="attachment.csv"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property expression="Some body text" name="transport.mail.bodyWhenAttached"
scope="axis2" type="STRING"/>
<property name="senderAddress" scope="default" type="STRING" value="test#test.com"/>
<property name="Subject" scope="transport" type="STRING" value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full"/>
<header
expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To" scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
</inSequence>
Save the below file with the name sendEmailProxy.xml under the location
//repository/deployment/server/synapse-configs/default/proxy-services
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="sendEmailProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property name="transport.mail.Format"
scope="axis2"
type="STRING"
value="Attachment"/>
<property name="AttachmentFile"
scope="axis2"
type="STRING"
value="attachment.csv"/>
<property name="ContentType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/html"/>
<property name="senderAddress"
scope="default"
type="STRING"
value="test#test.com"/>
<property name="Subject"
scope="transport"
type="STRING"
value="WSO Email Test"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<log level="full"/>
<header expression="fn:concat('mailto:', get-property('senderAddress'))"
name="To"
scope="default"/>
<call>
<endpoint>
<default/>
</endpoint>
</call>
<respond/>
</inSequence>
</target>
<parameter name="useOriginalwsdl">true</parameter>
<description/>
</proxy>
Once it is saved start wso2 EI/ESB instance , log into the instance, then click on service which is on left hand side of screen below services you wil find the proxy, You will have two options wsdl1.1 wsdl2.0 click on which ever you prefer , this would provide the wsdl file for you proxy
If you are already having a custom wsdl and want wso2 to pick up that wsdl then you need to add the below parameter
<parameter name="useOriginalwsdl">true</parameter>
This would accept your custom wsdl and wso2 will not generate it's own wsdl
I have a WSO2 ESB server with DSS features installed. When I invoke a REST service with "accept: application/json" in request header, I don't receive JSON response, only XML.
Best, Ivan
In this API, to get the response in JSON, I use these two properties:
<property name="Accept" value="application/json" scope="transport" type="STRING"/>
<property name="messageType" value="application/json" scope="axis2"/>
You can see the implementation here
<api xmlns="http://ws.apache.org/ns/synapse" name="showById" context="/getById">
<resource methods="POST GET" uri-template="/getEmployeeXML/{Id}">
<inSequence>
<property name="getId" expression="get-property('uri.var.Id')" scope="default" type="STRING"/>
<log>
<property name="ID" expression="get-property('getId')"/>
</log>
<property name="Accept" value="application/json" scope="transport" type="STRING"/>
<property name="messageType" value="application/json" scope="axis2"/>
<payloadFactory media-type="xml">
<format>
<p:getEmployeeXML xmlns:p="arce.farmacy">
<xs:Id xmlns:xs="arce.farmacy">$1</xs:Id>
</p:getEmployeeXML>
</format>
<args>
<arg evaluator="xml" expression="get-property('getId')"/>
</args>
</payloadFactory>
<property name="Action" value="urn:getEmployeeXML" scope="transport" type="STRING"/>
<property name="SOAPAction" value="urn:getEmployeeXML" scope="transport" type="STRING"/>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint>
<address uri="http://169.254.193.10:9763/services/StoredProcedureFarmacy" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
<faultSequence>
<sequence key="{faultSEQ}"/>
</faultSequence>
</resource>
</api>
This is the response
{
"Employees": {
"Employe": [
{
"Id": 5,
"Description": "Office 2"
}
]
}
}
I've tried this on 1.10.0 and 2.0.0
On 1.10.0, you can disable the JMS sender in repository/conf/axis2/axis2_blocking_client.xml and use the call mediator in blocking mode. This is described in this blog post: http://shenavid.blogspot.nl/2016/08/invoking-external-endpoints-using-call.html and works ok. However this method does not work in 2.0.0 even though the related issue is marked as resolved.
Has anyone else tested this on 2.0.0 already? Or found an other workaround?
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="opal_auth_and_send"
onError="gov:apimgt/customsequences/fault/json_fault.xml"
trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property description="ORG_PAYLOAD" expression="$body/child::node()"
name="ORG_PAYLOAD" scope="default" type="STRING"/>
<property description="URL_POSTFIX"
expression="get-property('axis2', 'REST_URL_POSTFIX')"
name="URL_POSTFIX" scope="default" type="STRING"/>
<property action="remove" description="Remove REST_URL_POSTFIX"
name="REST_URL_POSTFIX" scope="axis2"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<header name="Authorization" scope="transport" value="Basic xxxxxxxx"/>
<property description="set messageType" name="messageType"
scope="transport" type="STRING" value="application/json"/>
<call blocking="true" description="Get Auth token (blocking)">
<endpoint>
<http method="get" trace="enable" uri-template="https://opal-demo34.ortec-finance.com/auth/api/token"/>
</endpoint>
</call>
<property description="Get Token from Response"
expression="json-eval($.token)" name="TOKEN" scope="default" type="STRING"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<log description="Log auth result" level="full"/>
<property description="Restore REST_URL_POSTFIX"
expression="get-property('URL_POSTFIX')" name="REST_URL_POSTFIX"
scope="axis2" type="STRING"/>
<payloadFactory description="Restore Payload" media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('ORG_PAYLOAD')"/>
</args>
</payloadFactory>
<header expression="get-property('TOKEN')" name="Authorization" scope="transport"/>
</sequence>
Thanks,
Danny
I am developing a proxy service with a soap webservice that performs soap to rest conversion, the message is sent to a servlet that response with a string in flat format (not xml), just a secuence of characters like
OIUW|ECHNOWE|RFHQWIUE|FBPQW|EFHAO|IEFH
I am invoking with SOAP UI and I get this response fine, now I would like to receive it in "SOAP format", wrapping the message into a soap:body, I've tried with a XSLT and with a PayloadFactory Mediator, but as soon as I use any of them (even doing nothing) I get a
[2014-07-31 09:30:41,847] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
What do I do wrong ? How can I achieve a message transformation without this exception?
Thank you!
UPDATE: My proxy as requested by Ratha
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SCL3"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="custom">
<property name="MyTrace" value="--- REQUEST ---"/>
</log>
<log level="full"/>
<property name="REST_URL_POSTFIX"
value="x4?msg=x4|0003|0000000021|0|0|0400002081020224849"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<send>
<endpoint>
<address uri="http://localhost:8087/X4" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="custom">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<property name="ContentType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<property name="messageType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<a xmlns="">$1</a>
</format>
<args>
<arg value="my value"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:/C:/wso2/wso2esb-4.8.1/repository/workspaces/myproject/SCL3.wsdl"/>
</proxy>
I've seen that my servlet was setting content type to "text/xml" instead of "text/plain", I've changed it to "text/plain" and everything is working fine now.
Therefore I deduce that the error message
"Content is not allowed in prolog"
actually means
"Unexpected content type"
When you have following outsequence configuration what your log prints?
<outSequence>
<log level="full">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<send/>
</outSequence>
i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..