0 Replies Latest reply on May 5, 2013 6:52 PM by arulprashanth

    Issue accessing SOAP Header in JBoss AS7


      I have to access the Soap Header in the WebService Request and perform a functionality based on the information in header. I am running into the below issues


      1. I have a SOAPHandler written but when I access the header attributes all values are null but I can see any new attributes added as part of the request being available in SOAPHeader expect that the value is null.

      2. How can I access the header value in my WebMethod




      public class CustomSOAPHandler implements SOAPHandler<SOAPMessageContext>{



         public boolean handleMessage(SOAPMessageContext context) {


                                    System.out.println("Server : handleMessage()......");


                                    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

                                    //for response message only, true for outbound messages, false for inbound




                                        SOAPMessage soapMsg = context.getMessage();

                                        SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();

                                      SOAPHeader soapHeader = soapEnv.getHeader();

                                      System.out.println("Server : handleMessage()......"+isRequest);

                                        if (soapHeader == null){

                                                soapHeader = soapEnv.addHeader();

                                                throw new IllegalArgumentException("No SOAP header.");



                                         Iterator it = soapHeader.extractAllHeaderElements();

                                         System.out.println(" >> message_type_id >> "+soapHeader.getAttribute("message_type_id"));







                                              }catch(SOAPException e){


                                              }catch(IOException e){






                                      //continue other handler chain

                                      return true;




                                    public boolean handleFault(SOAPMessageContext context) {


                                              System.out.println("Server : handleFault()......");


                                              return true;




                                    public void close(MessageContext context) {

                                              System.out.println("Server : close()......");




                                    public Set<QName> getHeaders() {

                                        System.out.println("Inside SOAP handler of get Headers");

                                        QName messageTypeId = new QName("http://www.test.com","message_type_id");

                                        HashSet<QName> headers = new HashSet<QName>();


                                        System.out.println("got Headers:  " + headers);

                                              return headers;






      SOAP Request :


      <?xml version="1.0" encoding="UTF-8"?>

      <soapenv:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rule="http://ws.test.com/rule" xmlns:ws="http://ws.test.com/" xmlns:ebus="http://schemas.datacontract.org/2004/07/test.e.Components.Messaging">


                   <message_type_id mustUnderstand="1" xmlns="http://www.test.com">102</message_type_id>








      Server Output:


      stdout - Server : handleMessage()......

      stdout - Server : handleMessage()......false

      stdout -  >> message_type_id >>

      stdout - [message_type_id: null]

      stdout - <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">

      stdout -    <soapenv:Header>

      stdout -

      stdout -    </soapenv:Header>

      stdout -    <soapenv:Body>

      stdout -       <ws:Respond>

      stdout -       </ws:Respond>