You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Craig Fisher <cr...@itg-ak.com> on 2002/10/28 09:18:43 UTC

re-writing the message in handler

All--

For reasons far to convoluted to broach here I am trying to re-write the
SOAPBody.  I feel like I am very close but just missing it but a bit.  Maybe
someone will see something I do not.  I have written a service specific
handler called THandler which seeks to re-write the SOAPBody.  The following
is the code for THandler (there is a good chance I am importing stuff I
don't need as I have been flailing at this code a while...):


package interwest.myalaska;

import org.apache.axis.AxisFault;
import org.apache.axis.Handler;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;

import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Iterator;

import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.Options;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.*;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPElement;
import org.apache.axis.soap.SOAPFactoryImpl;
import org.apache.axis.message.*;
import javax.xml.namespace.QName;


public class THandler extends BasicHandler {
    public void invoke(MessageContext msgContext) throws AxisFault
    {
        try {
            SOAPMessage msg = msgContext.getMessage();
            msgContext.setProperty("Name", "Value");
            SOAPPart sp = msg.getSOAPPart();
            SOAPEnvelope se = (SOAPEnvelope)sp.getEnvelope();
            SOAPBody sb = (SOAPBody)se.getBody();
            Iterator i = sb.getChildElements();
            MessageElement sbe = (MessageElement)i.next();
            SOAPFactoryImpl sf = new SOAPFactoryImpl();
            MessageElement ne =
(MessageElement)sbe.addChildElement(sf.createName("RAuser"));
            ne.addAttribute("http://www.w3.org/2001/XMLSchema-instance",
"type", "xsd:string");
            ne.addTextNode("new text node");

		//this stuff is a vain attempt to see what is going on...
            FileOutputStream msgfile = new
FileOutputStream("c:\\temp\\msg.xml", false);
            msg.writeTo(msgfile);
            msgfile.close();

            FileOutputStream packetfile = new
FileOutputStream("c:\\temp\\element.xml", false);
            PrintWriter packetwriter = new PrintWriter(packetfile);
            packetwriter.println(ne.toString());
            packetwriter.close();
            FileOutputStream sbefile = new
FileOutputStream("c:\\temp\\sbe.xml", false);

            PrintWriter SBEwriter = new PrintWriter(sbefile);
            SBEwriter.println(sbe.toString());
            SBEwriter.close();
            packetwriter.close();


        } catch (Excepgtion e) {
            throw AxisFault.makeFault(e);
        }
    }
}

>>From what I can tell the new element gets written to the SOAPBodyElement but
it is wrong somehow...  (And for what it is worth all the file wrtiing at
the bottom is useles... the msg act like it never changes...)

I can't seem to figure out how.  Anyone got a clue?


Craig Fisher
InterWEST Technology Group, Inc.
http://www.itg-ak.com/
craig@itg-ak.com
907-301-1010