WSO2EI API list - wso2

I need to get all apis(list of apis) with their parameters from wso2ei. I could do that with wso2 api-manager with curl command.how can I do this with curl command in wso2ei?

There aren't any rest APIs available in wso2ei to get the list of APIs.

You can retrieve API list and details from RestApiAdmin admin service (SOAP service). You can get parameters and types from the WSDL. Follow [1] to retrieve WSDL of RestApiAdmin Admin service.
Sample curl to retrieve API list:
curl -k -v -X POST \
https://localhost:9443/services/RestApiAdmin \
-H 'Accept: */*' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'SOAPAction: "urn:getAPIsForListing"' \
-d '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://org.apache.axis2/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:getAPIsForListing>
<!--Optional:-->
<xsd:pageNumber>0</xsd:pageNumber>
<!--Optional:-->
<xsd:itemsPerPage>10</xsd:itemsPerPage>
</xsd:getAPIsForListing>
</soapenv:Body>
[1] https://docs.wso2.com/display/EI610/Calling+Admin+Services+from+Apps#CallingAdminServicesfromApps-Discoveringtheadminservices

Related

WSO2 MI How to create an Insert or Update PUT resource?

I want to create a PUT resource in WSO2 Micro Integrator, so I can either insert or update event records, but it's not even accepting my http request. Could you help me configure this correctly?
What I was expecting was that when I'd call something like this, it would insert in batch into the database.
curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord?calendar_date=2022-12-01' \
--header 'Content-Type: application/xml' \
--data-raw '
<event_record_list>
<event_record>
<event_type>1000124</event_type>
<event_count>217140</event_count>
</event_record>
<event_record>
<event_type>1000127</event_type>
<event_count>1567</event_count>
<event_record>
</event_record>
<event_type>1000129</event_type>
<event_count>31</event_count>
</event_record>
</event_record_list>'
But in reality it responds with this:
<axis2ns52:DataServiceFault xmlns:axis2ns52="http://ws.wso2.org/dataservice">
<axis2ns52:current_params>{event_type=1000124, event_count=217140}</axis2ns52:current_params>
<axis2ns52:source_data_service>
<axis2ns52:data_service_name>APIDataService</axis2ns52:data_service_name>
<axis2ns52:description></axis2ns52:description>
<axis2ns52:location>/home/wso2/qa/wso2mi/tmp/carbonapps/-1234/1671624403635APICompositeExporter_1.0.0.car/APIDataService_1.0.0/APIDataService-1.0.0.dbs</axis2ns52:location>
<axis2ns52:default_namespace>http://ws.wso2.org/dataservice</axis2ns52:default_namespace>
</axis2ns52:source_data_service>
<axis2ns52:ds_code>INCOMPATIBLE_PARAMETERS_ERROR</axis2ns52:ds_code>
<axis2ns52:current_request_name>_puteventrecord</axis2ns52:current_request_name>
</axis2ns52:DataServiceFault>
However, when I make this request, I'm able to make the request, and it returns me with 202, but I'm only able to insert or update one row at a time.
curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord?calendar_date=2022-12-01&event_type=1000124&event_count=217140' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'calendar_date=2022-12-01' \
--data-urlencode 'event_type=1000124' \
--data-urlencode 'event_count=217140'
Here is the Data Service definition:
<data name="APIDataService" serviceNamespace="" serviceGroup="" transports="http https local">
<description />
<config id="postgresDataService">
<property name="carbon_datasource_name">APIPostgres</property>
</config>
<query id="eventRecord" useConfig="postgresDataService">
<sql>
INSERT INTO event_record(calendar_date, event_type, event_count)
VALUES (:calendar_date, :event_type, :event_count)
ON CONFLICT (calendar_date, event_type)
DO UPDATE SET event_count = EXCLUDED.event_count
</sql>
<param name="calendar_date" sqlType="date" />
<param name="event_type" sqlType="integer" />
<param name="event_count" sqlType="integer" />
<properties>
<property name="forceJDBCBatchRequests">true</property>
</properties>
</query>
<resource method="PUT" path="eventRecord">
<call-query href="eventRecord">
<with-param name="calendar_date" query-param="calendar_date" />
<with-param name="event_type" query-param="event_type" />
<with-param name="event_count" query-param="event_count" />
</call-query>
</resource>
</data>
Due to a limitation of MI[1], you cannot use both the request body and URL params to call a dataservice. When the content type is set in the request it tries to dispatch to the data service operation based on the request body and ignores the URL params. As a result, you will observe the INCOMPATIBLE_PARAMETERS_ERROR error. Therefore you will need to pass all the required parameters of the eventRecord operation in your request body. Can you try to send a request as follows,
curl --location --request PUT 'http://wso2-mi.mkwtf.com/services/APIDataService/eventRecord' \
--header 'Content-Type: application/xml' \
--data-raw '
<event_record_list>
<event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000124</event_type>
<event_count>217140</event_count>
</event_record>
<event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000127</event_type>
<event_count>1567</event_count>
<event_record>
</event_record>
<calendar_date>2022-12-01</calendar_date>
<event_type>1000129</event_type>
<event_count>31</event_count>
</event_record>
</event_record_list>'
[1] - https://github.com/wso2/product-ei/issues/2811

