How to set the response in a custom mediator?
I'm experimenting with a custom mediator that will handle all of the mediation for a service. I'd like to know how to set the SOAP response. Other than setting the response, it's working fine. Right now, it mirrors back the request message.
Here's how it's configured in synapse.xml:
<proxy name="IntegrationObjectTest">
<target>
<inSequence>
<class name="IntegrationObjectTestMediator" />
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<send/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
Here's the mediator code:
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
public class IntegrationObjectTestMediator extends AbstractMediator {
public boolean mediate(MessageContext msgCtx) {
boolean continueFurtherMediation = true;
System.out.println("IntegrationObjectTestMediator.mediate");
StringBuffer sb = new StringBuffer();
sb.append(" <SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\"> ");
sb.append(" <SOAP-ENV:Header/> ");
sb.append(" <SOAP-ENV:Body> ");
sb.append(" <getIntegrationObjectTestResponse xmlns=\"http://axisversion.sample\"> ");
sb.append(" <return/> ");
sb.append(" </getIntegrationObjectTestResponse> ");
sb.append(" </SOAP-ENV:Body> ");
sb.append(" </SOAP-ENV:Envelope> ");
// msgCtx.set
msgCtx.setResponse(true);
return continueFurtherMediation;
}
}
- Login or register to post comments
- Printer friendly version
- 358 reads











You can use
You can use msgCtx.setEnvelope(<<your new message>>);
Check transformation mediators like the XSLTMediator to see how this can be done. If I did this, I'd use Axiom to build the XML directly instead of using a string buffer.. but thats upto you to decide with your requirements
asankha
I'm getting closer, I think
Here's my code:
Here's the exception I get:
I figured it out
I figured it out. I'm now using StAXSOAPModelBuilder to create my response from the StringBuffer and everything works as expected.
Cool :-)!
Cool :-)!
What if?
Hi again Asankha!
If you're remembered I asked you a few questions about mediating messages from a web service to a regular http servlet here -> http://wso2.org/forum/thread/3856.
I've sucessfully put everything into work with your help and now I'd like to do an improvement and I'm not getting how to do it.
Actually I'm using this code to do requests to my http servlet:
EndpointDefinition myEndpoint = new EndpointDefinition();myEndpoint.setForceGET(true);
myEndpoint.setAddress(MY_ADDRESS + "&name=" + this.name);
myEndpoint.setFormat("get");
Yes, everything is being made with my own java code. Here I can make my requests and put in the address the values that I want to pass to the servlet. The problem now is that I want to produce a file (in a format known by my servlet) with the data arrived from the web service and them send it to my http servlet and I don't understand where do I must put the file? Is there any way to get an inputStream to the httpRequest to be sent to my servlet?
I'm really stuck here (again...).
Thanks in advance for your attention and patience! ;)
Hi again. Can anyone help me
Hi again.
Can anyone help me with this? I'm still stuck here...
Hi, If I got this correctly
Hi,
If I got this correctly this is some sort of a J2EE question where you need a mechanism to pass the input stream in an HTTPServletRequest, isn't it?
I am not an J2EE expert, but looking at the API it should be possible to get the parameters map of the HTTPServletRequest and insert a new entry to that map with the input stream is being put as the value. I think this is what we do when we need to upload a file....
This may be wrong but worth in giving it a try :-)
Ruwan Linton
Hi Ruwan, Thanks for your
Hi Ruwan,
Thanks for your response. I have one Task in wso2 esb and I what that it could send a file to a regular http servlet in an address like http://my.server.com/upload.
The requests that this servlet receive are of this kind:
The next data in the http request is the binary of my file test.xls. How can I do this with wso2 esb? I know that if you add childs to the body of the soap message like:
<upload> <file>myfile</file> </upload>It then transforms to a request like: http://my.server.com/upload&file=myfile . This is how I send parameters to my servlet, but to send a file? should I put the binary in the place of my string "myfile" ?
Sorry for my big post. It was just to make sure that I'm clear enought for you to understand my problem.
Thanks for all the attention!!!!
If you can do a POST shown
If you can do a POST shown in the original request then you should be able to send the file as an attachment, but with GET requests you cannot do that, you may construct the message in the way you need it to be and do a POST to the servlet.
You will need to remove the format="get" attribute from the endpoint.
Thanks,
Ruwan
ok, I'll try a post request.
ok, I'll try a post request.
But how can I enforce a post request without having a soap message attached?
With get, synapse decode the data in the soap body to parameters for the get request like I described in the above post. How can I the same for a POST request?
Hi Joao What you seem to be
Hi Joao
What you seem to be wanting to do is not something we support currently.. You could raise a JIRA for this enhancement, but as far as I have seen bridging to file upload servlets is not so common with an ESB.. so we may not be able to work on a JIRA right away..
However if this is urgent/critical for your production deployment, you could get commercial support from WSO2 to help you
asankha
Ok... Thanks anyway.
Ok...
Thanks anyway.
This is for my MSc thesis,
This is for my MSc thesis, so as you might understand the budget is very small and all supported by... me.
As a workaround I'm thinking in implementing a web service in my web app to handle this case (the file upload). My app is based on Spring so I'm thinking in using WSO2 WSF/Spring. Is this a good idea?
Hi Joao As an open source
Hi Joao
As an open source project, we will help any user irrespective of who they are. But ofcourse we will prioritize requests or issues raised by users who have paid for support.
Can I suggest that you use the esb-java-dev@wso2.org or the dev@synapse.apache.org mailing lists where the core WSO2 ESB / Apache Synapse ESB developers hang out? You will first need to subscribe to them, but there you would get answers from a wider audience (esp the Synapse list). This I am sure would be very helpful to you.
If you could share your "problem statement" - i.e. whats the business problem you want to solve - we could help you decide on the best solution from a technical point of view. if you simply want file transfer over SOAP, have you considered MTOM / SwA? Lets start from that description on the mailing lists and I'm sure you will get help from many developers as well as other users too..
Of course once your problem gets solved, you could blog about it or write some articles etc, that would get you good publicity for your work, as well as help us - which we would consider as a reward from another happy user :)
asankha