cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute a WebScript from a Java WebService ?

rafpgn
Champ in-the-making
Champ in-the-making
Hi,
I need to call a webscript form a Java WebService .

I have just solved it using the URLConnection Java class ,
but i don't want to parse the html respose  for getting the return values .

This is the code that i'm testing with the Javascript Debubber web script
because it require authentication :

package org.alfresco.sample.webservice;

import org.alfresco.webservice.repository.*;
import org.alfresco.webservice.types.*;
import org.alfresco.webservice.util.*;
import java.io.*;
import java.net.*;
import org.alfresco.webservice.util.*;

public class Call2
{
    public static void main(String[] args)
        throws Exception
    {
       AuthenticationUtils.startSession("admin","admin");
       String ticket=AuthenticationUtils.getTicket();
   
        try
        {  
           try
           {
              URL url= new URL("http://localhost:8080/alfresco/service/api/javascript/debugger?alf_ticket='+ticket);
              
                URLConnection uc = url.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
                String inputLine;

                while ((inputLine = in.readLine()) != null)
                    System.out.println(inputLine);
                in.close();
           }catch(IOException e)
           {
              System.out.println("Error"+e);
           }           

        }
        finally
        {
            AuthenticationUtils.endSession();
        }
    }      
}

and this is the html reponse :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Alfresco Javascript Debugger</title>
    <link rel="stylesheet" href="/alfresco/css/main.css" TYPE="text/css">
  </head>
  <body>
    <form action="/alfresco/service/api/javascript/debugger" method="post">
        <input type="hidden" name="visible" value="true">
        <table>
          <tr>
            <td><img src="/alfresco/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
            <td><nobr><span class="mainTitle">Alfresco Javascript Debugger</span></nobr></td>
          </tr>
          <tr><td><td>Alfresco Community Network v2.1.0 (482)
          <tr><td><td>Currently disabled.
          <input type="submit" name="submit" value="Enable">
        </table>
    </form>
  </body>
</html>


The question is:  if there exists another ways to do the same thing ?
Thanks in advance.
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
Hi

What's wrong with your current implementation? If you're having trouble parsing the response, then you could create an XML-output version of the web script you want to call, or even Json, plain text, etc.

Thanks,
Mike

rafpgn
Champ in-the-making
Champ in-the-making
Thanks for the response.

That's nothing wrong with my code, the question is if there is another way
of doing the same thing , things like executeAction()  ?

mikeh
Star Contributor
Star Contributor
That depends on whether you'd prefer to write your own repository action or web script.

There's no "right or wrong" way as such. If there's an existing web script that does what you need, then by all means call that, otherwise if an existing repository action does what you need then executeAction() would be better suited. Also the Web Script API doesn't cover 100% of the Alfresco repository, so you may find you need to write your own action, depending on what you're trying to achieve.



Thanks,
Mike

rafpgn
Champ in-the-making
Champ in-the-making
ok , thank you.
I need to list all groups in the system, but i haven't well understood what is a Reference , a Predicate and a Store .