Create parameters in API Header in WSO2

I have created a API in WSO2 studio integrator like below:
curl --location --request POST 'http://localhost:8290/internal/send-messages'
--header 'accept: text/plain'
--header 'Content-Type: application/json'
--data-raw '{
"bankName": "heere",
"uniqueIdentifier": "445334564"
}'
To pass the requests (which received from this API) toward the endpoint, I need to add two following parameters into API Header
--header 'MasterName: TOMSON'
--header 'clientName: TOM' \
TOMSON value is unique(static) and would NOT change for any user.
However TOM would be change based on application username given from API Manager (there is OATH2 authentication).
How can I add a static header (Like MasterName) to a API while sending toward the endpoint
How can I understand the username of application ??
You can add a static header using the header mediator[1].
<header name="MasterName" value="TOMSON" scope="transport"/>
To get the application information from the API Manager, you can enable backend JWT[2]. This will be a JWT generated with much more information regarding the request. By decoding this[3] JWT at the backend, you can get the application information with the claim http://wso2.org/claims/applicationname.
[1] - https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/header-Mediator/
[2] - https://apim.docs.wso2.com/en/latest/deploy-and-publish/deploy-on-gateway/api-gateway/passing-enduser-attributes-to-the-backend-via-api-gateway/
[3] - WSO2 Decode JWT
You can use header mediator to add headers
For example
<header name="miCustomHeader" value="ThisIsTheWay" scope="transport"/>
<send>
<endpoint>
<address uri="https://someRandomURL"/>
</endpoint>
</send>
It will send miCustomHeader along its value to the endpoint

How to format a SOAP request

I want to access an online program via the command line within a bash script. I've been told I can run a SOAP request in order to access the software. This is the request I've been told I can use.
POST /OnlineAnalysis/Service.asmx HTTP/1.1
Host: cydas.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.cydas.org/OnlineAnalysis/analyseKaryotype"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<analyseKaryotype xmlns="http://www.cydas.org/OnlineAnalysis/">
<strKaryotype>string</strKaryotype>
</analyseKaryotype>
</soap:Body>
</soap:Envelope>
I've never run a SOAP request before but it looks like I'm able to use the curl command based on this question. I've tried to model my curl command according to the link I posted
curl -X POST -H "POST /OnlineAnalysis/Service.asmx HTTP/1.1" -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction: \"http://www.cydas.org/OnlineAnalysis/analyseKaryotype\"" -H "Host: cydas.org" --data-binary #request.xml
And am getting this output
<HTML>
<HEAD>
<TITLE>405 Method Not Allowed</TITLE>
<BASE href="/error_docs/"><!--[if lte IE 6]></BASE><![endif]-->
</HEAD>
<BODY>
<H1>Method Not Allowed</H1>
The HTTP verb used to access this page is not allowed.<P>
<HR>
<ADDRESS>
Web Server at cydas.org
</ADDRESS>
</BODY>
</HTML>
<!--
- Unfortunately, Microsoft has added a clever new
- "feature" to Internet Explorer. If the text of
...
These are the contents of my request.xml file below
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<analyseKaryotype xmlns="http://www.cydas.org/OnlineAnalysis/">
<strKaryotype>46,XX,del(3)(p11)</strKaryotype>
</analyseKaryotype>
</soap:Body>
</soap:Envelope>
I'm not sure what the expected output is supposed to be yet because I can't run the program. I just want to get my SOAP request running properly.
try this:
curl -v "http://www.cydas.org/OnlineAnalysis/Service.asmx" -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: \"http://www.cydas.org/OnlineAnalysis/analyseKaryotype\"" -H "Connection: Keep-Alive" -H "Host: www.cydas.org" --data #request.xml
The server responded with the message: "The Karyotype del(3)(p11) is not valid:
Non-specified error in chromosome count element (del(3)(p11))"
Here's the complete response message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<analyseKaryotypeResponse xmlns="http://www.cydas.org/OnlineAnalysis/">
<analyseKaryotypeResult>
<Original_ISCN_Formula>del(3)(p11)</Original_ISCN_Formula>
<IsPolyClonal>false</IsPolyClonal>
<IsValidKaryotype>false</IsValidKaryotype>
<Corrected_ISCN_Formula/>
<CloneSize>0</CloneSize>
<IsIncompleteKaryotype>false</IsIncompleteKaryotype>
<Ploidy>0</Ploidy>
<ErrorMessages>The Karyotype del(3)(p11) is not valid:
Non-specified error in chromosome count element (del(3)(p11))</ErrorMessages>
</analyseKaryotypeResult>
</analyseKaryotypeResponse>
</soap:Body>
</soap:Envelope>
cURL is a great tool, but if you want a nice gui you can try other tools like SoapUI or Postman for testing APIs. SoapUI is a standalone Java application and Postman is a plugin for Chrome. They're both free.

