I used WSO2 ESB 5.0. I used two soap endpoints to get the response. Below mention the proxy service code.
<?xml version="1.0" encoding="UTF-8"?>
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<log/>
<property expression="//sam:getCertificateID/sam:vehicleNumber"
name="getVehicleNo" scope="default" type="STRING" xmlns:sam="http://sample.esb.org"/>
<log>
<property expression="get-property('default','getVehicleNo')" name="VehicleNo"/>
</log>
<call>
<endpoint>
<wsdl port="EmissionTestServiceHttpSoap11Endpoint"
service="EmissionTestService" uri="http://172.17.0.1:9763/services/EmissionTestService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getCertificateIDResponse/ns:return"
name="getCertificateIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getCertificateIDResponse')" name="CertificateID"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sam="http://sample.esb.org" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sam:getPolicyID>
<sam:vehicleNumber>$1</sam:vehicleNumber>
</sam:getPolicyID>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('default','getVehicleNo')"/>
</args>
</payloadFactory>
<log/>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<call>
<endpoint>
<wsdl port="InsuranceServiceHttpSoap11Endpoint"
service="InsuranceService" uri="http://172.17.0.1:9763/services/InsuranceService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getPolicyIDResponse/ns:return"
name="getPolicyIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getPolicyIDResponse')" name="PolicyID"/>
</log>
</inSequence>
First endpoint is working fine and gave the specific log messages. But when going to call second endpoint, below error message is occurred.
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found faultstring
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:148)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:137)
... 14 more
Can you help me to solve this issue. Any help or workarounds are really appreciated.
Your endpoint is not returning an soap Envelope. You can see what's happening if you set 'configure->logging->apache.synapse.tranport.http.wire' to 'debug'.
Because the endpoint is not returning SOAP, but likely plain old XML you can try setting
<property name="messageType" value="application/xml" scope="axis2"/>
<property name="ContentType" value="application/xml" scope="axis2"/>
before sending the message.
Related
I'm using WSO2 EI 6.3v.I want to pass application/x-www-form-urlencoded data to the rezlive hotel Supplier. In hear i put my code and response.
CODE
<inSequence>
<log category="WARN" level="full">
<property name="API BEGIN" value="Test_Supplier API"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<HotelFindRequest xmlns="">
$1
</HotelFindRequest>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$env/*[local-name()='Body']/*[local-name()='HotelFindRequest']/*"/>
</args>
</payloadFactory>
<property expression="$env/*[local-name()='Body']/*" name="xmlbody" scope="default" type="STRING"/>
<log>
<property expression="$ctx:xmlbody" name="Body======="/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
<property expression="$body" name="payload" scope="default" type="STRING"/>
<property name="uri.var.url" scope="default" type="STRING" value="http://test.xmlhub.com/testpanel.php/action/findhotel"/>
<call>
<endpoint>
<address format="pox" uri="http://test.xmlhub.com/testpanel.php/action/findhotel?XML={xmlbody}"/>
</endpoint>
</call>
<respond/>
</inSequence>
Body Log
<HotelFindRequest>
<Authentication>
<AgentCode>xxxxxxx</AgentCode>
<UserName>xxxxx</UserName>
<Password>xxxxxx</Password>
</Authentication>
<Booking>
<ArrivalDate>22/05/2019</ArrivalDate>
<DepartureDate>25/05/2019</DepartureDate>
<CountryCode>AE</CountryCode>
<City>968</City>
<GuestNationality>LK</GuestNationality>
<HotelRatings>
<HotelRating>1</HotelRating><HotelRating>2</HotelRating>
<HotelRating>3</HotelRating><HotelRating>4</HotelRating>
<HotelRating>5</HotelRating>
</HotelRatings>
<Rooms>
<Room>
<Type>Room-1</Type>
<NoOfAdults>2</NoOfAdults>
<NoOfChilds>0</NoOfChilds>
</Room>
<Room>
<Type>Room-2</Type>
<NoOfAdults>1</NoOfAdults>
<NoOfChilds>0</NoOfChilds>
</Room>
<Room>
<Type>Room-3</Type>
<NoOfAdults>2</NoOfAdults>
<NoOfChilds>0</NoOfChilds>
</Room>
<Room>
<Type>Room-4</Type>
<NoOfAdults>3</NoOfAdults>
<NoOfChilds>0</NoOfChilds>
</Room>
</Rooms>
</Booking>
Response comming as
<HotelFindResponse>
<error>Please provide agentcode.</error>
<error>Please provide username.</error>
<error>Please provide password.</error></HotelFindResponse>
But I pass same configuration in POSTMAN, give me the correct response.
I put the same configuration in Postman. I tried so meny ways to get response.All are failed.
What is wrong with that code?.
Please help.
Can you try with HTTP endpoint (https://docs.wso2.com/display/EI640/HTTP+Endpoint) using post?
Payload factory already sets the body, so it should work right away as it will try to post it.
Try using "uri.var.xmlBody" property name instead of simple "xmlBody":
<property expression="$env/*[local-name()='Body']/*" name="uri.var.xmlBody" scope="default" type="STRING"/>
<call>
<endpoint>
<address format="pox" uri="http://test.xmlhub.com/testpanel.php/action/findhotel?XML={uri.var.xmlBody}"/>
</endpoint>
</call>
Can you try this? from here
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root xmlns="">
<XML>$1</XML>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:xmlbody"></arg>
</args>
</payloadFactory>
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"></property>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"></property>
<call>
<http method="post" uri-template="test.xmlhub.com/testpanel.php/action/findhotel"/>
</call>
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
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
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>
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>