简体   繁体   中英

Getting 403: Forbidden when consuming SOAP service using apache cxf in java

While trying to consume a SOAP service using apache cxf 3.1.6 and java 8, by changing the payload content, I am getting either a '200 OK' or '403 Forbidden'.

The weird part is, if I print out the payload and put on SOAPUI, then I always get 200 OK.

Have you encountered a similar issue? how to solve this?

So you do not get stuck for days like me, scratching the head and thinking why on earth that is happening, here is the issue explained and the solution.

The issue happens because by default apach cxf uses "Chunking", which basically sends small chunks of data to the endpoint, once the defined threshold is reached. That results in SOAP messages being sent while not complete, resulting in a '403' (assuming that the server does not support 'chunking')! The solution is to disable "Chunking", by changing spring-config.xml to:

  <http-conf:conduit name="*.http-conduit">
<http-conf:client Connection="Keep-Alive"
                  MaxRetransmits="1"
                  AllowChunking="false" />

Additional info:

on org.apache.cxf.transport.http.HTTPConduit, for the "prepare" method there is this bit that explains all:

// DELETE does not work and empty PUTs cause misleading exceptions
        // if chunking is enabled
        // TODO : ensure chunking can be enabled for non-empty PUTs - if requested
        if (csPolicy.isAllowChunking() 
            && isChunkingSupported(message, httpRequestMethod)) {
            //TODO: The chunking mode be configured or at least some
            // documented client constant.
            //use -1 and allow the URL connection to pick a default value
            isChunking = true;
            chunkThreshold = csPolicy.getChunkingThreshold();
        }
        cookies.writeToMessageHeaders(message);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM