Obtain HTTP_METHOD programatically inside WSO2 Custrom Handler? - wso2

I have a custom authentication handler in which I need to figure out the HTTP_METHOD.
In my custom mediators I can get this easily from the synapse context, from api.ui.HTTP_METHOD property. For example
api.ut.HTTP_METHOD ==> POST
But I do not have this property in my custom authentication handler. Is there another way to get hold on the HTTP METHOD of the API inside a custom authentication handler?

In a custom handler, you have access to the message context. Using that message context , you can retrieve HTTP_METHOD like below.
((Axis2MessageContext) messageContext).getAxis2MessageContext().get‌Property("HTTP_METHOD")
Can refer Writing Custom Handlers and Axis2 Java doc for more info.

Related

Obtain endpoint URL programatically inside wso2 custom handler

I have a custom mediator which obtains the endpoint url from message context property ENDPOINT_PREFIX.
I am trying to do the same in my authentication handler, but the get property returns null.
Is there a different way to obtain this information inside a custom handler?
Note that I am not after the endpoint itself (e.g. /api/1.0.0) but after the url to which it points to (in the publisher ui it appears as production/sandbox url).

Null endpoint is passed when using soap ui project custom properties

I am trying to pass the endpoint for a project using the project custom properties. Say I created a custom property "EndPoint" and am trying to pass http://${#Project#EndPoint} in the endpoint field for the get request, it is throwing me null response. The request sent is not having the endpoint value.
GET http://null///int/locations/v1/destinations?
Should we able to override the properties?

Push user SAML attributes to backend service via WSO2 API Manager

I am using WSO2 API Gateway to service API calls. The backend requires custom user attributes (username, e-mail, etc.) to be sent as part of the query string in the URL. The values for the query string pairs will be provided in the SAML2 token embedded in the API call.
How can a mediator access these custom SAML2 attributes?
You can create a custom mediator or custom handler to parse the saml token and set it to a header or something . see Writing Custom+Handlers for sample handler which reads a header .

Get the name of the Application that triggers a call from WSO2 API Manager

Is it possible to get the name of the Application that triggered the API call on WSO2 API Manager and pass it on to the call as a header?
Any can help how to do this please.
Yes, application name is part of the JWT token that you get with the calls. Here's documentation.
JWT tokens are enabled by default in WSO2 API Cloud (the public hosted service from WSO2). So if you are using it - everything just works.
If you are deploying API Manager yourself, you need to configure JWT yourself as explained here.
One option would be to implement an custom handler. See Writing Custom Handlers
APIMgtUsageHandler is one of the handlers in API manager which collects the application name (to collect usage data). So you can refer it as a sample handler on how to get the application name. see APIMgtUsageHandler.java

How to send the post request in wso2 api manager?

How to send the post request in wso2 api manager? What would be the content type, parameters etc.
I am publishing Rest APIs in WSO2 API Manager , I would like to intercept my own API input field validations for each API like input parameter format and value etc. If validation success then API Manager should allow the request to invoke back-end , else reject the request with error message.
You can create a custom handler or custom sequence and deploy it for that api. You can implement the validation logic inside that.
see following product documentation
https://docs.wso2.com/display/AM1100/Writing+Custom+Handlers
https://docs.wso2.com/display/AM1100/Adding+Mediation+Extensions