Totvs Fluig - Customization - Call in REST service in the beforeSendData event

3

Does anyone know how to make a call to a REST service inside the beforeSendData event, below my code (not functional):

My goal is to execute a call on a REST service from the fluig itself in order to get the detail of a request (process instance).

I tried to use the standard jQuery call but it did not work, this script runs on the server side.

function beforeSendData(customFields, customFacts) {
      log.info("****************teste");      
      customFields[0] = "1";
      customFacts[0] = 10.53;      
      var processInstanceId = getValue("WKNumProces"); 
      var taskUserId = getValue("WKUser");     
      log.info("****************teste");
//Tentei usar esta API mas não funciona
//Tentei usar jQuery mas também não funcionou.
      WCMAPI.Read({
        type: "POST",
        url: WCMAPI.getServerURL() + '/ecm/api/rest/ecm/workflowView/findDetailsMyRequests?processInstanceId=' + processInstanceId + "&taskUserId=" + taskUserId,
        async: false,
        success: function funcao(data) {
            log.info(txt);
            var data = jQuery.parseJSON(txt);        
        },
        error: function (msg){
            log.info("****Não funcionou********");
        }
    });     
}
    
asked by anonymous 11.11.2015 / 17:50

1 answer

1

I've turned your comment in response, so the question is not left unanswered, and can help others. Accept as correct, if applicable. I made the corrections in the variable declarations, you do not need to put var in all, just at the beginning, separating with a comma.

var url = "google.com.br",
get = new org.apache.commons.httpclient.methods.GetMethod(url),
client = new org.apache.commons.httpclient.HttpClient(),
br = new java.io.BufferedReader(newjava.io.InputStreamReader(get.getResponseBodyAsStream())),
response = "",
line = br.readLine();
 while(line != null)
 {
   response = response + line; 
   line = br.readLine()
 } 

log.info(response); 
get.releaseConnection();
    
22.01.2016 / 12:01