Creating a file using Wso2Esb getting stuck - wso2

Hi am working with Wso2Esb 4.7.0
I have created a proxy which creates a file in the local system, Below is the proxy and its sequence, I have uncommented the required vfs transport in axis2 file.
Proxy service:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FileProxy"
transports="https http"
startOnLoad="true"
trace="enable">
<description/>
<target>
<inSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property name="Body"
expression="$body"
scope="default"
type="STRING"/>
<property name="transport.vfs.ReplyFileName"
expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')"
scope="transport"/>
<payloadFactory>
<format>
<Reading>$1</Reading>
</format>
<args>
<arg evaluator="xml" expression="get-property('Body')"/>
</args>
</payloadFactory>
<property name="OUT_ONLY" value="true"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<send receive="fileWriteSequence">
<endpoint>
<address uri="vfs:file:///home/youtility/Documents/Capp_services/wso2esb-4.7.0/Files"/>
</endpoint>
</send>
</inSequence>
<outSequence onError="fault">
<send/>
</outSequence>
</target>
</proxy>
Sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fileWriteSequence">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<log level="custom">
<property name="sequence" value="fileWriteSequence"/>
</log>
<payloadFactory media-type="xml">
<format>
<ResponseJSON xmlns="">
<Body>
<Datalist>file Created</Datalist>
</Body>
<Status>200</Status>
</ResponseJSON>
</format>
<args/>
</payloadFactory>
<send/>
</sequence>
curl:
curl -v -H "Accept: application/json" -H "Content-Type:application/json" -d '{"test1":"1","test2":"-1","test3":"-1"}' http://localhost:8282/services/FileProxy
When am trying to call this service with the curl file is getting created in the mentioned file location with the given content but am not getting any response as file Created as mentioned in the sequence, Actually after creating the file the process is not going the the fileWriteSequence so it is getting stuck.
Any Suggestions..

You are in OUT_ONLY, (you have set <property name="OUT_ONLY" value="true"/>) and you must be in OUT_ONLY when you create a file because there is no response from the filesystem
Therefore, the "receive" sequence will never be executed : add it's content after the send mediator

Related

WSO2 ESB with DSS integrated doesn't response JSON

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"
}
]
}
}

How to respond with status 500 (server error) when proxy fails?

In our test environment we build a one-way proxy service that uses callout to get data from several other services. Now when one of those services fails wso2 proxy sends 202 accepted anyway. Is it possible to "catch exceptions" and return a different status?
I know that in this case it would be better to use a request-response proxy, but even if we would create a proxy that only stores the payload in a messagestore there could be issues regarding database where the payload would be stored (database is down, etc) and we don't want status 202 to be returned if the message was not stored in db.
edit:
Here is my proxy after changes suggested in first answer to my question:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="notifyOfClaimChangeOut" serviceGroup="" startOnLoad="true"
trace="disable" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property description="OUT_ONLY" name="OUT_ONLY" scope="default"
type="BOOLEAN" value="true"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" scope="default"
type="STRING" value="true"/>
<property description="OriginalPayload" expression="$body"
name="OriginalPayload" scope="default" type="STRING"/>
<iterate description=""
expression="$body//InsClaimData/PartnerList/PartnerEntry" id="" sequential="true">
<target>
<sequence>
<payloadFactory description="" media-type="xml">
<format>
<plat:FindCustomerSync xmlns:plat="http://platform.###.pl/">
<plat:request>
<plat:FirstName>$1</plat:FirstName>
<plat:LastName>$2</plat:LastName>
<plat:Pesel>$3</plat:Pesel>
</plat:request>
</plat:FindCustomerSync>
</format>
<args>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/firstName"/>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/lastName"/>
<arg evaluator="xml" expression="$body/PartnerEntry/BusinessPartner/personData/PESEL"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="$body" name="property_name"/>
</log>
<callout action="http://platform.###.pl/FindCustomerSync"
description="QueryCustomersOut"
endpointKey="gov:###/endpoints/###/QueryCustomersOut.xml" initAxis2ClientOptions="false">
<source type="envelope"/>
<target key="QueryCustomersOutResponse"/>
</callout>
<log description="" level="custom" separator=",">
<property expression="$ctx:QueryCustomersOutResponse"
name="QueryCustomersOut"
xmlns:cla="http://###.###.io/service/internal/ClaimService" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
</log>
</sequence>
</target>
</iterate>
<!--
<callout description="ClaimService"
endpointKey="gov:###/endpoints/###/ClaimService.xml" initAxis2ClientOptions="false">
<source type="envelope"/>
<target key="ClaimServiceResponse"/>
</callout>
<log description="ClaimService Response" level="custom">
<property expression="$ctx:ClaimServiceResponse" name="ClaimServiceResponse"/>
</log>
-->
<drop/>
</inSequence>
<outSequence/>
<faultSequence>
<property name="HTTP_SC" scope="axis2" type="STRING" value="500"/>
<log>
<property name="Error" value="Fault :("/>
</log>
</faultSequence>
</target>
<publishWSDL key="gov:###/schemas/###/ClaimService.wsdl"/>
</proxy>
You can use the HTTP_SC property to send status 500. You'll also need the makefault mediator to construct the fault message.
<property name="HTTP_SC" value="500" scope="axis2"/>
<makefault version="soap11">
You can refer this jira to get an idea.
In addition, in the inSequence, you may need to set FORCE_ERROR_ON_SOAP_FAULT property to move to the fault sequence when a soap fault occurs. Some explanation available here.
<inSequence>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
</inSequence>

