FileDocCategorySizeDatePackage
ServiceHandler2.javaAPI DocApache Axis 1.45423Sat Apr 22 18:57:26 BST 2006test.wsdl.jaxrpchandlereval

ServiceHandler2

public class ServiceHandler2 extends Object implements Handler

Fields Summary
Constructors Summary
public ServiceHandler2()

        System.out.println("ServiceHandler2:Constructor");
    
Methods Summary
public voiddestroy()

        System.out.println("ServiceHandler2:destroy");
    
public javax.xml.namespace.QName[]getHeaders()

        System.out.println("ServiceHandler2:getHeaders");
        return null;
    
public booleanhandleFault(MessageContext context)

        System.out.println("\nServiceHandler2:handleFault");
        try {
            SOAPMessageContext soapMsgCtx = (SOAPMessageContext)context;
            SOAPMessage soapMsg = soapMsgCtx.getMessage();

            soapMsg = prepareError(soapMsgCtx);


            // soapMsg.writeTo(System.out);

            SOAPPart sp = soapMsg.getSOAPPart();
            SOAPEnvelope se = sp.getEnvelope();
            SOAPBody sb = se.getBody();
            SOAPHeader sh = se.getHeader();

            Name xmlServicesHandler2HdrName =
                se.createName("ServiceHandler2-handleFault", "", "");
            SOAPHeaderElement xmlServicesHandler2Hdr =
                sh.addHeaderElement(xmlServicesHandler2HdrName);
            xmlServicesHandler2Hdr.addTextNode(
                "Processed by ServiceHandler2Hdr2.handleFault");


         } catch (Exception ex) {
             ex.printStackTrace();
         }
        return true;
    
public booleanhandleRequest(MessageContext context)

        System.out.println("ServiceHandler2:handleRequest");

         try {
            SOAPMessageContext soapMsgCtx = (SOAPMessageContext)context;
            SOAPMessage soapMsg = soapMsgCtx.getMessage();
            SOAPPart sp = soapMsg.getSOAPPart();
            SOAPEnvelope se = sp.getEnvelope();
            SOAPBody sb = se.getBody();
            SOAPHeader sh = se.getHeader();

            Name xmlServicesHandler2HdrName =
                se.createName("ServiceHandler2-handleRequest", "", "");
            SOAPHeaderElement xmlServicesHandler2Hdr =
                sh.addHeaderElement(xmlServicesHandler2HdrName);
            xmlServicesHandler2Hdr.addTextNode(
                "Processed by ServiceHandler2Hdr2.handleRequest");

			/*--- getElementsByTagName() does not work.
			NodeList list = sb.getElementsByTagName("in0");
			if (list.getLength() == 0) {
				throw new JAXRPCException("No such element : 'in0'");
			}
			SOAPElement elem = (SOAPElement) list.item(0);
            String curBody = elem.getValue();
			---*/
			String curBody = sb.toString();
            if (curBody.indexOf("server-throw-soapfaultexception") >= 0) {
                String reason = "A FATAL EXCEPTION has occurred while processing ServiceHandler2.handleRequest";
                soapMsgCtx.setProperty("fault", reason);

                QName faultcode = new QName("Testimg Exception",
                                            "http://example.org/security/");
                throw new SOAPFaultException(faultcode, reason, null, null);
                //throw new JAXRPCException(reason);
            } else if (curBody.indexOf("server-return-false") >= 0) {
                soapMsgCtx.setProperty("fault",
                        "An error has occurred while processing ServiceHandler2.handleRequest - returning false");
                return false;
            }
         } catch (SOAPException ex) {
             throw new JAXRPCException(ex);
         }
        return true;
    
public booleanhandleResponse(MessageContext context)

        System.out.println("ServiceHandler2:handleResponse");

        try {
            SOAPMessageContext soapMsgCtx = (SOAPMessageContext)context;
            SOAPMessage soapMsg = soapMsgCtx.getMessage();
            if (soapMsg == null) {
                soapMsg = prepareError(soapMsgCtx);
            }

            SOAPPart sp = soapMsg.getSOAPPart();
            SOAPEnvelope se = sp.getEnvelope();
            SOAPBody sb = se.getBody();
            SOAPHeader sh = se.getHeader();

            Name xmlServicesHandler2HdrName =
                se.createName("ServiceHandler2-handleResponse", "", "");
            SOAPHeaderElement xmlServicesHandler2Hdr =
                sh.addHeaderElement(xmlServicesHandler2HdrName);
            xmlServicesHandler2Hdr.addTextNode(
                "Processed by ServiceHandler2Hdr2.handleResponse");


         } catch (Exception ex) {
             throw new JAXRPCException(ex);
         }
        return true;
    
public voidinit(HandlerInfo config)

        System.out.println("ServiceHandler2:init");
    
public javax.xml.soap.SOAPMessageprepareError(javax.xml.rpc.handler.soap.SOAPMessageContext soapMsgCtx)

        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMsg = messageFactory.createMessage();
        soapMsgCtx.setMessage(soapMsg);

        String fault = (String)soapMsgCtx.getProperty("fault");
        if (fault != null) {
            SOAPFault soapFault =
                soapMsg.getSOAPPart().getEnvelope().getBody().addFault();
            soapFault.setFaultString(fault);
        }
        return soapMsg;