AnsweredAssumed Answered

Url authentication with ticket

Question asked by lfo on May 14, 2008
Hi,

I developpe a webscript which return a list a documents.

When i run my code all is OK for the  url1 part :-) whitch try to call a webscript

For the url2, whitch try to call a document (the url is render by the url1 webscript), i have the "conn 2 OK" but not the second OK message, i get an error :
java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:5900/alfresco/service/api/node/content/workspace/SpacesStore/40495a69-1c3b-11dd-a188-f170301757eb/Doc1.htm&alf_ticket=TICKET_1f171e2bd6856acdc8836063c3714587aee152ae
   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1241)
   at com.test.Test.main(Test.java:65)

When i try the url2 in my browser, i have a form to connect me and after authentication its ok i can see my document, but i can get it with my code

can anybody tell me why , and where is my mystake?

thanks you very much for your help

Have a nice day

Loïc


My code

AuthenticationUtils.startSession("admin", "admin");
         System.out.println("auth OK");
                  
         String ticket = AuthenticationUtils.getTicket();

         // ******* URL 1 PART ***********
         URL url1 = new URL("http://localhost:5900/alfresco/service/asir/documents_list/myDocumentsListApp?myDirectory=Company%20Home/User%20Homes&myCategory=Consultant&format=text" +
               "&alf_ticket="+ticket);
         
         URLConnection conn1 = url1.openConnection();
         System.out.println("conn 1 OK");
         BufferedReader br1 = new BufferedReader(new InputStreamReader(conn1
               .getInputStream()));
         String line;
         while ((line = br1.readLine()) != null) {            
            System.out.println(line);
         }
         br1.close();
         
         // ******* URL 2 PART ***********
         URL url2 = new URL(
               "http://localhost:5900/alfresco/service/api/node/content/workspace/SpacesStore/40495a69-1c3b-11dd-a188-f170301757eb/Doc1.htm" +
         "&alf_ticket="+ticket);
         
         URLConnection conn2 = url2.openConnection();
         System.out.println("conn 2 OK");
         
         BufferedReader br2 = new BufferedReader(new InputStreamReader(conn2
               .getInputStream()));
         System.out.println("InputStream conn  2 OK");
         while ((line = br2.readLine()) != null) {            
            System.out.println(line);
         }
         br2.close();

Outcomes