/*
 * SuperFlacoHandler.java
 * 
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * 
 * Original author: Jonathan Colwell
 */
package org.apache.beehive.wsm.axis;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;

import org.apache.axis.message.PrefixedQName;

/*******************************************************************************
 * 
 *
 * @author Jonathan Colwell
 */
public class SuperFlacoHandler extends GenericHandler {


    public boolean handleRequest(MessageContext mc)
    {
        System.err.println("handling request");
        return true;
    }

    public boolean handleResponse(MessageContext mc)
    {
        System.err.println("handling response");
        try {
            if (mc instanceof SOAPMessageContext) {
                SOAPMessage msg = ((SOAPMessageContext)mc).getMessage();
                if (msg != null) {
                    SOAPBodyElement sbe = msg.getSOAPBody()
                    .addBodyElement(new PrefixedQName(new QName("SuperFlaco")));
                    sbe.addTextNode("funkadelic");
                    msg.saveChanges();
                    //return true;
                }
            }
        }
        catch (Exception se) {
            System.err.println("Doh!: " + se.toString());
            return false;
        }
        System.err.println("handled response");
        return true;
    }

    public QName[] getHeaders()
    {
        return new QName[]{new QName("SuperFlaco")};
    }
}
