Changing Wso2 HTTP Method from POST to GET - wso2

How can i chnage the HTTP Method in wso2 esb using java class mediator
currently I am using
mc.setDoingGET(false);
mc.setDoingPOX(true);
I want to take a post request to ESB and then send to a webservice via GET or vice versa
but the above code is not working at all

Use the property mediator with property name: HTTP_METHOD and http method name as the value (GET,POST etc) and scope as 'axis2'.

If you want to change this property in the java class level, you may do the following:
msgCtx.setProperty(Constants.Configuration.HTTP_METHOD, "GET");

Related

Parameters in POST call to Data Service in Enterprise Integrator

I'm migrating some data services from DSS to EI but I have problems with the parameters in POST calls. I published a Data Service with a query exposed as a REST resource using the methods POST and GET, just for testing. Then I try to call it using cURL.
The GET is easy because I only need to append the parameter to the URL, but for the POST I try passing it using -d and a JSON or XML structure but always the server responds with error 400 (bad request).
If the resource have no parameters both calls works fine.
Can anyone tell me the right way to pass the parameters to the RESTFUL resource when I use the POST method?
If you publish this service as wsdl service do you have same problems with methods, thats analogies to your post methods? I was catch similar problem when don't set request_box parameter of my service to on. It was look as I send request without parameters, but they was send correcltly in fact.

WSO2 API Message Mediation based on accept headers

I am using WSO2 Api Manager as a proxy between a client and the server. The server sends XML responses that I successfully converted to a JSON response with a custom PayloadFactory message mediation. Problem that I now am facing is the following: How do I mediate based on the accept headers of a request?
When I have in the header of a request:
Accept application/json
I want to use my mediator to convert the response from the server to JSON, but when I have
Accept text/xml or application/xml
I don't want to use my mediator and just forward the response as is.
Edit:
Basicly the only thing a really need is to save my "Accept ... " header. I can forward it to the server, but the server doesn't do anything with it. Are there global variables or something that I can use per proxy request?
Any advice will be appreciated.
You can use Filter mediator or Switch mediator to do a if-then-else kind of operations inside the insequence and implement your first requirement. You can get the header using synapse xpath variables.
You can define a custom sequence and add it to the api
for the second question, you can use property mediator to define values and use them later. set the 'Scope' parameter according to your need

How to set SoapAction with SoapJaxbDataFormat

Hi I am trying to use Camel-SOAP component to create the soap message to invoke a .Net SOAP 1.2 service.
It is not working beacause the the SoapJaxbDataFormat is not putting the SOAP action, I am able to test and call the service using SOAPUI and I see in the request generated by SOAPUI that the soap header with action is filled in.
How can get action filled in ?
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("xx.zzz.yy", new ServiceInterfaceStrategy(DpoService.class, true));
soapDF.setVersion("1.2");
soapDF.setNamespacePrefixRef(NAMESPACE_MAPPING_BEAN_NAME);
from("direct:quote")
.marshal(soapDF)
.log("${body}")
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/soap+xml;charset=UTF-8;action=\"http://example.com/services/DpoServiceContract/GetPof\""))
.to("http://localhost:7898/DpoService.svc");
The reason I am using this approach is because the CFX and WSImport generated client code does not work.
I was able to call the service using a velocity template to generate the SOAP msg.
Thank you for your help.
You can set the SOAP action from your message header, just like this:
exchange.getIn().setHeader(Exchange.SOAP_ACTION, "SOAPACTION");

Call WSO2 DSS service using ajax?

I have one data service in WSO2 DSS. And also its possible to call using browsers.But i can't make a request using ajax to call this service.I think CORS issue is occurring.So i want to add Access-Control-Allow-Origin parameter to response header.How this is possible in WSO2 DSS ,Any suggestion ?
I think you can put a custom headers by adding axis2 custom out flow handler.
http://shivendra-tripathi.blogspot.com/2010/04/adding-handler-in-axis2.html?m=1
http://shivendra-tripathi.blogspot.com/2010/04/adding-soap-header-in-axiom.html?m=1

URI templates in WSO2 API Publisher

Is it possible to register endpoints with URI templates in the API Publisher that ships with WSO2 API Manager version 1.4.0? For example, I would like to register an endpoint such as:
/jobs/{jobid}/pems
After saving an API, I can see this bit in the API config file:
<resource methods="GET" url-mapping="/jobs/{jobid}/pems">
I have tried manually changing the XML file from url-mapping to uri-template, i.e., to:
<resource methods="GET" uri-template="/jobs/{jobid}/pems">
but I still get "No matching resource found in the API for the given request". In any case, this is not a good work around since we need developers to be able to register these endpoints from the publisher application. Whenever changes are saved to an API from within the API Publisher interface, 'uri-template' gets reverted back to 'url-mapping'.
Thanks in advance.
This is due to APIPublisher app only supports URL-Mappings when defining API resources.
If you want to define a uri-template ,instead of a url-mapping,you can achieve this from changing the api xml manually.
But before that make sure,when creating the API,you have define the API with a valid url-mapping.So in your trying API,first please edit the API from APIPublisher as keeping a valid url-mapping pattern for API resources and then change its xml to match with your mentioned uri-template pattern.
Thanks;
we don't currently support uri-template patterns. We support only url-mappings.
Even , if you edit the backend API configuration (that is, api configuration file ) to url-mappings, it wont work, because we validate request before the request get hits the mediation engine.
You can use ESB RESTApi as your backend service endpoint.That is, define the RESTAPI in wso2esb, with uri-templates(it is supported out of the in ESB) and point that API as the service endpoint from wso2APIManager with url-mappings pattern.
I would like to add some more points.As I mentioned earlier,WSO2 APIManager supports uri-templates.Only api-publisher app UI is not allowing to add uri-templates.
When creating the API from the Publisher UI, you have to give the resource mapping as /* or valid url-mapping. Then when the synapse api is created, you have to change that xml file to uri-template and then change the /* to the uri-template pattern.
Hope above will help you to resolve your issue.
Thanks;