webthumbnail icon indicating copy to clipboard operation
webthumbnail copied to clipboard

Accessing service programatically

Open jana01 opened this issue 12 years ago • 4 comments

Hello,

I have been trying to integrate your service to our application. I need to get the status of the thumbnail so that I know when it is ready.

I use Java or Javascript.

With Javascript, I am not allowed to make Ajax request due to cross-domain scripting restrictions. I guess you don't support JSONP?

With Java I use the following rather simple code:

    HttpURLConnection connection = null;
    URL u = new URL("http://api.webthumbnail.org?url=dir.bg&action=get-status");
    connection = (HttpURLConnection) u.openConnection();

    connection.connect();

    System.out.println(connection.getResponseMessage());
    System.out.println(connection.getResponseCode());

    InputStream str = connection.getInputStream();

But I am getting "Invalid Http response" exception.

Can you please help on this?

Thank you!

PS Also, your contact form crashed.

jana01 avatar Nov 27 '12 02:11 jana01

Hello,

well thats quite odd:

both urls work: http://api.webthumbnail.org/?url=http://dir.bg http://api.webthumbnail.org/?url=http://dir.bg&action=get-status

The api.webthumbnail.org server is behind reverse proxy but i don't think that this might cause an "Invalid Http Response" problem. Regarding ajax cross domain, you could setup a simple proxy script/servlet that just passes the request further to the api.webthumbnail.org directly from your webserver, the widget that generates a screenshot on the front page works this way.

Btw do you know the time when you got that exception? I could check this out in logs.

Thx for notice about mailing problem :)

bests

W dniu 27.11.2012 03:55, jana01 pisze:

Hello,

I have been trying to integrate your service to our application. I need to get the status of the thumbnail so that I know when it is ready.

I use Java or Javascript.

With Javascript, I am not allowed to make Ajax request due to cross-domain scripting restrictions. I guess you don't support JSONP?

With Java I use the following rather simple code:

| HttpURLConnection connection = null; URL u = new URL("http://api.webthumbnail.org?url=dir.bg&action=get-status"); connection = (HttpURLConnection) u.openConnection();

 connection.connect();

 System.out.println(connection.getResponseMessage());
 System.out.println(connection.getResponseCode());

 InputStream str = connection.getInputStream();

| |

But I am getting "Invalid Http response" exception.

Can you please help on this?

Thank you!

PS Also, your contact form crashed.

— Reply to this email directly or view it on GitHub https://github.com/idea4software/webthumbnail/issues/2.

Lukasz Cepowski Idea4 Software +48 502 670 711 http://www.idea4software.com http://lukasz.cepowski.com

cepa avatar Nov 27 '12 07:11 cepa

Thanks for you answer!

I would have set up proxy servlet if I could connect to the service via Java.

I have just made 2 requests (10:41 AM, GMT+2) with http://api.webthumbnail.org?width=400&height=300&screen=1280&format=png&url=http://www.bbc.co.uk/&action=get-status

Please, let me know if you have any clue on the problem.

jana01 avatar Nov 27 '12 08:11 jana01

Well I used the code you have sent me, plz try this again:

import java.io.*;
import java.net.*;

class App 
{

    public static void main(String[] argv)
    {
        try {
            String str = new String("http://api.webthumbnail.org/?width=400&height=300&screen=1280&format=png&url=http://www.bbc.co.uk/&action=get-status");
            URL url = new URL(str);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();

            System.out.println(conn.getResponseMessage());
            System.out.println(conn.getResponseCode());

            InputStreamReader inputStreamReader = new InputStreamReader(conn.getInputStream());
            BufferedReader bufReader =  new BufferedReader(inputStreamReader);            
            String line = null;
            while ((line = bufReader.readLine()) != null) {
                System.out.println(line);
            }

        } catch (MalformedURLException exc) {
            throw new RuntimeException(exc);
        } catch (IOException exc) {
            throw new RuntimeException(exc);
        }
    }   

}

my otput:

cepa@diabeu:~$ java App OK 200 finished

cepa avatar Nov 27 '12 10:11 cepa

Heh, it works indeed now!

There must have been some stupid error I have made - though I have no idea what it might be.

If I found out what it was, I will let you know.

Thanks alot!

jana01 avatar Nov 27 '12 10:11 jana01