An upload retried after a proxy challenge needs its body again. For Jersey 2's Apache connector, select buffered entity processing on the configuration used to build that client:

ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ClientProperties.PROXY_URI,
                "http://proxy.example.net:8080");
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING,
                RequestEntityProcessing.BUFFERED);

Perform the upload through the resulting client. These types come from Jersey client and Apache-connector packages; setting an unused config would not affect the request.

The connector wraps a buffered entity in Apache's BufferedHttpEntity. Its nonbuffered streaming entity is not repeatable. Buffering provides the authentication flow with bytes it can resend instead of rereading a consumed producer.

It does not guarantee that authentication ends after one 407. Some schemes legitimately require several exchanges, so inspect the whole negotiation before treating another challenge as lost state.

Keep the body size within the memory budget. A large streaming upload needs a replay strategy suited to that workload; enabling buffering for every request can trade a negotiation failure for memory exhaustion.

Artihkkalat mat laktásit