Error calling WSO2 API Manager Admin Servces via soapUI

I am experiencing an error calling WSO2 API Manager v2.1.0 Admin Services via soapUI. It seems that the requests that are changing state in API Manager like this one, addRole, are failing. Note that "read only" style requests like listAllUsers or getAllRolesNames are succeeding.
Here is the raw request from soapUI:
POST https://localhost:9443/services/UserAdmin.UserAdminHttpsSoap11Endpoint HTTP/1.1
Accept-Encoding: gzip,deflate
SOAPAction: "urn:addRole"
Authorization: Basic YWRtaW46YWRtaW4=
Content-Type: application/soap+xml
Content-Length: 283
Host: localhost:9443
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://org.apache.axis2/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:addRole>
<xsd:roleName>test_role</xsd:roleName>
</xsd:addRole>
</soapenv:Body>
</soapenv:Envelope>
Here is the response form soapUI:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<soapenv:Code>
<soapenv:Value>soapenv:VersionMismatch</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US">Transport level information does not match with SOAP Message namespace URI</soapenv:Text>
</soapenv:Reason>
<soapenv:Detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Here is the log entry that appears in wso2carbon.log:
[2017-03-03 16:23:03,474] ERROR - ResponseTimeCalculator wso2statistics.request.received.time is null in the IN MessageContext
Any help is greatly appreciated.
Thanks!
Looks like your request is a SOAP 1.1.
In that case, the Content-Type of the request should be text/xml, not application/soap+xml.
If that doesn't work, try using RemoteUserStoreManagerService instead of UserAdmin.

Sending a SOAP query to reactome.org with curl

(Note: this question was cross-posted on Biostar)
Hi all,
I'm trying to send a RPC-encoded SOAP query to Reactome (a biological pathways database), using curl:
I want to call the remote method
queryPathwaysForReferenceIdentifiers defined in http://www.reactome.org:8080/caBIOWebApp/services/caBIOService?wsdl
I created the following SOAP/XML file: soap.xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:r="http://www.reactome.org:8080/caBIOWebApp/services/caBIOService" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:reactome="http://www.reactome.org/caBIOWebApp/schema">
<SOAP-ENV:Body>
<r:queryPathwaysForReferenceIdentifiers>
<r:referenceIdentifiers>
<soapenc:Array soapenc:arrayType="soapenc:string[3]">
<soapenc:string>Q9Y266</soapenc:string>
<soapenc:string>P17480</soapenc:string>
<soapenc:string>P2048</soapenc:string>
</soapenc:Array>
</r:referenceIdentifiers>
</r:queryPathwaysForReferenceIdentifiers>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
and I sent it with curl using the following command:
curl -d #soap.xml \
-H "Content-Type: application/soap+xml" \
-H 'SOAPAction: ""' \
"http://www.reactome.org:8080/caBIOWebApp/services/caBIOService"
But the response is empty, whereas I expected a result.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body>
<ns1:queryPathwaysForReferenceIdentifiersResponse xmlns:ns1="http://www.reactome.org:8080/caBIOWebApp/services/caBIOService" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<queryPathwaysForReferenceIdentifiersReturn xmlns:ns2="http://www.reactome.org/caBIOWebApp/schema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="ns2:Pathway[0]" xsi:type="soapenc:Array"/>
</ns1:queryPathwaysForReferenceIdentifiersResponse>
</soapenv:Body>
</soapenv:Envelope>
is there an error in my Request ? where ?
Many thanks !
Pierre
the question was answered on Biostar: http://biostar.stackexchange.com/questions/5511