Axis2
  1. Axis2
  2. AXIS2-1014

org.apache.asix2.saaj.SOAPConnectionImpl does not handle MimeHeaders (SOAPAction)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.3, 1.6.0
    • Component/s: saaj
    • Labels:
      None

      Description

      I looked into org.apache.axis2.saaj.SOAPConnectionImpl.java in the
      Axis2 Source Repositoy, as the following code snippet shown, it
      never pass down MimeHeaders from SOAPMessage to the ServiceClient,
      so all the SOAPMessages with empty SOAPAction as ""

      ==========================================
      public SOAPMessage call(SOAPMessage request, Object endpoint) throws SOAPException {

      if (closed)

      { throw new SOAPException("SOAPConnection closed"); }

      // initialize URL
      URL url;
      try

      { url = (endpoint instanceof URL) ? (URL) endpoint : new URL(endpoint.toString()); }

      catch (MalformedURLException e)

      { throw new SOAPException(e); }

      // initialize and set Options
      Options options = new Options();
      options.setTo(new EndpointReference(url.toString()));

      // initialize the Sender
      OperationClient opClient;
      try { serviceClient = new ServiceClient(); opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP); } catch (AxisFault e) { throw new SOAPException(e); }

      opClient.setOptions(options);

      if (request.countAttachments() != 0)

      { // SOAPMessage with attachments opClient.getOptions().setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); return handleSOAPMessage(request, opClient); }

      else

      { // simple SOAPMessage return handleSOAPMessage(request, opClient); }

      }

      private SOAPMessage handleSOAPMessage(SOAPMessage request,
      OperationClient opClient) throws SOAPException {

      MessageContext requestMsgCtx = new MessageContext();
      try

      { requestMsgCtx.setEnvelope(toOMSOAPEnvelope(request)); opClient.addMessageContext(requestMsgCtx); opClient.execute(true); MessageContext msgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); //TODO: get attachments return getSOAPMessage(msgCtx.getEnvelope()); }

      catch (AxisFault e)

      { throw new SOAPException(e); }

      }

      protected org.apache.axiom.soap.SOAPEnvelope toOMSOAPEnvelope(SOAPMessage saajSOAPMsg)
      throws SOAPException {

      final org.apache.axiom.soap.SOAPEnvelope omSOAPEnv =
      SAAJUtil.toOMSOAPEnvelope(saajSOAPMsg.getSOAPPart().getDocumentElement());
      System.err.println("#### req OM Soap Env=" + omSOAPEnv);

      Map attachmentMap = new HashMap();
      final Iterator attachments = saajSOAPMsg.getAttachments();
      while (attachments.hasNext()) {
      final AttachmentPart attachment = (AttachmentPart) attachments.next();
      if (attachment.getContentId() == null ||
      attachment.getContentId().trim().length() == 0)

      { attachment.setContentId(IDGenerator.generateID()); }

      if (attachment.getDataHandler() == null)

      { throw new SOAPException("Attachment with NULL DataHandler"); }

      attachmentMap.put(attachment.getContentId(), attachment);
      }

      insertAttachmentNodes(attachmentMap, omSOAPEnv);

      // printOMSOAPEnvelope(omSOAPEnv);

      return omSOAPEnv;
      }
      ======================================

      As suggested by Davanum Srinivas, I file this bug to track this problem

        Activity

        Hide
        Davanum Srinivas added a comment -

        Sumedha,

        Please check if this works now.

        – dims

        Show
        Davanum Srinivas added a comment - Sumedha, Please check if this works now. – dims
        Hide
        Deepal Jayasinghe added a comment -

        No point of keeping these issues open forever

        Show
        Deepal Jayasinghe added a comment - No point of keeping these issues open forever
        Hide
        Glen Daniels added a comment -

        "No point of keeping these issues open forever"?

        Is it fixed, or not?

        Show
        Glen Daniels added a comment - "No point of keeping these issues open forever"? Is it fixed, or not?
        Hide
        Takayoshi Fujiki added a comment -

        Hi,

        Although, I'm not submitter but I have same problem with Axis2 now. Could someone give me comment on this?

        I downloaded rev.675563 Axis2 source codes from svn, and tried the following code with it.
        (This also occurs with Axis2 1.4)

        import java.net.MalformedURLException;
        import java.net.URL;

        import javax.xml.namespace.QName;
        import javax.xml.soap.MessageFactory;
        import javax.xml.soap.MimeHeaders;
        import javax.xml.soap.SOAPBody;
        import javax.xml.soap.SOAPConnection;
        import javax.xml.soap.SOAPConnectionFactory;
        import javax.xml.soap.SOAPEnvelope;
        import javax.xml.soap.SOAPException;
        import javax.xml.soap.SOAPMessage;

        public class Axis2SoapTest {
        public static void main(String[] args) {
        try

        { MessageFactory mfactory = MessageFactory.newInstance(); SOAPMessage message = mfactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); MimeHeaders headers = message.getMimeHeaders(); headers.setHeader("SOAPAction", "\"urn:myUrn#myAction\""); SOAPBody body = message.getSOAPBody(); body.addBodyElement(new QName("urn:myUrn", "myAction", "u")); SOAPConnectionFactory cfactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = cfactory.createConnection(); connection.call(message, new URL("http://10.3.10.13:55247/")); connection.close(); }

        catch(SOAPException e)

        { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); }

        }
        }

        But this code sends the following request to the server. SOAPAction header was "urn:anonOutInOp".("urn:myUrn#myAction" is expected.)
        It seems that call() method still did not see MimeHeaders.

        POST / HTTP/1.1
        Content-Type: text/xml; charset=UTF-8
        SOAPAction: "urn:anonOutInOp"
        User-Agent: Axis2
        Host: 10.3.10.13:55247
        Transfer-Encoding: chunked

        c4
        <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><u:myAction xmlns:u="urn:myUrn" /></soapenv:Body></soapenv:Envelope>
        0

        FYI, the above code works properly with JDK default library.
        POST / HTTP/1.1
        Accept: text/xml, text/html, image/gif, image/jpeg, ; q=.2, */; q=.2
        SOAPAction: "urn:myUrn#myAction"
        Content-Type: text/xml; charset=utf-8
        Content-Length: 229
        Cache-Control: no-cache
        Pragma: no-cache
        User-Agent: Java/1.6.0_06
        Host: 10.3.10.13:55247
        Connection: keep-alive

        <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><u:myAction xmlns:u="urn:myUrn"/></SOAP-ENV:Body></SOAP-ENV:Envelope>

        Thanks in advance.

        Show
        Takayoshi Fujiki added a comment - Hi, Although, I'm not submitter but I have same problem with Axis2 now. Could someone give me comment on this? I downloaded rev.675563 Axis2 source codes from svn, and tried the following code with it. (This also occurs with Axis2 1.4) import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.soap.MessageFactory; import javax.xml.soap.MimeHeaders; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPConnection; import javax.xml.soap.SOAPConnectionFactory; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; public class Axis2SoapTest { public static void main(String[] args) { try { MessageFactory mfactory = MessageFactory.newInstance(); SOAPMessage message = mfactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); MimeHeaders headers = message.getMimeHeaders(); headers.setHeader("SOAPAction", "\"urn:myUrn#myAction\""); SOAPBody body = message.getSOAPBody(); body.addBodyElement(new QName("urn:myUrn", "myAction", "u")); SOAPConnectionFactory cfactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = cfactory.createConnection(); connection.call(message, new URL("http://10.3.10.13:55247/")); connection.close(); } catch(SOAPException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } } } But this code sends the following request to the server. SOAPAction header was "urn:anonOutInOp".("urn:myUrn#myAction" is expected.) It seems that call() method still did not see MimeHeaders. POST / HTTP/1.1 Content-Type: text/xml; charset=UTF-8 SOAPAction: "urn:anonOutInOp" User-Agent: Axis2 Host: 10.3.10.13:55247 Transfer-Encoding: chunked c4 <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><u:myAction xmlns:u="urn:myUrn" /></soapenv:Body></soapenv:Envelope> 0 FYI, the above code works properly with JDK default library. POST / HTTP/1.1 Accept: text/xml, text/html, image/gif, image/jpeg, ; q=.2, */ ; q=.2 SOAPAction: "urn:myUrn#myAction" Content-Type: text/xml; charset=utf-8 Content-Length: 229 Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.6.0_06 Host: 10.3.10.13:55247 Connection: keep-alive <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><u:myAction xmlns:u="urn:myUrn"/></SOAP-ENV:Body></SOAP-ENV:Envelope> Thanks in advance.
        Hide
        Ulf Dittmer added a comment - - edited

        Yep, it's still there in 1.4. It may be resolved, but it's not fixed.

        Guys, this is a biggie. Please make this part of 1.4.1.

        WS-Security doesn't work if the WSA-Addressing Action value isn't the same as the SOAPAction header, and because of this bug it's not possible to set SOAPAction.

        And since the Authorization HTTP header also can't be set, it's not possible to properly secure SAAJ services using HTTP authentication, either.

        Show
        Ulf Dittmer added a comment - - edited Yep, it's still there in 1.4. It may be resolved, but it's not fixed. Guys, this is a biggie. Please make this part of 1.4.1. WS-Security doesn't work if the WSA-Addressing Action value isn't the same as the SOAPAction header, and because of this bug it's not possible to set SOAPAction. And since the Authorization HTTP header also can't be set, it's not possible to properly secure SAAJ services using HTTP authentication, either.
        Hide
        Ulf Dittmer added a comment -

        As a stopgap measure to get SOAPAction to work, add the following lines before "opClient.setOptions(options);":

        MimeHeaders mh = request.getMimeHeaders();
        String[] action = mh.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
        if (action != null)
        options.setAction(action[0]);

        You'll also need:

        import org.apache.axis2.transport.http.HTTPConstants;

        With that change, it's possible to use WS-Security with SAAJ clients. I still think this is a major bug; I really don't understand why it's been lingering for years.

        Show
        Ulf Dittmer added a comment - As a stopgap measure to get SOAPAction to work, add the following lines before "opClient.setOptions(options);": MimeHeaders mh = request.getMimeHeaders(); String[] action = mh.getHeader(HTTPConstants.HEADER_SOAP_ACTION); if (action != null) options.setAction(action [0] ); You'll also need: import org.apache.axis2.transport.http.HTTPConstants; With that change, it's possible to use WS-Security with SAAJ clients. I still think this is a major bug; I really don't understand why it's been lingering for years.
        Hide
        Ulf Dittmer added a comment -

        Seeing that Axis-1.5 is coming up, is there a chance to get this fixed? I don't think it's resolved, and it's definitely not fixed, despite what Deepal's comment says.

        Actually, at this point, I'd be happy if someone even so much as commented on this issue, as a sign that it's not completely off everyone's radar.

        Show
        Ulf Dittmer added a comment - Seeing that Axis-1.5 is coming up, is there a chance to get this fixed? I don't think it's resolved, and it's definitely not fixed, despite what Deepal's comment says. Actually, at this point, I'd be happy if someone even so much as commented on this issue, as a sign that it's not completely off everyone's radar.
        Hide
        Nico Hoogervorst added a comment -

        Please reopen, it's not fixed in the latest revision (737757).

        Look in the call-method of SOAPConnectionImpl, it does not set the action in the options, and neither does it copy the MimeHeaders.
        OperationClient is always created with the ServiceClient.ANON_OUT_IN_OP name.
        The resulting SOAPAction is always:
        SOAPAction: "urn:anonOutInOp"
        or
        "urn:anonOutInOpResponse" (WS-Addressing module on)

        Show
        Nico Hoogervorst added a comment - Please reopen, it's not fixed in the latest revision (737757). Look in the call-method of SOAPConnectionImpl, it does not set the action in the options, and neither does it copy the MimeHeaders. OperationClient is always created with the ServiceClient.ANON_OUT_IN_OP name. The resulting SOAPAction is always: SOAPAction: "urn:anonOutInOp" or "urn:anonOutInOpResponse" (WS-Addressing module on)
        Hide
        Andreas Veithen added a comment -

        Fixed in trunk.

        Show
        Andreas Veithen added a comment - Fixed in trunk.

          People

          • Assignee:
            Andreas Veithen
            Reporter:
            Jian Wu
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development