Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Length header not being sent? #109

Closed
uplink42 opened this issue Apr 13, 2020 · 9 comments
Closed

Content-Length header not being sent? #109

uplink42 opened this issue Apr 13, 2020 · 9 comments
Assignees
Labels

Comments

@uplink42
Copy link

Hello and first of all thanks for this great library.

I'm currently performing some tests with a trading partner and apparently the messages are not being processed in the other end because the 'Content-Length' header is missing. I assume this has to do with the way the trasnfer encoding works with as2-lib (it's being set as chunked). Is there any way to disable this behavior and force it to send the 'content-length' header? I couldn't find anything in the documentation.

@phax phax self-assigned this Apr 13, 2020
@phax phax added the question label Apr 13, 2020
@phax
Copy link
Owner

phax commented Apr 13, 2020

This is a tricky one, because it depends on many parameters:

  • The source you are using (stream based or fully available)
  • The usage of compression or not
  • The usage of encryption or not
  • The Content-Transfer-Encoding used
  • Whether chunked encoding is used or not

I've scanned the code and I've seen no evidence of setting the header anywhere. It is only evaluated when reading incoming messages...

@uplink42
Copy link
Author

Interestingly enough, I'm getting an error indicating it's being set somewhere if I try to add it manually.

In AS2SenderModule.java, updateHttpHeaders method I've added a simple header to the message:

try {
      MimeBodyPart message = aMsg.getData();
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      message.writeTo(os);
      int bytes = os.size();

      aHeaderMap.setHeader("Content-Length", String.valueOf(bytes));

       System.out.println(String.valueOf(bytes));
    } catch (IOException ex) {
      System.out.println(ex);
      // nothing
    } catch (MessagingException ex) {
      System.out.println(ex);
      // nothing
    }

When I try to send a new message I get the following error:

as2-lib 4.5.1-SNAPSHOT WrappedAS2Exception terminated: org.apache.http.client.ClientProtocolException; 

Caused by: org.apache.http.ProtocolException: Content-Length header already present
        at org.apache.http.protocol.RequestContent.process(RequestContent.java:97) ~[httpcore-4.4.12.jar:4.4.12]

If I were to completly disable chunked encoding and instead always provide a Content-Length, where would be the most appropriate place to do this?

@phax
Copy link
Owner

phax commented Apr 13, 2020

Ah okay, so than it is something Apache HttpClient does on it's own :)
Than it happens in AS2HttpClient.send - lines 172ff

@uplink42
Copy link
Author

uplink42 commented Apr 14, 2020

I see. Thanks

Would an option to disable stream based requests be a possibility? There's still a few AS2 clients out there that don't support chunked encoding.

Open AS2 seems to still support it, but unfortunately this option has no effect with as2-lib:

14.5. Content Length Versus Chunked
OpenAS2 will send all messages using the “chunked” mechanism wherby the actual size of the
payload is not pre-determined and sent as a header”Transfer-Encoding=chunked”. Some systems
cannot handle the chiunked mechanism (it was standardised in HTTP 1.1) and require the
“Content-Length” header is used instead. To make OpenAS2 use the “Content-Length” header
method, set the following attribute on the partnership that needs it:

attribute name="no_chunked_max_size" value="104857600"/

@phax
Copy link
Owner

phax commented Apr 14, 2020

Okay, let me see what I can do...

@uplink42
Copy link
Author

Thank you for your time :)

@uplink42
Copy link
Author

uplink42 commented Jul 6, 2020

@phax did you manage to find anything? I have been hitting my head against the wall trying to create a message witouth chunked encoding but so far I'm unable to.

I noticed the option to send chunked messages replaced the old 'default' method in version 4.4

Remove support for the old HttpUrlConnection, therefore making "large file support" the default (see #87)

Is there a chance we can have an option to toggle this back? Some AS2 clients are unable to recieve chunked messages and simply die. :(

phax added a commit that referenced this issue Jul 14, 2020
@phax
Copy link
Owner

phax commented Jul 14, 2020

I tried to add the Content-Length; can you please try with 4.6.1-SNAPSHOT? Thx

@phax
Copy link
Owner

phax commented Jul 15, 2020

Closing this, as it is contained in 4.6.1

@phax phax closed this as completed Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants