I would like to expose an API (REST) on ESB that traslate the request to a SOAP service.
My Api is definined in this way :
<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest">
<resource methods="GET" uri-template="/{symbol}">
<inSequence>
<property name="symbol" expression="get-property('uri.var.symbol')"/>
<payloadFactory media-type="xml">
<format>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:request>
<xsd:symbol>$1</xsd:symbol>
</ser:request>
</ser:getQuote>
</format>
<args>
<arg evaluator="xml" expression="get-property('symbol')"/>
</args>
</payloadFactory>
<log level="full"/>
<send>
<endpoint>
<wsdl service="SimpleStockQuoteService" port="SimpleStockQuoteServiceHttpEndpoint"
uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
But when i invoke the url with http://:8280/mytest/WSO2 I heve this error on console
<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">
The endpoint reference (EPR) for the Operation not found is /services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpEndpoint/WSO2?request= and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
</soapenv:Text>
</soapenv:Reason>
Because the esb append the WSO2 part of the request to URL.
How I can solve this ?
Thanks
You can follow this guide for achieving this. Note that the soap action header should be added as follows and endpoint is different.
<header name="Action" value="urn:getQuote"/>
Find the complete solution API below,
<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest"><resource methods="GET" uri-template="/{symbol}">
<inSequence>
<property name="symbol" expression="get-property('uri.var.symbol')"/>
<payloadFactory media-type="xml">
<format>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:request>
<xsd:symbol>$1</xsd:symbol>
</ser:request>
</ser:getQuote>
</format>
<args>
<arg evaluator="xml" expression="get-property('symbol')"/>
</args>
</payloadFactory>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<log level="full"/>
<header name="Action" value="urn:getQuote"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
</endpoint>
</send>
</inSequence></resource></api>
If you want to use the WSDL url directly, you can achive this using WSO2 API Manager and it can be easily tried in WSO2 API Cloud. There is a similar question here.
Related
I want to use this expression in WSO2 property mediator
sum(//datas//queryResponse[CODEAGENCE='01003']//NOMBER)
I have done this to count without apply filter
fn:sum($ctx:datas//*[local-name()='queryResponse']//*[local-name()='NOMBRE'])
Your question is unclear. Do you want to count sum of NOMBRE field, using xquery on a property, that contains XML? If so, here is a sample API. You can call it from POSTMAN or browser http://{YourWSO2SErver}:8280/Test/testSO_57326564
The result is {"sum":"340.0"} on sample data.
Please note, that the property "datas" has OM type.
<api xmlns="http://ws.apache.org/ns/synapse" name="Test" context="/Test">
<resource methods="GET" uri-template="/testSO_57326564">
<inSequence>
<log level="full"/>
<payloadFactory media-type="xml">
<format>
<datas xmlns="">
<queryResponse>
<CODEAGENCE>01003</CODEAGENCE>
<NOMBRE>100</NOMBRE>
</queryResponse>
<queryResponse>
<CODEAGENCE>01003</CODEAGENCE>
<NOMBRE>240</NOMBRE>
</queryResponse>
<queryResponse>
<CODEAGENCE>01002</CODEAGENCE>
<NOMBRE>10000000</NOMBRE>
</queryResponse>
</datas>
</format>
<args/>
</payloadFactory>
<property name="datas" expression="$body/*[1]" type="OM" description="property must be an OM type"/>
<property name="sum" expression="fn:sum($ctx:datas//queryResponse[CODEAGENCE=01003]/NOMBRE)"/>
<payloadFactory media-type="json">
<format> {"sum":"$1"} </format>
<args>
<arg evaluator="xml" expression="get-property('sum')"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
</resource>
</api>
I'm using wso2ei 6.0.0 and I have a simple task - send specific xml message via POST to the endpoint.
I have API configured like this:
<api xmlns="http://ws.apache.org/ns/synapse" name="glisTest" context="/glisTest">
<resource methods="GET" uri-template="/{sampleid}">
<inSequence>
<property name="PRESERVE_WS_ADDRESSING" value="false"/>
<payloadFactory media-type="xml">
<format>
<register />
</format>
</payloadFactory>
<log level="full"/>
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="https://localhost/manager" encoding="UTF-8" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</resource>
</api>
But service is expected
<?xml version="1.0" encoding="UTF-8" ?>
to be inserted at the beginning and wso2 do not do it (I just added debug logging for org.apache.synapse.transport.http.wire and I see it simple send
<register/>
As result, it does not recognize message as an xml and returm me error.
Question - how to tell synapse to add this special xml header to the message?
I need to get a pdf from a request to my WSO2 esb. This is my scenario:
Request:
CMS -- Request ----> wso2 ESB ----> backend
Response:
CMS <--- (PDF) --- wso2 ESB <--- PDF Byte Array --- backend
I think that I need to use something like 'aplication/pdf' but when I try to do it, my ESB throws a java error. The following is my code:
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/myService">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://backendService/getPDF""></http>
</endpoint>
</call>
<loopback/>
</inSequence>
<outSequence>
<property name="messageType" value="application/pdf" scope="axis2"/>
<property name="ContentType" value="application/pdf" scope="axis2" type="STRING"></property>
<send/>
</outSequence>
<faultSequence></faultSequence>
</resource>
</api>
Any idea?
--- SOLUTION ---
It was really easy and stupid, but I post my solution to avoid that someone waste time in the future:
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/myService">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://backendService/getPDF""></http>
</endpoint>
</send>
</inSequence>
<faultSequence></faultSequence>
</resource>
</api>
With this code I just returns the same request that I do to the server, so I get my PDFs files :D
I am working on sample application in WSO2 esb
which connects to Oracle Database and return the response of a query. Below mentioned is my service. Issue I am facing is I am not getting the response back after execution of service.However I am able to see the value returned as a query response, but not able to render it in response document.
Can anybody suggest, what I am missing?
DB credentials fields have been hashed.
Proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="getEmployeeDetails"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="BOOLEAN"/>
<log level="full" category="DEBUG"/>
<dblookup>
<connection>
<pool>
<password>****</password>
<user>****</user>
<url>****</url>
<driver>oracle.jdbc.xa.client.OracleXADataSource</driver>
</pool>
</connection>
<statement>
<sql>select firstname from employee where lastname = 'pawar'</sql>
<result name="firstname" column="firstname"/>
</statement>
</dblookup>
<log level="custom">
<property name="firstname" expression="get-property('firstname')"/>
</log>
<payloadFactory media-type="xml">
<format>
<GetEmployeeDetailsResponse xmlns="">
<out>$1</out>
</GetEmployeeDetailsResponse>
</format>
<args>
<arg evaluator="xml" expression="get-property('firstname')"/>
</args>
</payloadFactory>
</inSequence>
<outSequence>
<log level="full" category="DEBUG"/>
</outSequence>
</target>
<publishWSDL uri="file:/development/data/wso2/wsdl/Employee.wsdl"/>
<description/>
</proxy>
You have to send back the message generated by your payloadFactory in your inSequence :
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
Your mediation is "OUT_ONLY", so, your outSequence will never been executed
I am trying to make an API at WSO2 ESB 4.7.0 to process requests for a RESTful service. It seems that the URL-Mapping feature is not working or is working just like a filter, choosing what to send to the endpoint and what to drop. I have followed this tutorial: http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/. Here is my API configuration:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
There are three situations:
This URL works: http://esb/rest
This URL doesn't work: http://esb/rest/numbers
This URL works: http://myserver/REST/allnumbers
In situation 2, I got an Apache Tomcat error:
HTTP Status 404 - Not Found
type Status report
message Not Found
description The requested resource (Not Found) is not available.
Apache Tomcat/6.0.32
But if I try the endpoint address, it works. I thought that the URL-Mapping would route requests for "/numbers" to "/allnumbers". What am I doing wrong?
Solved! I had to remove the REST_URL_POSTFIX before sending to the endpoint:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Now, http://esb/rest/numbers works too! :)