0

I create a function that downloads a image to my local web server. When I run this function like a Java Application, it works fine. But when I try to run this method using the Web Service made by AXIS2 ( http://localhost:8080/axis2/services/adoroCinemaService2/downloadPhoto ), the AXIS2 returns Internal server error.

It happens probabily, because I use a "root path" in my code. So, what I need to do to solve this problem? Where is the root of my service? How can I setup this path?

    public void downloadPhoto() throws IOException{

    URL url = new URL("http://vamosla.mobi/img/bonde.png");
    String target = "vamosla.jpg";  

    HttpURLConnection c = (HttpURLConnection)url.openConnection();
    c.setRequestMethod("GET");
    c.setDoOutput(true);
    c.connect();

    FileOutputStream f = new FileOutputStream(new File(target));

     InputStream in = c.getInputStream();
        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ( (len1 = in.read(buffer)) > 0 ) {
            f.write(buffer,0, len1);
        }

        f.close();
}
finnw
  • 47,861
  • 24
  • 143
  • 221
cleliodpaula
  • 819
  • 2
  • 11
  • 27

1 Answers1

0

Hm, there are certainly some tricks available to work out where the code currently executes and setup relative paths from there, but i don't think that will work reliably for you.

Therefore, i suggest you configure something like an 'asset.path' either via system properties or via some configuration file you load from your classpath.

mkro
  • 1,902
  • 14
  • 15