4

Basically I made a Webservice using JAXWS. It uses SOAP and works. However on some request some clients crash/error, it seems to be linked to the fact the JAXWS webservice does not send the content-length header. Is there a way to add it?

Using: openjdk-6 (6b20)

My class looks like this:

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.Endpoint;

@WebService
public class SOAP {
public static void main(String[] args) {
    try {
        SOAP server = new SOAP();
        Endpoint endpoint = Endpoint.publish('localhost:1234', server);
    } catch (Exception e) {
                Utils.getLog("SOAP").fatal("General Error", e);
    }
}
}

Using tcpdump confirms there is no content-length in the response:

0x0000:  4500 00b0 4da5 4000 4006 20d5 5cf3 1021  E...M.@.@...\..!
0x0010:  5cf3 01c7 13b2 bcea a9be 716e 14c3 16a1  \.........qn....
0x0020:  8018 006c cc70 0000 0101 080a 2e1b 3ccc  ...l.p........<.
0x0030:  2e18 23a2 4854 5450 2f31 2e31 2032 3030  ..#.HTTP/1.1.200
0x0040:  204f 4b0d 0a54 7261 6e73 6665 722d 656e  .OK..Transfer-en
0x0050:  636f 6469 6e67 3a20 6368 756e 6b65 640d  coding:.chunked.
0x0060:  0a43 6f6e 7465 6e74 2d74 7970 653a 2074  .Content-type:.t
0x0070:  6578 742f 786d 6c3b 6368 6172 7365 743d  ext/xml;charset=
0x0080:  2275 7466 2d38 220d 0a44 6174 653a 2053  "utf-8"..Date:.S
0x0090:  6174 2c20 3137 2053 6570 2032 3031 3120  at,.17.Sep.2011.
0x00a0:  3134 3a31 393a 3337 2047 4d54 0d0a 0d0a  14:19:37.GMT....

So my question is, is there a way to tell the webservice to send the content-length along with the reply? Or a way to append it before the reply is sent?

Neck
  • 43
  • 1
  • 3
  • 1
    `Transfer-encoding chunked` does not have a `content-length` header. http://en.wikipedia.org/wiki/Chunked_transfer_encoding - I suspect your problem lies elsewhere. – Brian Roach Sep 17 '11 at 16:18
  • Good point... Time to dig more to find why some requests do not seem to be "complete" although all data is sent out. – Neck Sep 17 '11 at 16:22
  • You should wonder why the client has a problem. All HTTP/1.1 clients must support Transfer-encoding: chunked and not require a content-length to work. If the client does not support this, then that client must use HTTP/1.0 – Mark Rotteveel Sep 17 '11 at 17:00
  • This is what I ended with as well. Appears to be a bug with the client side (php in this case). Due to ANOTHER bug, it ignores forcing http 1.0 if wsdl cache is enabled. I am left trying to disable chunking in JAXWS... if anyone has a lead? – Neck Sep 17 '11 at 17:24
  • Setting the content-length header should do the trick on the response. Also connection=close on either the client or response header. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html. Either way my answer below should help. – Simeon G Sep 17 '11 at 17:58
  • After more digging, it seems to be a bug with JAXWS, see the output of curl fetching the same reply: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 106 4190 0 4190 0 260 25 1 --:--:-- 0:02:43 --:--:-- 0 106% ? – Neck Sep 17 '11 at 18:24

2 Answers2

3

You can add HTTP headers to the outgoing response by writing a handler. Your handler will extend the standard JAX-WS handler and use the MessageContext in the handleMessage(C context) method to modify the HTTP_RESPONSE_HEADER property (actually a key in the map). So for example your handler will be:

public class MyHandler<SOAPMessageContext> implements Handler {

    public boolean handleMessage(SOAPMessageContext c) {
        if((Boolean)c.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
            c.put(SOAPMessageContext.HTTP_RESPONSE_HEADERS,"your header stuff here");
            return true;
        }
    }
 }

You will need to create a handler-chain file and add an annotation pointing to that file in your endpoint class. The annotation is @HandlerChain(file="...");

Once you do this you should be able to modify HTTP headers on in and outbound. HTH.

Simeon G
  • 1,188
  • 8
  • 20
1

I had a similar issue where a provider would not accept a chunked message... it would not set the Content-length in the header either and would actually chunk the message and the web service provider would reject my call... This was using JAX-WS with Axis2 1.6 as the JAX-WS runtime.

I tried add the HTTP headers to manually add Content-length, but this would cause other issues. I eventually got it to work by setting the HTTPConstants.CHUNKED to false on the SOAPMessageContext in a Handler.

I blogged about here: http://btarlton.blogspot.com/2013/03/jax-ws-with-axis2-how-to-disable.html#!/2013/03/jax-ws-with-axis2-how-to-disable.html

With Axis2 as the JAX-WS runtime, this was the only fix I could find.

  • You should add the main parts of your link to this answer. This way if later your blog goes down the answer wouls still contain important information – SztupY Mar 12 '13 at 15:24