• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • 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.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Linux MS IE
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome - thanks for the pie.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And have a cow for sharing that solution
 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!