• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Commons HTTPClient org.apache.http.HttpException: Unsupported Content-Coding: none

 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope this is the right place to post this question!

I am having a problem with Apache Commons' HTTPClient. When I try to execute a request on a few particular websites, it throws org.apache.http.HttpException: Unsupported Content-Coding: none at me.

The problem lies in the fact that there are web servers that send "Content-Encoding: none" header which is non-standards compliant (standard-compliant would have set value to "identity", btw). HTTPClient doesn't like that and it throws this exception.

I can't do anything to fix the issue on the server side, so I have to come up with something on my side. Is there any way to make HTTPClient ignore that "little mistake" from server? Or some hacky workaround, like adding custom encoding named "none"?

I tried googling but I haven't found anything useful.
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using a HttpResponseInterceptor?

You should be able to delete the problematic header, or replace it with something more suitable before hits the client for processing.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron, you have saved my project and... my mental health I was struggling with that issue for a long time and finally I have it fixed! Please take this piece of pie as my thanks!

So here is what I did. I am building my HttpClient with HttpClients.custom(). I have tried to add the interceptor with addInterceptorFirst but it didn't work. The content-encoding was processed somewhere before this interceptor. After some time of diving in the docs trying to learn the entire process, I have found that I can provide my own custom HttpProcessor for the HttpClient. As processing of content-encoding is done inside the default HttpProcessor, I wrote my own that deals with this header before anything else. Result: success!

Here is the code I used, for future generations. I removed all unnecessary elements for simplicity.

Creation of the HttpClient:


Creation of the HttpProcessor:


Code of the HttpResponseInterceptor:
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome - thanks for the pie.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And have a cow for sharing that solution
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rob!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic