Scheduled job Call Web Script

cancel
Showing results for 
Search instead for 
Did you mean: 
faispis
Member II

Scheduled job Call Web Script

Hi. 

I have some questions. I have a scheduled job on my schedule job I need to call an API Webscript that I have. Currently,  am stuck on call API Webscript. Can someone help me to explain the best way to call API Webscript. Below is the code that i stuck.

/**
 * The Class CustomJobProcessor.<br/>
 */
public class CustomJobProcessor implements org.quartz.StatefulJob{
 
 /** The Constant LOG. */
 private static final Log LOG = LogFactory.getLog(CustomJobProcessor.class);
    
 /** The global properties. */
 private Properties globalProperties;
 
 /** The service registry. */
 private ServiceRegistry serviceRegistry;

 @Override
 public void execute(final JobExecutionContext jobCtx) throws JobExecutionException {
    System.out.println("CustomJobProcessor Started..");
    try{
      //Run as system user since this job is user independent hence
       // permission is required on repo
     AuthenticationUtil.setRunAsUserSystem();
     System.out.println("AuthenticationUtil");
     // TODO:: Put job processing logic here..
     // Get the job space where all jobs are stored 
                  // using  serviceRegistry.getFileFolderService()
                  // Read the jobs in a list as given below:
                  // List<FileInfo> fileInfoList =    fileFolderService.listFiles(jobSpaceNode);
    // Read the uniuqe id from the job property and process
    
        AuthenticationService authenticationService = this.serviceRegistry.getAuthenticationService();

        String ticket = authenticationService.getCurrentTicket();

        HttpClient client = new HttpClient();

        //String uid = recorNoNodeRef.getId();
        //String apiurl = "http://172.16.20.210:8080/alfresco/s/api/managePermissionQueryBy?nodeRef=workspace://SpacesStore/98a93306-3888-4cb2-87fa-2fafa14462d1" + "?alf_ticket=" + ticket;
        String apiurl = "http://172.16.20.210:8080/alfresco/s/api/managePermissionQueryBy?nodeRef=workspace://SpacesStore/98a93306-3888-4cb2-87fa-2fafa14462d1";
        System.out.println("Get url :::" + apiurl);
        String resultString = "";
        GetMethod getComment = new GetMethod(apiurl);
        try {
                int status = client.executeMethod(getComment);
                if (status != 200) {
                        System.out.println("Method failed: " + getComment.getStatusLine());
                }
                resultString = getComment.getResponseBodyAsString();
                 System.out.println("==== resultString ====");
                    System.out.println(resultString);
                    System.out.println("==== resultString ====");
        } catch (Exception e) {
                System.out.println("Line 1643::" + e.getMessage());
                //return "{\"error\":\"" + e.getMessage() + "\"}";
                System.out.println("error :::" + e.getMessage());
        } finally {
                getComment.releaseConnection();
        }
    
   } catch (RuntimeException excp){
      System.out.println("Exception occured while processing job" + excp);
   }
    
   System.out.println("CustomJobProcessor End!");

 }// execute end

 /**
  * Sets the global properties.
  *
  * @param globalProperties the global properties
  */
 public void setGlobalProperties(final Properties globalProperties) {
  this.globalProperties = globalProperties;
 }
 
 /**
  * Sets the service registry.
  *
  * @param serviceRegistry the service registry
  */
 public void setServiceRegistry(final ServiceRegistry serviceRegistry) {
  this.serviceRegistry = serviceRegistry;
 }
}

 

 

By error as below

Method failed: HTTP/1.1 401 Unauthorized
==== resultString ====
{
"status" :
{
"code" : 401,
"name" : "Unauthorized",
"description" : "The request requires HTTP authentication."
},

"message" : "00270000 Authentication failed for Web Script org\/alfresco\/repository\/managePermission\/managepermissionby.get",
"exception" : "",

"callstack" :
[

],

"server" : "Enterprise v5.2.3 (r852994b1-b12) schema 10,065",
"time" : "Jan 27, 2022 11:22:05 AM"
}


==== resultString ====

1 Reply
angelborroy
Alfresco Employee

Re: Scheduled job Call Web Script

Since you are in the Repository side, why to invoke a WebScript but to the code executed by that WebScript? Is there any other integration available by using Java API?

Hyland Developer Evangelist