views:

4

answers:

0

Hi, I am trying the Transform Response XML using the Handler, following is the code

import java.io.File; import java.io.OutputStream; import java.util.ArrayList; import java.util.List;

import javax.xml.rpc.handler.*;

import javax.xml.namespace.QName; import javax.xml.rpc.handler.soap.SOAPMessageContext; import javax.xml.rpc.JAXRPCException; import javax.xml.rpc.NamespaceConstants; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPBody; import org.w3c.dom.*;

import javax.xml.transform.TransformerFactory; import javax.xml.transform.Transformer; import javax.xml.transform.Source;

import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource;

public class PortfolioJaxrpcHandler extends GenericHandler {

HandlerInfo hi;

public void init(HandlerInfo info) {
    hi = info;
}

public QName[] getHeaders() {
    return hi.getHeaders();
}

public boolean handleResponse(MessageContext context) {

    System.out.println("response");
    File styleSheet=new File("PortfolioXSL.xsl");
    StreamSource stylesource = new StreamSource(styleSheet);


    try {

        // get the soap header
        SOAPMessageContext smc = (SOAPMessageContext) context;
        SOAPMessage message = smc.getMessage();


        // Create transformer
        TransformerFactory tff = TransformerFactory.newInstance();
        Transformer tf = tff.newTransformer(stylesource);

        // Get reply content
        Source sc = message.getSOAPPart().getContent();

        // Set output transformation
        StreamResult result = new StreamResult(System.out);

        tf.transform(sc, result);


        System.out.println();

    } catch (Exception e) {
        throw new JAXRPCException(e);
    }
    return true;
}

public boolean handleRequest(MessageContext context) {

    // return true to continue message processing
    return true;
}

}

I can see the trasnformed xml, but I am not able find the correct output stream in which I need to set the Transformed output. so that webservice client can pick up the tranformed xml, right now it throws null pointer exception. Thanks