I am trying to forward a customized string which i have in my class mediator to the client who have invoked the process and i'm unable to figure out how that is done.
So please help me to solve the issue.
you need to set your string to the payload message. Then this can send as the response. Please have a look at here[1]
[1] http://wso2.org/library/knowledge-base/generating-simple-response-using-wso2-enterprise-service-bus
Class mediator can modify the message and append custom data into the message. This sample shows how to add a string to the message using a class mediator.
Related
Hi everyone I am new using WSO2 ESB, here is the issue I made a integration project to learn but I have not been able to read the body of my request when I try I see this warning "Json Payload is empty"
enter image description here
Here is how I am trying to read the body <filter regex="[1-9]" source="json-eval($.test)">
enter image description here
And finally here is my request, I already set the header application/json
enter image description here
If anyone could help me, I would be very grateful. Thanks in advance
The request needs to be a POST to see the payload hit the ESB.
With GET it will just do a GET request without it.
Technically you can do GET with body but it's not a very common scenario.[1]
[1]https://docs.wso2.com/display/EI611/Unusual+Scenarios+for+HTTP+Methods+in+REST#UnusualScenariosforHTTPMethodsinREST-UsingGETwithaBody
That is because the GET method in wso2 does not allow the body payload. You can read in wso2 documentation:
Typically, a GET request does not contain a body, and the ESB profile does not support these types of requests. When it receives a GET request that contains a body, it drops the message body (...)
From doc: Using GET with a Body
Additional it is not good practice to do that, refer to this question: HTTP GET with request body
So you should use POST request.
I tried to create proxy which will receive soap request and store it to rabbitmq.
Example from documentation works well, but it always stores full message with envelope and body elements.
How can I store pure xml message without envelope?
I used payload mediator, but got same result.
When you are storing, it will store with envelope as it must have a proper message. Even though you try to remove that, it may cause an error if message doesn't have an envelope.
You can try sending binary format (which will attach xml file in to message: Try this with POSTMAN tool) and it will send the xml file separate one. But still its' better not to remove envelope as it may cause errors.
I have saved an xml file in Configuration registry /_system/config/test.xml. My xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<ServiceDefinition>
<Source1001>Endpoint1</Source1001>
<Source1002>Endpoint2</Source1002>
</ServiceDefinition>
Now can i create a proxy to update the contents of the above xml file by use of sequence or class mediator? If i pass new endpoint= Endpoint3 and Node = Source1001 in the request of the proxy. then for the node Source1001 i should be able to see the changed endpoint as Endpoint3
Looking forward to your answers. Thanks in advance.
No built-in mediator can do this. You can write a class mediator to read the xml placed in registry, then save it after editing. You have to get the reference to registry service via osgi at the class mediator for that.
FYI. you can get the input from message context and find the values to replace.
This [1] post explains about creating class mediator to read from registry resource. Hope this will be helpful during your task.
[1] http://vvratha.blogspot.com/2013/02/accessing-registry-resources-from-class.html
You can use the following code segment within a class mediator or you can do the same with script mediator as well.
mc.getConfiguration().getRegistry().updateResource(
resourcePath, mc.getProperty("myProperty").toString().getBytes());
You can find more details on how to use either one of those mediators here
I try to send an HTTP POST request to a service endpoint using Play2/Scala WS API. Since there is no parameters to be sent in the HTTP POST body, how can I send it using
WS.url("http://service/endpoint").post()
I have tried post() without argument but it gave me an error.
Cannot write an instance of Unit to HTTP response. Try to define a
Writeable[Unit]
Can you please help on this ?
thanks in advance...
Since post awaits a value that implements the Writeable and ContentTypeOf type classes,
you can use the Results.EmptyContent from play.api.mvc. (See API)
So I guess
WS.url("http://service/endpoint").post(Results.EmptyContent())
should do. (Didnt test)
For Play 2.6 and after, you have to use play.api.libs.ws.EmptyBody.
import play.api.libs.ws.{EmptyBody, WSClient}
WS.url("http://service/endpoint").post(EmptyBody)
Typical error is:
Cannot find an instance of play.api.mvc.Results.EmptyContent to WSBody. Define a BodyWritable[play.api.mvc.Results.EmptyContent] or extend play.api.libs.ws.ahc.DefaultBodyWritables
As of Play 2.8, you cannot use the WSRequest.post(body) methods with an empty body, because the BodyWritable trait requires a non-empty Content-Type
Instead, you can do ws.url(u).execute("POST") to send an HTTP POST request with no body.
I have a service in wso2.
For example,the endpoint is http://localhost:9000/services/SimpleStockQuoteService, and the request message is:
<m:getQuote xmlns:m="http://services.samples">
<m:request>
<m:symbol></m:symbol>
</m:request>
</m:getQuote>
If the symbol value is null. I do not want to send this request to the endpoint. I can use request message as response or send an error message out. I try to set property RESPONSE=true,but no use. How to do this in wso2? Someone can help me? Best regards.
You can use filter mediator to filterout the messages..Check the sample here[1] If particular filed is empty, then drop the message/execute fault sequence else allow it..
[1]http://wso2.org/project/esb/java/4.0.3/docs/mediators/filter.html
Use makefault mediator in your fault sequence.. Check the following post
http://techfeast-hiranya.blogspot.com/2010/04/wso2-esb-tips-tricks-05-error-handling.html