Create a REST proxy for SOAP service in wso2 esb - rest

We have a SOAP service that I want to proxy in WSO2 ESB. This is for POC that I am working on. I came across various documents and some explanation on forums but nothing concrete yet. I looked at API option but couldn't get anything to work. Whats the best way to do this? Can the transformation occur in esb itself or is the api the only option? Please advise.

You can better choose RESTAPI option.
Here is the documentation for that

What do you mean by couldn't get this working? This is not a big configuration, you need to define your proxy service such that you send the message (REST message) to the back end as a SOAP message. Here is a sample configuration.
<proxy name="StockQuoteProxy" transports="http https" startOnLoad="true">
<target>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"
format="soap11"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
You can call this proxy in REST manner and it will automatically send the message to the backend SOAP service.
you can do it with the sample axis2 client as below.
ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Drest=true

Related

WSO2 Data Service, Enterprise Integrator and Data Mapper mediator

I have created a Data Service (DS) and expose the data as a REST resource. and I could successfully retrieve data via CURL command given below.
curl -X GET -H "Accept: application/json" http://localhost:8280/services/TestDataService.HTTPEndpoint/Member/0
The REST API resource template is Member/{MemberID} - DS Endpoint
The response is,
{"Members":{"Email":"example#test.com","FirstName":"Mad","MembershipCategory":"Gold","InsuranceType":"Health","LastName":"Tim"}}
Then I wanted to convert this JSON response to a CSV using WSO2 EI's Data Mapper mediator. I know there are alternative ways to achieve this usecase via other mediators or WSO2 API manager.
I created another API resource in WSO2 EI which has the template
/convertDetails/Member/{MemberID} - EI Endpoint
Anyhow, with following configurations, I could not get the correct response when I call the REST API resource from a REST client.
Following is my mediation flow,
<?xml version="1.0" encoding="UTF-8"?>
<api context="/convertDetails" name="MemberDetailsConversion" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/Member/{MemberID}">
<inSequence>
<log description="Request Log" level="full"/>
<send>
<endpoint>
<http method="get" uri-template="http://localhost:8280/services/TestDataService.HTTPEndpoint/Member/{uri.var.MemberID}"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<datamapper config="gov:datamapper/MemberDetailsMapping.dmc" inputSchema="gov:datamapper/MemberDetailsMapping_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/MemberDetailsMapping_outputSchema.json" outputType="CSV"/>
<log description="Response Log" level="full"/>
<respond/>
</outSequence>
<faultSequence/>
</resource>
</api>
But still when I invoke the EI REST resource endpoint, http://localhost:8280/convertDetails/Member/0, it give me an ERROR.I have extracted the first few lines of the stack below.
[2018-11-01 10:30:30,817] [EI-Core] ERROR - DBInOutMessageReceiver Error in in-out message receiver
DS Code: INCOMPATIBLE_PARAMETERS_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'CallQuery.extractParams', cannot find parameter with type:query-param name:MemberID
DS Code: INCOMPATIBLE_PARAMETERS_ERROR
Source Data Service:-
Name: TestDataService
Location: /Users/mad/Documents/wso2ei-6.3.0/wso2/tmp/carbonapps/-1234/1541088489969TestDataServiceProjectCompositeApplication_1.0.0.car/TestDataService_1.0.0/TestDataService-1.0.0.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: _getmember_memberid
Current Params: {}
I'm assuming that I have missed something along the configuration. Would appreciate your help regarding this.

Wso2 API Manager : Soap Service | How to Default SoapAction

How to set default SoapAction value for a soap service configured on wso2 api managaer 2.1.0.
For Soap services we do not have option to edit swagger definition:
please advise how do i default the value of soap action, in our scenario it is not relevant. if there is way to remove from ui and set default value for all api call that would also work. thank you.
If it's SOAP 1.2 you can simply ignore Soap Action.
If it's SOAP 1.1, you can have a custom mediation sequence and set SOAPAction http header like this.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--sample">
<property name="SOAPAction" scope="transport" expression="YourSoapActionHere"/>
</sequence>
If you want to modify the UI, you'll have to tweak this file.
repository/deployment/server/jaggeryapps/store/site/themes/wso2/templates/api/swagger/swagger/swagger-ui{.min}.js

Received sun.net.www.protocol.http.httpurlconnection$httpinputstream as response while calling service which is unable to process

