StringBuilder sb = new StringBuilder();
sb.append("<html><head><title>OFBiz SOAP/1.1 Services</title></head>");
sb.append("<body>No such service.").append("<p>Services:<ul>");
for (String scvName: dctx.getAllServiceNames()) {
ModelService model = dctx.getModelService(scvName);
if (model.export) {
sb.append("<li><a href=\"").append(locationUri).append("/").append(model.name).append("?wsdl\">");
sb.append(model.name).append("</a></li>");
}
}
sb.append("</ul></p></body></html>");
writer.write(sb.toString());
writer.flush();
return null;
} catch (Exception e) {
sendError(response, "Unable to obtain WSDL");
throw new EventHandlerException("Unable to obtain WSDL");
}
}
}
// not a wsdl request; invoke the service
response.setContentType("text/xml");
// request envelope
SOAPEnvelope reqEnv = null;
// get the service name and parameters
try {
XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(request.getInputStream());
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(xmlReader);
reqEnv = (SOAPEnvelope) builder.getDocumentElement();
// log the request message
if (Debug.verboseOn()) {
try {
Debug.logInfo("Request Message:\n" + reqEnv + "\n", module);
} catch (Throwable t) {
}
}
} catch (Exception e) {
sendError(response, "Problem processing the service");
throw new EventHandlerException("Cannot get the envelope", e);
}
Debug.logVerbose("[Processing]: SOAP Event", module);
try {
// each is a different service call
SOAPBody reqBody = reqEnv.getBody();
Iterator serviceIter = reqBody.getChildElements();
while (serviceIter.hasNext()) {
Object serviceObj = serviceIter.next();
if (serviceObj instanceof OMElement) {
OMElement serviceElement = (OMElement) serviceObj;
String serviceName = serviceElement.getLocalName();
Map<String, Object> parameters = UtilGenerics.cast(SoapSerializer.deserialize(serviceElement.toString(), delegator));
try {
// verify the service is exported for remote execution and invoke it
ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);
if (model != null && model.export) {
Map<String, Object> results = dispatcher.runSync(serviceName, parameters);
Debug.logVerbose("[EventHandler] : Service invoked", module);