saaj
  1. saaj
  2. SAAJ-15

SOAPMessage.getSOAPHeader returns null when there is no SOAPHeader

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      15

      Description

      As per API, it should throw SOAPException when there is no SOAPHeader.
      But it returns null.

      TestCase:
      String simple_sm = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
      "<S:Envelope
      xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Header/><S:Body><DataType
      xmlns=\"http://cptestservice.org/xsd\"><param>foo
      bar</param></DataType></S:Body></S:Envelope>";
      MessageFactory messageFactory = MessageFactory.newInstance();
      MimeHeaders headers = new MimeHeaders();
      headers.addHeader("Content-Type", "text/xml");
      SOAPMessage simple_soapMsg = messageFactory.createMessage(headers,
      new ByteArrayInputStream(simple_sm.getBytes()));
      SOAPHeader header = simple_soapMsg.getSOAPHeader();

        Activity

        Hide
        kumarjayanti added a comment -

        fixed

        Show
        kumarjayanti added a comment - fixed
        Hide
        ramapulavarthi added a comment -

        Can you please revert back the fix. Although the bug is valid as per the method
        contract, SAAJ API is not consistent regarding accessing SOAPHeader.

        For example, SOAPEnvelope.getHeader() says return null whn there is no header.
        This is contrast to whats offered on SOAPMessage.getSOAPHeader() which asks us
        to throw SOAPException. I don't a getXXX() methd should throw SOAPException.

        Since we don't know how the user has accesses the SOAPHeader, it better to leave
        the implementation as it was before.
        ----------------------------
        SOAPEnvelope.java
        /**

        • Returns the <code>SOAPHeader</code> object for
        • this <code>SOAPEnvelope</code> object.
        • <P>
        • A new <code>SOAPMessage</code> object is by default created with a
        • <code>SOAPEnvelope</code> object that contains an empty
        • <code>SOAPHeader</code> object. As a result, the method
        • <code>getHeader</code> will always return a <code>SOAPHeader</code>
        • object unless the header has been removed and a new one has not
        • been added.
          *
        • @return the <code>SOAPHeader</code> object or <code>null</code> if
        • there is none
        • @exception SOAPException if there is a problem obtaining the
        • <code>SOAPHeader</code> object
          */
          public SOAPHeader getHeader() throws SOAPException;
        Show
        ramapulavarthi added a comment - Can you please revert back the fix. Although the bug is valid as per the method contract, SAAJ API is not consistent regarding accessing SOAPHeader. For example, SOAPEnvelope.getHeader() says return null whn there is no header. This is contrast to whats offered on SOAPMessage.getSOAPHeader() which asks us to throw SOAPException. I don't a getXXX() methd should throw SOAPException. Since we don't know how the user has accesses the SOAPHeader, it better to leave the implementation as it was before. ---------------------------- SOAPEnvelope.java /** Returns the <code>SOAPHeader</code> object for this <code>SOAPEnvelope</code> object. <P> A new <code>SOAPMessage</code> object is by default created with a <code>SOAPEnvelope</code> object that contains an empty <code>SOAPHeader</code> object. As a result, the method <code>getHeader</code> will always return a <code>SOAPHeader</code> object unless the header has been removed and a new one has not been added. * @return the <code>SOAPHeader</code> object or <code>null</code> if there is none @exception SOAPException if there is a problem obtaining the <code>SOAPHeader</code> object */ public SOAPHeader getHeader() throws SOAPException;
        Hide
        kumarjayanti added a comment -

        I have reverted the fix. I was actually of the same opinion before making the
        fix that there will be some inconsistencies and wanted to talk to you before
        making the fix.

        However i decided to make the fix since i thought it was causing JAXWS TCK
        regressions/failures. Also the fix was in accordance with the javadoc.

        Show
        kumarjayanti added a comment - I have reverted the fix. I was actually of the same opinion before making the fix that there will be some inconsistencies and wanted to talk to you before making the fix. However i decided to make the fix since i thought it was causing JAXWS TCK regressions/failures. Also the fix was in accordance with the javadoc.

          People

          • Assignee:
            saaj-issues
            Reporter:
            ramapulavarthi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: