I have a service returns a text/plain content. The response message like:
RESP0Success"
But in ESB4.0.3, the response is like:
<text xmlns="http://ws.apache.org/commons/ns/payload"><?xml version="1.0" encoding="UTF-8"?><message><MsgType>RESP</MsgType><ReturnCode>0</ReturnCode><ReturnMessage>Success</ReturnMessage></message>
</text>
I set builder and formatter in axis2.xml. But no use.
<messageBuilder contentType="text/plain"
class="org.apache.axis2.format.PlainTextBuilder"/>
<messageFormatter contentType="text/plain"
class="org.apache.axis2.format.PlainTextFormatter"/>
Can anyxone tell me how to set the builder and formatter in axis2.xml? My service config is:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TextPlain" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="ContentType" value="text/plain" scope="axis2" />
<log level="full" />
</inSequence>
<outSequence>
<log level="full" />
<property name="ContentType" value="text/plain" scope="axis2" />
<send />
</outSequence>
<endpoint>
<address uri="http://172.20.28.206:8080/AAAService/recieveMsg" format="pox">
</address>
</endpoint>
</target>
</proxy>
I've had the same problem, then I set
<property name="messageType" value="text/plain" scope="axis2"/>
and now it works, if i call it from URL, it will return only text.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="RESTE" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" value="text/plain" scope="axis2"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://10.15.21.189:8180/contadorServicos/ola-mundo"/>
</endpoint>
</target>
<parameter name="serviceType">proxy</parameter>
<description></description>
</proxy>
Unfortunattely the Tryit functionality stoped working, now it giver the following error.
<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">Erro no processamento de XML: formatação incorreta Posição: http://xxxxxxx/services/RESTE?tryit# Número da linha 1, coluna 221:
<sourcetext><TryitProxyError h:status='SOAP envelope error' xmlns:h='http://wso2.org/ns/TryitProxy'>org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'r' (code 114) in prolog; expected '<'at [row,col {unknown-source}]: [1,1]</TryitProxyError> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^</sourcetext>
</parsererror>
p.s: When I use other tools like SOAPUI, it works correctly.
You need to specify the ContentType of your message. As the input from the HTTP will contain the Soap envelope and body, your content is being included inside such a tag.
When you now tell your endpoint, that the message is of type text/plain, the PlainTextFormatter will convert it to real text and send it your endpoint (the axis2.xml is only the config - now you need to tell that you want to use now the PlainTextFormatter)
This line is missing:
<property name="ContentType" value="text/plain" scope="axis2"/>
Related
In wso2 ESB, I am able to send data to WebSocket but I am not able to receive data.
I tried this with rest api of wso2 esb.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<log level="full">
<property name="message" value="********************************************input**********************"/>
</log>
<send>
<endpoint>
<http method="post" uri-template="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
outsequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="************************************************"/>
</log>
</sequence>
with the above API, I am able to send data to the server as shown in below image.
Http request from postman.
But as shown in below image of the console, the response which i am getting is empty as no body present.
If I use proxy service with content-type mentioned as in esb documentation(link) in websocket server i am getting exception
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="dispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<property name="websocket.accept.contenType" scope="axis2" value="text/plain"/>
<send>
<endpoint>
<address uri="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</sequence>
axis2.xml websocket configuration is:
<transportSender name="ws" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
<parameter name="ws.outflow.dispatch.sequence" locked="false">outflowDispatchSeq</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence" locked="false">outflowFaultSeq</parameter>
</transportSender>
So how to send and receive the data from websocket
I want to get text from following Envelope so that I can use it as REST_URL_POSTFIX.
I am sending a plain text message to a JMS queue and following WSO2-ESB proxy service is used as a receiver/listener of JMS queue. I have tried following expressions but they does not work :
$body
$body/text
$body/text()
The SOAP 1.1 or 1.2 body element. For example, the expression
$body/getQuote refers to the first getQuote element in a SOAP body,
regardless of whether the message is SOAP-11 or SOAP-12.
and
//Envelope//Body//text
//Envelope//Body//text()
INFO - (Send
LogMediator To: , MessageID: ID:sunnydyal-K55VM-44230-1439804805911-3:2:1:1:9,
Direction: request, ##### Message = ,
Envelope:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<axis2ns8:text xmlns:axis2ns8="http://ws.apache.org/commons/ns/payload">Test</axis2ns8:text>
</soapenv:Body>
</soapenv:Envelope>
#Proxy Service:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JmsToRestProxy"
transports="jms"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<property name="REST_URL_POSTFIX"
expression="//Envelope//Body//text"
scope="axis2"
type="STRING"/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
</case>
<case regex="POST">
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
</case>
<default/>
</switch>
<log level="full">
<property name="##### Message" expression="$body/text"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:8080/Rest/rest" format="rest"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/plain</default>
</rules>
</parameter>
<description/>
</proxy>
text node belong to a specific namespace "http://ws.apache.org/commons/ns/payload" :
<log level="full">
<property xmlns:syn="http://ws.apache.org/commons/ns/payload" name="##### Message" expression="$body/syn:text/text()"/>
</log>
You can get the body using the $body variable[1]. /text() is trying to access the text element of the body which doesn't exist.
<log level="custom">
<property name="Body" expression="$body" />
</log>
[1] - https://docs.wso2.com/display/ESB481/Synapse+XPath+Variables#SynapseXPathVariables-$body
My goal is to put messages that return a soap error on a queue, in order to retry them later.
I have nearly all working, but the most important part : I can't access the original message from the fault sequence of my proxy :(
I first made a proxy service that returns an error for a given value, or OK for the other values :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxyService" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="custom">
<property name="TestProxyService" value="InSequence"/>
</log>
<switch xmlns:bnc="http://bnc.org/" source="//bnc:id">
<case regex="1">
<log level="custom">
<property name="TestProxyService" value="Send Error !"/>
</log>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="ERROR ERROR ERROR"/>
<detail>ERROR</detail>
</makefault>
<respond/>
</case>
<default>
<log level="custom">
<property name="TestProxyService" value="No Error"/>
</log>
<log level="custom">
<property name="id" expression="//bnc:id"/>
</log>
<payloadFactory media-type="xml">
<format>
<bnc:response>OK</bnc:response>
</format>
<args/>
</payloadFactory>
<respond/>
</default>
</switch>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>
And it works fine
I then made another proxy, that uses the first one as an endpoint to test the queuing on error :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="QueuingProxyService" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<send>
<endpoint key="TestProxyServiceEndpoint"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<store messageStore="No1MessageStore"/>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="There has been an error"/>
<detail>We will retry later</detail>
</makefault>
<send/>
</faultSequence>
</target>
</proxy>
The message that is stored is the one made by the makefault in the TestProxy
I tried to save the original message in a property (in the inSequence) with
<property name="OriginalBody" expression="$body" scope="axis2" type="OM"/>
but in the faultSequence, when i do this :
<log level="custom">
<property name="OriginalBody" expression="get-property('OriginalBody')"/>
</log>
I got null as a result :(
Does anyone have an idea ?
Thanks !
remove scope "axis2" when defining property "OriginalBody" or explicitely specify scope="default" :
<property name="OriginalBody" expression="$body" type="OM"/>
My desired sequence is the following:
Read message from queue
Transform
Make an SOAP call
Output SOAP response to another queue
Steps 1,2,3 work fine but when the message sent in Step 4, that I'm intending to contain the SOAP response, is empty. What am I doing wrong?
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JmsToWsdlJms" transports="https,http,jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="jms_body_text"/>
</enrich>
<property name="jms_body_text"
expression="get-property('jms_body_text')"
scope="default"/>
<xslt key="jmsMsgToSoapMsg_xslt">
<property name="jms_text" expression="get-property('jms_body_text')"/>
</xslt>
<log level="full">
<property name="After transformation" value="****"/>
</log>
<send>
<endpoint key="axisStockQuote"/>
</send>
<log level="full">
<property name="After callout" value="****"/>
</log>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint key="jmsQueue2"/>
</send>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/plain; charset=ISO-8859-1</default>
</rules>
</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.Destination">cn=tro_Q_JMS1</parameter>
</proxy>
You can use 'send receive' instead of the send mediator. Something like,
<send receive="jmsQueue2Sequence">
<endpoint key="axisStockQuote"/>
</send>
So that the response of axisStockQuote will be sent to the jmsQueue2Sequence. Refer [1] for more info.
[1] https://docs.wso2.com/display/ESB481/Send+Mediator
with wso2esb 4.7.0 i deployed the following service to perform a proxy and expose the same json i get from a different server:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="crmws"
transports="http"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="messageType" value="text/xml" scope="axis2"/>
<cache id="c1"
scope="per-host"
collector="false"
hashGenerator="org.wso2.caching.digest.DOMHASHGenerator"
timeout="6"
maxMessageSize="10000">
<implementation type="memory" maxSize="10000"/>
</cache>
<send>
<endpoint>
<address uri="http://crm/backoffice/webservice.php" format="rest">
<timeout>
<duration>3000</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" value="application/json" scope="axis2"/>
<cache id="c1" scope="per-host" collector="true"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
i then try to implement some cache functionality, but even if first connection goes well, when i hit cache i get an empty answer with text/xml content-type.
UPDATE 20131204
I try again after 4.8.0 release and then enabling cache i get the full representation of my json in xml when i hit cache
anyone know where i have to look to fix this issue?
regards,
try adding the following property in your insequence.
eg:
<inSequence>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
---------------------------