server.stop();
}
@Test
public void createServer_registerCustomResponder() throws WSDLException {
SoapServer server = SoapServer.builder()
.httpPort(9090)
.build();
server.start();
URL wsdlUrl = ResourceUtils.getResourceWithAbsolutePackagePath("/", "wsdl/stockquote-service.wsdl");
Wsdl parser = Wsdl.parse(wsdlUrl);
final SoapBuilder builder = parser.binding().localPart("StockQuoteSoapBinding").find();
AbstractResponder customResponder = new AbstractResponder(builder) {
@Override
public Source respond(SoapOperation invokedOperation, SoapMessage message) {
try {
// build the response using builder
String response = builder.buildOutputMessage(invokedOperation);
// here you can tweak the response -> for example with XSLT
//...
return XmlUtils.xmlStringToSource(response);
} catch (Exception e) {
// will automatically generate SOAP-FAULT
throw new RuntimeException("my custom error", e);
}
}
};
server.registerRequestResponder("/service", customResponder);
server.stop();
}