• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange I/O exception with URL passed

 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys,

I have a servlet endpoint, where I've passed the following:

http://localhost/mytestapp/dispatch?image1_url=http%3A//4.bp.blogspot.com/_V7lJdZi_T9A/TAxBjmRjECI/AAAAAAAASco/gFOEujSDGzk/s1600/rihanna+red+hair+4.jpg

As you can see, the url, passed as a parameter is UTF-8 encoded. In the 'dispatch' servlet, I do the following:



or



which both result in the following URL:

http://4.bp.blogspot.com/_V7lJdZi_T9A/TAxBjmRjECI/AAAAAAAASco/gFOEujSDGzk/s1600/rihanna red hair 4.jpg - with pluses removed and spaces instead.

When I pass it to ImageIO.read(URL), I get 'Can't get input stream for the URL; Server returned response code 400', which is strange, since ImageIO uses the very same java.net package.

Would you please assist me on how to work this around and have valid URLs when building a URL?

Thanks a lot in advance!

Martin
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martin,

I think the problem is not connected to utf-8. Depending on the operating system you use plus signs are not valid inside a file name. The pluses are replaced by spaces but there is not file with spaces in the name so the input stream gets no data.

Is there a way to replace the plus signs with for instance underscores?

Best,
Ramon
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a small snippet, which reproduces the error:


And the exception is:


Of course, I can always do the following:

but I don't consider this the proper way to fix this. Also there might be other symbols that cause the same, of which I'm not aware right now...

Thanks
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramon Anger wrote:Hi Martin,

I think the problem is not connected to utf-8. Depending on the operating system you use plus signs are not valid inside a file name. The pluses are replaced by spaces but there is not file with spaces in the name so the input stream gets no data.

Is there a way to replace the plus signs with for instance underscores?

Best,
Ramon


Hi, Ramon,

Well I can't change URLs, since I've not created them Any random image URL could be passed to my app.

Best,
Martin
 
Martin Asenov
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is again - I regularly test my app with random images, but I can't even bring this image for reading. These spaces just freak me out. Here is the link:

http://www.sas.usace.army.mil/lakes/thurmond/images/camping%20at%20clark%202.jpg

This code always fails, no matter what I try:

Please assist me, any help will be greatly appreciated! What I need is to be able to read any image URL passed...

Best regards,
Martin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!