WSO2 Data Service, Enterprise Integrator and Data Mapper mediator - rest

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.

Related

WSO2 : "Error connecting to Back end" when testing Integration Solution

Hello everyone,
I deployed WSO2 APIM on a kubernetes cluster which includes the micro integrator, and I used Integration Studio locally to develop my first integration solution.
I followed these steps:
Configured the service catalog in Integration Studio using the ingress address of the APIM
The service appears inside the services tab
I created an API out of that service
Error : When I try testing the API I get the following error "Error Connecting to Back end"
I think the service url may be the problem, I tried using the ingress address for the Micro Integrator but it didn't work
The following is my configuration:
metadata.yaml file
---
key: "HelloWorld-1.0.0"
name : "HelloWorld"
displayName : "HelloWorld"
description: "Sample API"
version: "1.0.0"
serviceUrl: "https://localhost:8290/sample"
definitionType: "OAS3"
securityType: "BASIC"
mutualSSLEnabled: false
swagger.yaml file
openapi: 3.0.1
info:
title: HelloWorld
description: API Definition of HelloWorld
version: 1.0.0
servers:
- url: /sample
paths:
/testing:
get:
responses:
default:
description: Default response
and my API
<?xml version="1.0" encoding="UTF-8"?>
<api context="/sample" name="HelloWorld" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/testing">
<inSequence/>
<outSequence>
<payloadFactory description="name" media-type="json">
<format>
{"name":"$1","role":"$2"}
</format>
<args>
<arg evaluator="json" expression="$.name"/>
<arg evaluator="json" expression="$.role"/>
</args>
</payloadFactory>
</outSequence>
<faultSequence/>
</resource>
</api>
Hope Someone can help me as I'm really stuck
If you are trying to the testing through the console included in APIM, it might not recognize the Ingress host names (I assume the ingress host mapping is done in your local /etc/hosts). This should work if you use get the relevant curl and invoke it through the terminal.
As an alternative, you can use the service name (instead of Ingress host name) of the MI deployment and see whether you can invoke it through APIM's inbuilt console. This is of course if you have deployed those in the same namespace.

Wso2 EI 6.1.1 + third party rest api integration

I'm unable to call third party rest api(https://api.github.com/users/hackeryou) in wso2 ei and wso2 esb.
Below is the sample code:
<api xmlns="http://ws.apache.org/ns/synapse" name="VerifyCustID" context="/mambu">
<resource methods="GET" uri-template="/verify">
<inSequence>
<log>
<property name="CustID API" value="*********Inside CustID API********** "/>
</log>
<send>
<endpoint>
<http method="GET" uri-template="https://api.github.com/users/hackeryou"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
Below is the error in server log:
ID API = *********Inside CustID API**********
[2017-07-14 15:01:48,756] [] WARN - ConnectCallback Connection refused or failed for : api.github.com/192.30.253.116:443
[2017-07-14 15:01:48,759] [] WARN - EndpointContext Endpoint : AnonymousEndpoint with address https://api.github.com/users/hackeryou will be marked S
USPENDED as it failed
[2017-07-14 15:01:48,760] [] WARN - EndpointContext Suspending endpoint : AnonymousEndpoint with address https://api.github.com/users/hackeryou - cur
rent suspend duration is : 30000ms - Next retry after : Fri Jul 14 15:02:18 IST 2017
[2017-07-14 15:01:48,772] [] INFO - LogMediator To: https://api.github.com/users/hackeryou, MessageID: urn:uuid:7b834e0e-e348-4b60-adeb-f60a70f00483,
Direction: request, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 101503, ERROR_MESSAGE = Error connecting to the back end, Envelope: <?
xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
You might have some network connectivity issue to api.github.com:443 (perhaps firewalls etc.)
The API worked fine for me on EI611:
If you are not using the default truststore (client-truststore.jks) that comes with WSO2 or have made changes to it, you might need to import the certificate for api.github.com into the trust store that your WSO2 server is actually using.
Apart from network connectivity and missing certificate in trust store, can't see why your API shouldn't be able to call the remote service

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.

Create a REST proxy for SOAP service in wso2 esb

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

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"