// Copyright 2001-2003 Systinet Corp. All rights reserved. // Use is subject to license terms. package example.basics.webservices; import org.idoox.util.RuntimeWrappedException; import javax.xml.messaging.ReqRespListener; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPBodyElement; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPFault; import javax.xml.soap.SOAPMessage; import java.util.Iterator; public class XMLHelloService implements ReqRespListener { MessageFactory factory; //constructor public XMLHelloService() { try { this.factory = MessageFactory.newInstance(); } catch (SOAPException e) { throw new RuntimeWrappedException(e); } } public SOAPMessage onMessage(SOAPMessage message) { try { // read request SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); Iterator operations = body.getChildElements(envelope.createName("string_Request", null, "http://systinet.com/xsd/SchemaTypes/")); String requestString = ((SOAPElement) operations.next()).getValue(); // create response SOAPMessage respMessage = factory.createMessage(); SOAPEnvelope respEnvelope = respMessage.getSOAPPart().getEnvelope(); SOAPBody respBody = respEnvelope.getBody(); SOAPBodyElement bodyElement = respBody.addBodyElement(respEnvelope.createName("string_Response", null, "http://systinet.com/xsd/SchemaTypes/")); bodyElement.addTextNode("Hello, " + requestString + "!"); return respMessage; } catch (Exception e) { try { // create fault SOAPMessage faultMessage = factory.createMessage(); SOAPBody body = faultMessage.getSOAPPart().getEnvelope().getBody(); SOAPFault fault = body.addFault(); fault.setFaultCode("Server"); fault.setFaultString("SOAP Message could not be processed"); return faultMessage; } catch (SOAPException ee) { throw new RuntimeWrappedException(e); } } } }