API manager. Exception when URLis without version number - wso2

I'm using WSO2 API Manager 1.10.0. If I publish API and subscribe and then call this API with version number, all is OK. Default version of API is checked. When I send request to this API without version in URL I get exception:
TID: [-1234] [] [2016-05-06 07:23:01,782] ERROR {org.wso2.carbon.apimgt.usage.publisher.APIMgtFaultHandler} - Cannot publish event. null {org.wso2.carbon.apimgt.usage.publisher.APIMgtFaultHandler}
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:552)
at java.lang.Long.parseLong(Long.java:631)
at org.wso2.carbon.apimgt.usage.publisher.APIMgtFaultHandler.mediate(APIMgtFaultHandler.java:76)
at org.apache.synapse.mediators.ext.ClassMediator.mediate(ClassMediator.java:84)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:155)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:220)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:155)
at org.apache.synapse.rest.API.process(API.java:389)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:97)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:65)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:295)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:317)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:149)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Our API manager is configured to work with WSO2 IS 5.1.0 and WSO2 DAS.

This issue will be fixed in the next release and you can use following workaround in order to solve the issue.
For existing APIs
Edit the synapse config file of the default api which is in /repository/deployment/server/synapse-configs/default/api folder.
Ex:
File name of Version API - admin--CountryTest_v1.0.0.xml,
File name of default API - admin--CountryTest.xml
Replace the uri-template value inside the resource tag and save the file.
current value - uri-template="$util.escapeXml($resource.getUriTemplate())"
new value - uri-template="/*"
For new APIs
You can change the default_api_template.xml file in order to apply the fix for new APIs.
Edit the default_api_template.xml which is in /repository/resources/api_templates folder replace the resource tag from the new value.
Current Value -
<resource xmlns="http://ws.apache.org/ns/synapse"
#if($resource.getUriTemplate().contains("{") ||
($resource.getUriTemplate().contains("*") && !$resource.getUriTemplate().endsWith("/*")))
uri-template="$util.escapeXml($resource.getUriTemplate())"
#else
url-mapping="$resource.getUriTemplate()"
#end
methods="$resource.getMethodsAsString()" faultSequence="fault">
New Value -
<resource methods="POST PATCH GET DELETE HEAD PUT OPTIONS"
uri-template="/*"
faultSequence="fault">

I have tested your use case but for me, it's working fine. Can you please double check whether that API was properly saved and published after you checked the Make this the Default Version check box.
You can check it by listing APIs(Metadata-> list-> API) in the carbon console and then click on the API name.
I simply tested it using the CalculatorAPI sample which takes some query parameters. I just published the samples and I subscribed to the CalculatorAPI. Below is the findings.
Just after the publish(without checked the Make this the Default Version check box)
1st API call with version
curl -k -X GET --header "Accept: application/json" --header "Authorization: Bearer afbbb795dadf272cec9c44efc78dc81b" "https://192.168.1.4:8243/calc/1.0/add?x=2&y=2"
Response
{"answer": "4.0"}
2nd API call without version
curl -k -X GET --header "Accept: application/json" --header "Authorization: Bearer afbbb795dadf272cec9c44efc78dc81b" "https://192.168.1.4:8243/calc/add?x=2&y=2"
response
am:fault xmlns:am="http://wso2.org/apimanager"><am:code>404</am:code><am:type>Status report</am:type><am:message>Not Found</am:message><am:description>The requested resource (/calc/add?x=2&y=2) is not available.</am:description></am:fault>
Then I edited the API and checked the Make this the Default Version check box and then published the API. Now I called the API and below is the output.
1st API call with version
curl -k -X GET --header "Accept: application/json" --header "Authorization: Bearer afbbb795dadf272cec9c44efc78dc81b" "https://192.168.1.4:8243/calc/1.0/add?x=2&y=2"
Response
{"answer": "4.0"}
2nd API call without version
curl -k -X GET --header "Accept: application/json" --header "Authorization: Bearer afbbb795dadf272cec9c44efc78dc81b" "https://192.168.1.4:8243/calc/add?x=2&y=2"
response
{"answer": "4.0"}

