cancel
Showing results for 
Search instead for 
Did you mean: 

Permission WebScript

americanolinhar
Champ on-the-rise
Champ on-the-rise
Good afternoon,

I'm building an external module to Alfresco and I want to communicate with the Alfresco through the WebScripts.

I created a WebScript and it's working. I tested the webscript pasting the URL directly in the browser. Infact it is the copy of the model "start-workflow".

However, through the Java application is occurring the following message:  java.lang.RuntimeException: Failed : HTTP error code : 401

I tried to change the permission to guest and it didnt worked .

Anyone can help me?   The WebScript codes are attachment.


  try {
   
         DefaultHttpClient httpClient = new DefaultHttpClient();
         HttpGet getRequest = new HttpGet(
            "http://localhost:8081/alfresco/service/api/login?u=admin&pw=admin");
         getRequest.addHeader("accept", "application/json");
   
         HttpResponse response = httpClient.execute(getRequest);
   
         if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
         }
   
         BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
   
         String output,saida="";
         
         
      
         while ((output = br.readLine()) != null) {
            
            saida = saida + output;
         }
   
         
         ticket = saida.substring(53, 93);


         
         
      
      httpClient.getConnectionManager().shutdown();
   
        } catch (ClientProtocolException e) {
   
         e.printStackTrace();
   
        } catch (IOException e) {
   
         e.printStackTrace();
        }
       
      
       
        try {
          
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String url,urlScript;
            String encodeUrl = null;
            idCSV = idCSV.substring(0,36);
            String nodeRefId = idCSV;
            System.out.println(nodeRefId);
            String workflowType = "activiti$customComplement";
            String assignTo = "operadorAlfresco";
            String workflowDueDateDay = "10";
            String workflowDueDateMonth = "10";
            String workflowDueDateYear = "2015";
            String description = "teste";
            String workflowPriority = "2";
                  
            urlScript = "http://localhost:8081/alfresco/service/workflow/start-workflow?";
            
            url =  "alfTicket=TICKET_" + ticket;
            url = url + "&workflowType=" + workflowType;
            url = url + "&assignTo=" + assignTo;
            url = url + "&workflowDueDateDay=" + workflowDueDateDay;
            url = url + "&workflowDueDateMonth=" + workflowDueDateMonth;
            url = url + "&workflowDueDateYear=" + workflowDueDateYear;
            url = url + "&description=" + description;
            url = url + "&nodeRefId=" + nodeRefId;
            //url = url + "&guest=true";
               
                        
            url = urlScript + url;
            
                     
            System.out.println(url);

                     
            HttpGet getRequest = new HttpGet(url);
            
            getRequest.addHeader("accept", "application/json");
      
            HttpResponse response = httpClient.execute(getRequest);
      
            
            if (response.getStatusLine().getStatusCode() != 200) {
               throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
            }
      
            BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
      
            String output;
            
            
            System.out.println("Output from Server …. \n");
            while ((output = br.readLine()) != null) {
               
            }
      
            httpClient.getConnectionManager().shutdown();
      
           } catch (ClientProtocolException e) {
      
            e.printStackTrace();
      
           } catch (IOException e) {
      
            e.printStackTrace();
           }
       
       
   
      }
2 REPLIES 2

romschn
Star Collaborator
Star Collaborator
Try following and see if that works for you or not.Instead of alfTicket,use alf_ticket.

Thank you a lot. I've change to "alf_ticket" and now it works.