0

How should I call a large URL in Java? I'm integrating scene7 image server with java application. Here I call a URL of around 10000 characters which should return me an Image. What ways can I do this?

The way I wrote is -

URL oURL= new URL("<*LONG LONG URL - approx. 10k characters*>");
HttpURLConnection connection = (HttpURLConnection) oURL.openConnection();
InputStream stream = connection.getInputStream();
int len;
byte[] buf = new byte[1024];
BufferedImage bi = ImageIO.read(stream);
ImageIO.write(bi,"png",response.getOutputStream());  

while ((len = stream.read(buf)) > 0) {
    outs.write(buf, 0, len);
}
halfer
  • 19,824
  • 17
  • 99
  • 186
HarsH
  • 760
  • 3
  • 12
  • 27
  • Why do you have so many characters in url? Did you try? What did happen? – Keerthivasan Feb 25 '14 at 12:50
  • 4
    I think you may have a significant problem here. http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers – Brian Agnew Feb 25 '14 at 12:51
  • @Octopus yes, I tried and it gave me 400 error, and I think this is due to GET request as large URL with big big query string is getting added. You have any suggestion? – HarsH Feb 25 '14 at 13:02
  • @BrianAgnew Thanks, but I'm more concerned of URL call through Java and not through browser... Can you please update is there any specific thing I should look into, on the URL you provided? – HarsH Feb 25 '14 at 13:03
  • Can we assume you have an existing server that can handle this large URL? – Rudi Angela Feb 25 '14 at 13:10
  • Does the URL need to be that long? What if the data is expressed in a dense fashion, such as base64 (or some other baseX, where X > 64)? – Duncan Jones Feb 25 '14 at 13:11
  • Yes.. URL need to be that long, and base-fashions like base64 is not supported by the image server. – HarsH Feb 25 '14 at 13:25
  • @RudiAngela.. tried setting **maxHttpHeaderSize="1048576"** in tomcat's server.xml, but still facing the same prob. – HarsH Feb 25 '14 at 13:26

3 Answers3

2

You won't get URLs that long to work reliably. The longest you can rely on working is around 2000 characters. Beyond that, you are liable to run into browser or server-side limits. (Or even limits in intermediate proxy servers)

You are going to need to "think outside the box". For example:

  • pass some the information that is currently encoded in your URL in the form of POST data,
  • pass some the information in the form of custom request headers (ewww!!), or
  • come up with a clever way to encode (or compress) the informational part of the URL.

All of these are likely to require changes to the server side.

Reference:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

While the HTTP 1.1 specification does not place a limit on the length (size) of a URL, the server that you are working with might. You should check the documentation for the server you are connecting to (in this case, Adobe's Scene7.)

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
0

Just getting an image from the URL is as easy as:

URL url = new URL("<extremely long URL>");
Image image = ImageIO.read(url);

So I'm wondering if you weren't asking for something else.

Rudi Angela
  • 1,463
  • 1
  • 12
  • 20