I have found a answer or some reason why endpoint without version doesn't work. If I put some parameter to URL Pattern in API definition (for instance /a/{param}, or /a?param={param}, the resource in API description (xml file) is generated with attribute url-template=/a/{param} and in this case such endpoint doesn't work without version. If I remove {param} from URL pattern and insert parameter by button "Add Parameter" - endpoint without version (default) works OK. In this case in API description resource is generated with attribute url-mapping not with url-template (like in ESB, there are two types of URL in resource, I think).
So, I have to refuse to use path and query parameters explicitly in URL pattern when I wont to use endpoints without version (default).
Maybe there are some workaround?
There is some additional small question. If I wonted to add "path" parameter by pushing button ADD Parameter in GUI I couldn't do it, because of there aren't option "path" in select list, there are query, header, formData only.

Related

SOAP service to retieve scope detailse from WSO2IS

Is there SOAP service which returns the SCOPE from WSO2IS 5.5.0 ? I have bearer token generated using Oauth grant_type 'password'. Using this token, i need to retrieve set of scope associated with token.
I tried introespection RESTfull API, but its returning ' Could not resolve host: application' error message .
Any suggestion please ?
curl: (6) Could not resolve host: application
{"error": "Invalid input"}
thansk a lot
EDIT : I missed the tailing 't' of the end point. Added that.
You are missing the protocol here.
curl -k -u admin:admin -H 'Content-Type: application/x-www-form-urlencoded' -X POST --data 'token=a6998b8b-5fff-390d-abd6-b0c9170f3147' https://localhost:9443/oauth2/introspect -v
You don't need to use the SOAP call therefore. In case you need it, here is the documentation.

How to fix 'TypeError: failed to fetch' (Chrome) / 'NetworkError when attempting to fetch resource.' (FireFox) in WSO2-AM

I am setting up WSO2-AM and uploading an API's servicedefinition swagger.json but upon trying the service in WSO2-AM, I get the response in FireFox "TypeError: NetworkError when attempting to fetch resource.". In Chrome its response is "TypeError: Unable to fetch".
The server is informationproxy.com and has SSL configured. Looks fine having a green lock in the urlbar with trusted certificate-chain. It does not certify for using the ip-number "https://209.182.203.81:9443/store/"
Question is: what makes WSO2 respond (in FireFox) with "TypeError: NetworkError when attempting to fetch resource."
The service does not seem to be the problem, since it works fine in editor.swagger.io.
The service also works fine directly called from curl to the external serviceprovider, returning a valid JSON with the data I expect:
curl -k -X GET "https://tieka.nl/webservices/address/luxembourg/v1/?postcode=8080&number=1" -H "accept: application/json"
Also: all other api-services that I have tried to implement fail with the same error message.
There is a side-effect. The response to this curl is an encrypted payload:
curl -k -X GET "https://209.182.203.81:8243/webservices/address/luxembourg/v1/?postcode=8080&number=1" -H "accept: application/json" -H "Authorization: Bearer a1111111-1aa1-1111-aaaa-1111aaaa1111"
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9JRVRGLy9EVEQgSFRNTCAyLjAvL0VOIj4KPGh0bWw+PGhlYWQ+Cjx0aXRsZT4zMDEgTW92ZWQgUGVybWFuZW50bHk8L3RpdGxlPgo8L2hlYWQ+PGJvZHk+CjxoMT5Nb3ZlZCBQZXJtYW5lbnRseTwvaDE+CjxwPlRoZSBkb2N1bWVudCBoYXMgbW92ZWQgPGEgaHJlZj0iaHR0cHM6Ly93d3cudGlla2Eubmw6ODAvd2Vic2VydmljZXMvYWRkcmVzcy9sdXhlbWJvdXJnL3YxLz9wb3N0Y29kZT04MDgwJmFtcDtudW1iZXI9MSI+aGVyZTwvYT4uPC9wPgo8aHI+CjxhZGRyZXNzPkFwYWNoZSBTZXJ2ZXIgYXQgd3d3LnRpZWthLm5sIFBvcnQgODA8L2FkZHJlc3M+CjwvYm9keT48L2h0bWw+Cg==</ns:binary>