How to send to multiple endpoints in wso2esb

I am using wso2esb-4.8.1,
I wish to log the transaction details after response back to client.
For that I have written Proxy as well as sequence but wso2esb-4.8.1 is not supporting that with send mediator ,because I want t use load balance for every endpoint where as same logic is working in CallOUt mediator with URL option not with address endpoint .
proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_Proxy" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="ProxyInRequest"
expression="/soapenv:Envelope"/>
</log>
<xquery key="ProxyRequestTransformation">
<variable xmlns:ns="http://org.apache.synapse/xsd" name="Operation" expression="//Operation/text()" type="STRING"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceNameSpace" expression="//ServiceNameSpace/text()" type="STRING"/>
<variable name="Payload" type="DOCUMENT_ELEMENT"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceName" expression="//Service/text()" type="STRING"/>
</xquery>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
<send/>
<sequence key="AuditSeq"/>
</outSequence>
</target>
<publishWSDL key="EaiEnvelope"/>
</proxy>
In above proxy i have used default send mediator after that trying to do audit in same flow ,My client is getting response back but details are not auditing even not getting any error.
My sequence
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditSeq"> <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_CODE" expression="get-property('ResultCode')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_MESSAGE" expression="get-property('ResultMessage')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="REFERENCE_ID" expression="get-property('ReferenceID')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="FAULT_DETAILS" expression="concat(get-property('ERROR_CODE'),get-property('ERROR_MESSAGE'))" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<open:processRequest xmlns:open="http://www.openuri.org/">
<aud:Auditor xmlns:aud="http://jhm.kkk.fff/Auditor">
<aud:Request>
<aud:Operation_Name>processRequest</aud:Operation_Name>
<aud:Auditor_InputData>
<aud:Result_Code>$1</aud:Result_Code>
<aud:Result_Message>$2</aud:Result_Message>
<aud:Reference_Id>$3</aud:Reference_Id>
</aud:Auditor_InputData>
</aud:Request>
</aud:Auditor>
</open:processRequest>
</format>
<args>
<arg evaluator="xml" expression="get-property('RESULT_CODE')"/>
<arg evaluator="xml" expression="get-property('RESULT_MESSAGE')"/>
<arg evaluator="xml" expression="get-property('REFERENCE_ID')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="http://www.openuri.org/processRequest"/>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
</endpoint>
</send>
<log>
<property name="aftersend" value="message going out or not"/>
</log>
</sequence>
With above send mediator is not working .But after send my log is printing.
If i replace send mediator with CallOut URL option its working fine.
<callout serviceURL="http:///localhost:8081/middleware/services/AuditService">
<source type="envelope"/>
<target key="IsThisResponse"/>
</callout>
In above we are not able to use loadbalancing.For that I trying for send mediator.
Is any way to do this.
I thouhgt wso2esb-4.8.1 is become stable but again its having drawbacks.
Thanks in advance.
Please try by changing the send mediator in your proxy as mentioned here it may help you
<send receive="AuditSeq">
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>

WSO2 ESB Content is not allowed in prolog exception in a OutSecuence

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>

Is it possible with WSO2ESB to send E-Mail Using Header

i wish to send a e-mail to my client using Header mediator .
Is it possible with that or not
My proxy like this
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Mail"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log/>
<property name="workpartybranchid"
expression="//workpartybranchid/text()"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:SelectMail_Op xmlns:p="http://ws.wso2.org/dataservice">
<p:workpartybranchid>$1</p:workpartybranchid>
</p:SelectMail_Op>
</format>
<args>
<arg expression="get-property('workpartybranchid')"/>
</args>
</payloadFactory>
<send receive="Mailseq">
<endpoint>
<address uri="http://192.168.1.4:9773/services/muser_DataService/"
format="soap11"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy
and corresponding sequence is
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Mailseq" onError="fault">
<property name="CONTENT_TYPE"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:s="http://ws.wso2.org/dataservice"
name="primarymail"
expression="//s:primarymail/text()"
scope="axis2"
type="STRING"/>
</log>
<header name="To" expression="fn:concat('mailto:', get-property('primarymail'))"/>
<send/>
<log>
<property name="mail" value="ts working"/></log>
</sequence>
can we send a email like this i have got reference from this
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
i am posted my requirement in another way also please refer this
Can we send Multiple Mail in wso2esb in same sequence or dynamically set a mail
Just follow the step in below URL ( but rather than header part, use endpoint for this as below.. this worked for me)
http://docs.wso2.org/wiki/display/ESB460/Sample+256%3A+Proxy+Services+with+the+Mail+Transport
Add Send for mail as below...( no need header mediator)
<send> <endpoint>
<address uri="mailto:yourmailaddr#gmail.com" />
</endpoint>
</send>