I'm developing workflow application in Apache camel
Business Use case:
Service is exposed at consumer endpoint
Processing with request message
Call external SOAP Service, get the response
check particular tag in response xml and then only call another external SOAP Service
Return the final response to client
Now I got stuck in step 4
My camel Route is
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route streamCache="true">
<from uri="cxf:bean:proxyEndpoint"/>
<process ref="myProcessor"/>
<!-- processing request & logging -->
<setBody>
<!-- set request as body required for calling external web service -->
</setBody>
<to uri="cxf:bean:panEndpoint"/>
<!-- <to uri="file:C:/LOG" /> -->
<!-- <process ref="myProcessor2"/> -->
<log message=">>> ${body}" loggingLevel="INFO"/>
</route>
</camelContext>
I'm able to call external Service but after <to uri="cxf:bean:panEndpoint"/> if I try to log body I'm getting arbitrary value same in case of routing to file.
When I tried to route to Processor and print System.out.println(exchange.getIn().getBody());
I'm getting sun.net.www.protocol.http.httpurlconnection$httpinputstream which I'm unable to parse or process
External Service is called and proper response is receiving as I tried to monitor the scenario using TCP-IP Monitor
Any help will be appreciated.
Tell Camel what type you want the body as, and it uses its type converter to make that happen (if possible).
So if you want the body as a InputStream do
exchange.getIn().getBody(InputStream.class)
If you want it as String, then do
exchange.getIn().getBody(String.class)
Read more here
http://camel.apache.org/type-converter.html
And when working with streams mind about stream caching
http://camel.apache.org/stream-caching.html

Accessing restful services from wso2dss to wso2esb

I'm using wso2dss 3.1.0 and wso2esb 4.7.0..I have created a restful dataservice in dss and it's working fine for all operations like get,post,update and delete.Now I wish to user this dataservice in esb..for this i have created a proxy with following configuration :
<target>
<endpoint>
<address uri="http://192.168.1.23:9764/services/A_resttest/"
format="soap11"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
And tried to execute with curl command like this :
curl -v -H "Accept: application/json" http://youtility-desktop:8282/services/RestTest1
But it showing warning and error like :
WARN - SourceHandler Connection time out after request is read: http-incoming-1
ERROR - NativeWorkerPool Uncaught exception
java.lang.NullPointerException
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:156)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
WARN - SourceHandler Connection time out after request is read: http-incoming-2
I have referred https://docs.wso2.org/display/ESB460/Using+REST+with+a+Proxy+Service.
Is the procedure is correct or their is problem in curl command?Please let me know..I have tried this by creating api also but showing same error..Should i uncomment any code in axis2 file?
Are you going to expose the DSS service via SOAP using ESB? If not, I'd like to suggest that you create ESB REST API instead of a proxy service to expose the DSS service.
Secondly, you have set format="soap11" for the dss service endpoint. But as I understand from your question, you need to use rest format instead of soap 1.1. So, change the format to format="rest" or format="pox" depending on your requirement.

Wso2 Restful API

I have been given a REST URI from my client which is as follows:
https://vm3.digitary.net/verifier/HEDDRequestDocumentAccess
Following request xml has to be POSTed to the above URI to get the response xml.
<documentAccessRequest xmlns="http://www.digitary.net/schema/dare/hedd/documentAccessRequest/2013" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.digitary.net/schema/dare/hedd/documentAccessRequest/2013 http://www.digitary.net/schema/dare/hedd/documentAccessRequest/2013">
<head>
<institutionCode>BBCU</institutionCode>
<username>HEDDUser</username>
<password>HEDDPass</password>
</head>
<body>
<heddEnquiryId>12347895844</heddEnquiryId>
<enquiree>
<email>jane#doe.com</email>
<firstName>Jane</firstName>
<lastName>Doe</lastName>
</enquiree>
<enquirer>
<organisation>BBC</organisation>
<contactName>Jeremy Clarkson</contactName>
</enquirer>
<documentRequested>HEAR</documentRequested>
</body>
</documentAccessRequest>
Now I have the requirement to make my own wrapper REST API in WSO2 ESB 4.6.0 which would simply call the above mentioned REST URI having the same request and response XML. The idea is to make the pass through REST API to above mentioned API.
I have implemented the following REST API:
<api xmlns="http://ws.apache.org/ns/synapse" name="TestDareRest" context="/documentRequest" hostname="46.137.187.137" port="8280">
<resource methods="POST" url-mapping="/request/*">
<inSequence>
<log/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<send>
<endpoint>
<address uri="https://vm3.digitary.net/verifier/HEDDRequestDocumentAccess" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log/>
<property name="ContentType" value="application/xhtml+xml" scope="axis2"/>
<send/>
</outSequence>
</resource>
</api>
But above API is not working at all and it is gving loads of errors in the esb console. I am using the SOAPUI to test this REST service and posting the same request xml from there. The service is deployed on our public Ip server and can be seen by login in to following
https://46.137.187.137:9443/carbon/admin/index.jsp with username/pwd as admin/admin
I have tried setting both media type in SOAPUI as text/xml and application/xml
In case of text/xml it is giving error as follows:
org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found documentAccessResponse
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
In case of application/xml it is giving following error
INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:53a782ab-2081-4cb1-9e94-910b75816361, Direction: response
[2013-04-10 16:05:12,911] ERROR - PassThroughHttpSender Failed to submit the response
java.lang.UnsupportedOperationException
Please help me with this issue as it has got much critical to me.
Thanks in Advance
Shakshi
Can you switch the transport to nonblocking transport and check?
You can change the transport sender and receiver in the axis2.xml.
The media type is to be application/xml ..not the text/xml, which is used fro soap requests.
To post a request you can use curl utility.
# curl -X POST -d #request.xml "URL"