How to test OpenIm (ForgeRock) Request on Postman?

I have openIdm ForgeRock installed locally and I'am trying to go through the API Explorer etc. in order to see how to use the endpoints and the available endpoints.
From localhost:8080 where ForgeRock is running I can run/try a request. It works fine and I see the Response with Status 200 and its details.
When I try same Request URL on Postman, I get:
{
"code": 401,
"reason": "Unauthorized",
"message": "Access Denied"
}
In a way this makes sense for me as I'am not logged in in this case as directly via ForgeRock Server on localhost:8080. So how can I work around this to be able to run my tests also on Postman.
I tried the parameters username=xxx and password=xxx to the Request on Postman, but it keeps throwing the same error.
I also tried it on Postman as CURL request exactly how ForgeRock is using it, but it seems to have an issue with Authorization.
curl -X GET --header 'Accept: application/json' --header 'X-Requested-With: Swagger-UI' 'http://localhost:8080/openidm/managed/user?_queryId=query-all'
Any Idea please?
Fixed. Was actually simple... Had to add the following in the headers:
X-OpenIDM-Username
X-OpenIDM-Password
Value is by default: opendidm-admin for both.

wso2 api manager PUT method does not work in api store

Wso2 API Manager 1.10.0. PUT method does not work in API store.
GET, POST, DELETE methods work, but PUT dose not work.
Error,
Curl
curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer c6c90338514e561c8a02a7b6a1c96553" -d "{\"payment\":\"PAID\"}" "https://10.138.31.22:8243/Starbucks_API/1/order_1"
Request URL
https://10.138.31.22:8243/Starbucks_API/1/order_1
Response Body
<ams:fault xmlns:ams="http://wso2.org/apimanager/security">
<ams:code>900906</ams:code>
<ams:message>No matching resource found in the API for the given request</ams:message>
<ams:description>Access failure for API: /Starbucks_API/1, version: 1. Check the API documentation and add a proper REST resource path to the invocation URL</ams:description>
</ams:fault>
Response Code
403
Response Headers
{
"content-type": "application/xml; charset=UTF-8"
}
Resource given in the request is actually matching, which I mentioned in API.
Any help is appreciated.
Resource Definition
You are having two PUT with same URL. You can't have two different HTTP resource with same URL.

converting curl api call into restful api call

i am very new to the java EE.
I have built some simple restful client for calling rest api's from java using jersey framework.
I have one curl request which i have to call from java
curl -i -X POST 'https://{url}' -H 'Content-Type: application/x-www-form-urlencoded' -H "Accept: application/vnd.newbay.dv-1.8+json" -H "X-HTTP-METHOD-OVERRIDE: DELETE" -H "X-Client-Platform: SERVICES" -H "X-Client-Identifier: IL" --insecure --data 'path=%2FMy+Samsung+GT-I9082%2F20130822_172409.jpg&path=%2FMy+Samsung+GT-I9082%2F20130905_085407.jpg'
Here the paths of file are passed as form post in curl using --data.
Can anyone tell me how to call this api from my java program using jersey framework? I am having difficulty because of this --data part? how exactly i will pass that in my restful java client that i cant understand.
Also can anyone tell me how to pass form post --data part while calling the same api from soapUI?
In your cURL command, --data provides post data in a classic html form format. You shoud alrealy be aware of that because the content-type is explicit : application/x-www-form-urlencoded
Jersey can handle this encoding for you, using MultivaluedMapImpl.
see Sending Name Value Pair in POST using Jersey Client