/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.webservice.jbws167;

import javax.xml.namespace.QName;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.soap.MimeHeaders;

import org.jboss.logging.Logger;

public class HeaderHandler extends GenericHandler
{
   // provide logging
   private static Logger log = Logger.getLogger(HeaderHandler.class);
   
   protected QName[] headers;

   public QName[] getHeaders()
   {
      return headers;
   }

   public void init(HandlerInfo config)
   {
      headers = config.getHeaders();
   }

   public void destroy()
   {
   }

   public boolean handleRequest(MessageContext msgContext)
   {
      return true;
   }

   public boolean handleResponse(MessageContext msgContext)
   {
      log.info("handleResponse");
      SOAPMessageContext context = (SOAPMessageContext) msgContext;
      MimeHeaders headers = context.getMessage().getMimeHeaders();
      headers.addHeader("server-test-header", "1");
      headers.addHeader("server-test-header", "2");
      headers.addHeader("server-test-header", "3");
      return true;
   }

   public boolean handleFault(MessageContext msgContext)
   {
      return true;
   }
}
