Mediation sequence for DELETE method in wso2 not working - wso2-api-manager

I have a SOAP web service for delete action, with endpoint URL
http://some-ip-address:my-port/bank/websrv/delcus
And can be invoked only by POST method.
I have published this API and added DELETE resource for invoking this service.
So the URL becomes
https://my-apim-endpoint/public/customer/{customer-id}
And I added mediation sequence for DELETE action. So whenever this API is invoked, it will go through the mediation sequence and send POST request to the endpoint
http://some-ip-address:my-port/bank/websrv/delcus
But when I invoke the API, the endpoint URL is getting replaced with the following URL.
Here is how the send mediator looks like,
<send>
<endpoint>
<http method="post" uri-template="http://some-ip-address:my-port/bank/websrv/delcus"/>
</endpoint>
</send>
http://some-ip-address:my-port/bank/websrv/100000023
Instead of
http://some-ip-address:my-port/bank/websrv/delcus
And giving me error response. Please anyone can help?

When you use http type endpoint, the resource path get appended to the endpoint url. for example say you have an endpoint http://test.com/path and if you have defined a /resource/{id} resource, then the request will be sent to http://test.com/path/resource/{id} kind of a url. That is the default behavior.
To call a SOAP service instead of using http type endpoint, you can use use address endpoint type. when you create endpoint with address type, you can define whether it is a soap11 or soap12. (format option in advanced options section in the implement tab). this will send a soap payload to http://test.com/path. (you do not have to build soap headers etc. only message body) .

Related

Grpc Writing Interceptors for Specific Endpoint

I implemented a grpc server in Golang. This server has multiple endpoints, but for one of the endpoints I want to implement an interceptor that will check the validity of an authentication token before proceeding with the request. I know how to implement an interceptor that will run when a request reaches any of the grpc endpoints, but how can I make so that my interceptor only runs for one specific endpoint?
For those interested, I was able to find the method of the request by inspecting the grpc.UnaryServerInfo param of the interceptor. There is an attribute called FullMethod that gives you the the endpoint of the request.
You can get the method name and compare when you are getting a request through your interceptor. Your custom interceptor will have one component called ServerInfo which will help you to filter from which method you are getting called. Based on that, you can filter out your authentication endpoint

Mule calling rest api fails with " Response code 404 mapped as failure. "

I am trying to consume a rest api via mulesoft but from postman when i invoke the mule endpoint it gives the following error "Response code 404 mapped as failure."
<http:request-config name="HTTP_Request_Configuration" host="xxxxx" port="80" doc:name="HTTP Request Configuration" basePath="/xxx/Members"/>
<http:request config-ref="HTTP_Request_Configuration" path="/{mID}/Members" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-param paramName="mID" value="#[flowVars.memID]"/>
</http:request-builder>
</http:request>
The error message you are getting in Mule indicates that the REST API you are calling from Mule is returning a 404. This means that you are requesting a resource that doesn't exist.
Check your config and the service you are consuming to make sure they match. From your code above the URL that Mule will be requesting is:
http://xxxxx:80/xxx/Members/{mID}/Members
This is built up from the host, port and base path of the HTTP config along with the path of the HTTP Request component.
Not having any knowledge of the API you are trying to consume I can't tell you what it should be in your specific case. If you have documentation that describes the service you should be able to adjust your mule configuration to match it.
Hope that helps.
Johnson.

How to get actual request URL in routed service when using Zuul service and Spring boot?

I am using zuul service as API gateway for all my micro services.
In zuul filter, I am able to get the requestUrl like below:
import javax.servlet.http.HttpServletRequest;
import com.netflix.zuul.context.RequestContext;
.....
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
String requestUrl = request.getRequestURL();
Here requestUrl: http://localhost:8052/api/userservice/users
In user service, when I am trying to get the request URL in spring boot rest controller using HttpServletRequest:
String requestUrl = request.getRequestURL();
Here requestUrl: http://localhost:8055/userservice/users
I am getting the routed service request url but NOT actual URL which client requested.
How to get actual request URL in routed service ?
You are getting the routed service because when you call the getRequestURL method after the request url has been modified. Calling the same method in a pre filter which order is -50(for example), you can get the actual URL zuul server received.
So far I don't find any method to get the actual URL in a route/post filter after the request is modified, I think one way to solve this problem is define a pre filter to get the actual URL before modified, and put the url into a Threadlocal field, then you can get the url in the route/post filter by accessing the field.
Zuul creates a new Http Request to user service. obviously with different URL.
So in the user service its impossible to get access to original request by design.
Zuul is supposed to encapsulate an original request, not reveal it.
All headers, request parameters, request body should be preserved, it's only a path to be changed.
If for some reason there is a need to get parameters from original request, in Zuul filter they can be extracted and set as Headers to the "new" request before it's sent to user service.
Then in UserService there should also be a filter that will "read" these headers and use the information as required

B2B handling SOAP Message but there is no response

Dears,
I developed my first datapower b2b solution, it must handle soap messages, the sender is sending soap message and the b2b service must retrieve soap also.
and I did the following :
I created an external Profile ExternalParter_hub and internal Partner IntrenalPartner_hub.
I set the destination for IntrenalPartner_hub to soap web service as a back-end.
IntrenalPartner_hub I made the response type SOAP.
I created B2BGW service and i added the Profiles above and i created HTTP Front Side handler for it.
In the B2BGW service that i created , i used the Document Routing Preprocessor in Advanced tab and I set the xsl document to assign sender and reciever data.
I created MPGW service and routes to the B2BGW service.
I tested the service using soapui by calling MPGW url as endpoint,
the soapui response panel is empty and the header section tells me that everything is ok. When Opening debug probe it tells that the soap service returns success soap message...
but MPGW service doesn't recieves any response from B2BGW service!!
and B2B Transaction Viewer show that message result is success ??
what is the missing part !!!!
The B2BGW in DataPower can't return any Response data other than its own "signals", eg. AS2 MDN or ebMS receipts.
You have to either create/fetch your Response data in the MPGW "proxy" and attach that as the Result to the HTTP 200 Response from the B2BGW or use a url-open() (XSLT or GWS) in the Response (server-to-client) rule of the internal B2B partner.
So, there is no missing part, only a limitation in DataPower B2BGW...

Can't get authentication token from web api 2

I am new to Web Api 2. I am trying to build a project to explore token authorization. I created a new project in VS 2013 and selected the WebApi2 template and used Fiddler to emulate http requests. I didn't change anything in the template, just ran it as it was and tried to play with it with Fiddler. I successfully created a user by issuing request to /api/account/register but I can't login by issuing a POST request to the /Token endpoint. The request is:
http://localhost:YYYY/token?grant_type=password&password=admin123456&username=admin
(i also tried to pass the parameters as a json object in the request body).
I get back this:
{"error":"unsupported_grant_type"}
From other posts such as ASP.NET WEB API 2 OWIN Authentication unsuported grant_Type I learned that I needed to enable CORS for web api and at the token endpoint, but that hasn't worked for me.
Are you sure that you are sending POST request message and not GET?
If you simply go to the URL with query string (or open connection to this URL from your code) you are sending GET message by default. It's not what WebAPI with "/token" path is listening for.
If you are calling web service from same place, CORS is not needed. The error "unsupported_grant_type" could be in the format of the data you are passing server in post action.
Try sending with Content-Type application/x-www-form-urlencoded

Resources