FileDocCategorySizeDatePackage
ClientHandler2.javaAPI DocApache Axis 1.45961Sat Apr 22 18:57:28 BST 2006test.wsdl.jaxrpchandlereval

ClientHandler2

public class ClientHandler2 extends Object implements javax.xml.rpc.handler.Handler

Fields Summary
private static final String
_actorURI
Constructors Summary
public ClientHandler2()
Constructor for ClientHandler2.

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

see
javax.xml.rpc.handler.Handler#destroy()

    System.out.println("ClientHandler2.destroy");

public javax.xml.namespace.QName[]getHeaders()

see
javax.xml.rpc.handler.Handler#getHeaders()

    System.out.println("ClientHandler2.getheaders");

    return null;
public booleanhandleFault(javax.xml.rpc.handler.MessageContext context)

see
javax.xml.rpc.handler.Handler#handleFault(MessageContext)

    System.out.println("ClientHandler2:handleFault");
	HandlerTracker.addClientHandler("clienthandler2.handleFault");
    if (context instanceof SOAPMessageContext) {
        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 name = se.createName("ClientHandler2-handleFault", "", "");
            SOAPHeaderElement hdr = sh.addHeaderElement(name);
            hdr.addTextNode("Processed");
        } catch (SOAPException ex) {
            ex.printStackTrace();
            return false;
        } catch (Exception ex) {
            ex.printStackTrace();

             throw new JAXRPCException(ex);
         }
    }
    return true;
public booleanhandleRequest(javax.xml.rpc.handler.MessageContext context)

see
javax.xml.rpc.handler.Handler#handleRequest(MessageContext)

    System.out.println("ClientHandler2:handleRequest");
	HandlerTracker.addClientHandler("clienthandler2.handleRequest");

    if (context instanceof SOAPMessageContext) {
        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 name = se.createName("ClientHandler2-handleRequest", "", "");
            SOAPHeaderElement hdr = sh.addHeaderElement(name);
            hdr.addTextNode("Processed");

            String instruction = sb.toString();

            if (instruction.indexOf("client-throw-jaxrpcexception") >= 0) {
                soapMsgCtx.setProperty("fault", "Throwing a client side exception from ClientHandler2.handleRequest");

                QName faultcode = new QName("Testimg Exception",
                                            "http://example.org/security/");
                // According to JAX-RPC spec client handlers cannot throw SOAPFaultException
                throw new JAXRPCException();
            } else if (instruction.indexOf("client-return-false") >= 0) {
                soapMsgCtx.setProperty("fault", "Returning false from ClientHandler2.handleRequest");
                return false;
            }


        } catch (SOAPException ex) {
            ex.printStackTrace();
            return false;
        }
    }
    return true;
public booleanhandleResponse(javax.xml.rpc.handler.MessageContext context)

see
javax.xml.rpc.handler.Handler#handleResponse(MessageContext)

    System.out.println("ClientHandler2:handleResponse");
	HandlerTracker.addClientHandler("clienthandler2.handleResponse");

    if (context instanceof SOAPMessageContext) {
        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 name = se.createName("ClientHandler2-handleResponse", "", "");
            SOAPHeaderElement hdr = sh.addHeaderElement(name);
            hdr.addTextNode("Processed");

        } catch (SOAPException ex) {
            ex.printStackTrace();
            return false;
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
            return false;
        } catch (Exception ex) {
             throw new JAXRPCException(ex);
         }

    }
    return true;
public voidinit(javax.xml.rpc.handler.HandlerInfo config)

see
javax.xml.rpc.handler.Handler#init(HandlerInfo)

    System.out.println("ClientHandler2.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;