Currently, I am working on a application that receives XML messages over HTTP Request and responds again XML messages over HTTP responses.
I am using spring-oxm with JAXB and a very simple servlet that extracts the incoming message from http request and writes the outcoming messahe to http response.
HTML Code:
public interface MyBusinessProcessor {
MyResult process(MyObject x);
}
public class MyXmlProcessor {
private Unmarshaller unmarshaller;
private Marshaller marshaller;
private MyBusinessProcessor businessProcessor;
public void process(Source incomingMessage, Result outcomingMessage) {
MyObject x = unmarshaller.umarshall(incomingMessage);
MyResult y = businessProcessor.process(x);
marshaller.marshal(y, outcomingMessage);
}
}
public class MyProcessServlet ... {
private MyXmlProcess myXmlProcessor;
public void doGet(...) {
Source incoming = new StreamSource(request.getInputStream());
Result outcoming = new StreamResult(response.getOutputStream());
myXmlProcessor.process(incoming, outcoming);
response.flushBuffer();
}
}