cancel
Showing results for 
Search instead for 
Did you mean: 

How to use WorkflowService in Web Application?

raarm
Champ in-the-making
Champ in-the-making
Hi everybody,

I need to use the WorkflowService in Applets……How to call this service in SOAP or WebFactory?

In my application I show a workflow advanced List……. I need to start workflow with the instance, or better, the context that is already running!! I dont wanna to start a new ApplicationContext!! what can I do?


Thanks
3 REPLIES 3

pmonks
Star Contributor
Star Contributor
For most cases where remote calls into Alfresco are required, I'd recommend using a Web Script (http://wiki.alfresco.com/wiki/Web_Scripts).  Web Scripts effectively allow you to define your own remotely invocable APIs that exactly satisfy your use cases.

Because Web Scripts run in-process with the Alfresco repository, you have full access to all of Alfresco's functionality, via either the Javascript API (http://wiki.alfresco.com/wiki/JavaScript_API) for Javascript-backed Web Scripts, or the Foundation Services APIs (http://dev.alfresco.com/resource/docs/java/repository/index.html) for Java-backed Web Scripts.   This includes full access to the WorkflowService (which allows you to enumerate the available workflows and initiate new workflow instances, amongst other things).

One minor point is that in the case of applets you may (depending on your system architecture) need to proxy the HTTP calls your applets are making to Web Scripts, due to the applet security sandbox.  Note that this has nothing to do with Alfresco per se - it's simply the way applets work.

raarm
Champ in-the-making
Champ in-the-making
I don't know how to use web script in my applet . I read the article and now I know that I have to create a javascript file and after this call him but I don´t no how to associate this file with my application.

for example:

…….
try
    {  
       
       String serverhost = "http://10.1.9.46:8080/alfresco/api";
      WebServiceFactory.setEndpointAddress(serverhost);
      AuthenticationUtils.startSession(user, pass);
       try
       {
          RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
           String qString = "@bpm\\:workflowDefinitionId:\"jbpm$8\"";
              
              
          
           ResultSetRow[] rows = listaProcessos(repositoryService,qString);
               if (rows == null)
               {
                   System.out.println("No query results found.");
               }
               else
               {
                  for (int x = 0; x < rows.length; x++)
                   {
                     ResultSetRow row = rows[x];
                      
                       NamedValue[] columns = row.getColumns();
                      
                      
                                             for (int y = 0; y < columns.length; y++)
                       {   
                          
                          
                          if(row.getColumns(y).getName().endsWith("workflowInstanceId"))
                          {
                             
                             
                             
                              System.out.println("Process("+x+"): "
                                       + "WorkflowInstanceId = "
                                       + row.getColumns(y).getValue());
                              
                          }
                          if(row.getColumns(y).getName().endsWith("name"))
                          {
                             
                             
                                                           System.out.println("Process("+x+"): "
                                       + "ProcessName = "
                                       + row.getColumns(y).getValue());
                          }
                          
                          if(row.getColumns(y).getName().endsWith("creator"))
                          {
                             
                             
                                                          System.out.println("Process("+x+"): "
                                       + "ProcessCreator = "
                                       + row.getColumns(y).getValue());
                          }
                          if(row.getColumns(y).getName().endsWith("created"))
                          {
                             
                             String[] time = row.getColumns(y).getValue().split("T");
                                                          System.out.println("Process("+x+"): "
                                       + "CreationDate = "
                                       + time[0]);
                          }
                          
                          
                       }
                       String ResultId = rows[x].getNode().getId();
                          
                      
                       Reference reference = new Reference(STORE, ResultId, null);
                      
                                              QueryResult childQueryResult = repositoryService.queryChildren(reference);
                      
                                              ResultSet childResultSet = childQueryResult.getResultSet();
                       ResultSetRow[] childRows = childResultSet.getRows();
                       if (childRows == null)
                       {
                           System.out.println("No child.");
                       }
                       else
                       {
                           System.out.println("Results from process ("+x+")");
                          
                           for(int t=0;t<childRows.length;t++)
                           {
                                                            NamedValue[] colum = childRows[t].getColumns();
                              for (int y = 0; y < colum.length; y++)
                               {
                                   System.out.println("Process content (" + x + "): "
                                           + childRows[t].getColumns(y).getName() + " = "
                                           + childRows[t].getColumns(y).getValue());
                               }
                           }
                         
                       }
                       System.out.println("\n");
                  
                   }
                  AuthenticationUtils.endSession();
               }
              
              
       }
       catch(Exception e)
       {
          e.printStackTrace();
       }
        
    }
    catch(Exception e)
    {
       System.out.println("Nao Logou!!");
    }
  
}
…….

How to use javascript file in my code? how to call ?

Thanks :roll:

raarm
Champ in-the-making
Champ in-the-making
Hi pmonks,

Can you help me? I made Web Script (tree files xml, js and flt) yet!! But in my applet I dont access servlets by POST or GET. It needs authentication before to access the servlet!!!

I'm trying to access my script as this code:

String hostname = null;
      try {
         hostname = "10.1.9.46";
         String data = URLEncoder.encode("scriptPath", "UTF-8") + "=" + URLEncoder.encode("/Company%20Home/Teste/workflow.js", "UTF-8");
         int port = 8080;
         InetAddress addr = InetAddress.getByName(hostname);
         Socket socket = new Socket(addr, port);
                                               
         String path = "/alfresco/command/script/execute";
         BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
         wr.write("POST "+path+" HTTP/1.0\r\n");
         wr.write("Content-Length: "+data.length()+"\r\n");
         wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
         wr.write("\r\n");
         

//          Send data
         wr.write(data);
         wr.flush();

//          Get response
         BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
         String line;
         while ((line = rd.readLine()) != null) {
//          Process line…
            System.out.println(rd.readLine());
         }
         wr.close();
         rd.close();
         wf.fechaSessao();
      }catch ( UnknownHostException eh )
      {
      System.err.println( " host inexistente: "+hostname) ;
      System.exit( 1 ) ;
      }

This is the log error:

10:18:25,847 User:guest ERROR [[localhost].[/alfresco].[commandServlet]] Servlet.service() for servlet commandServlet threw exception
org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Acesso Negado. Você nao tem permissão para executar esta operação.
        at org.alfresco.web.app.servlet.CommandServlet.service(CommandServlet.java:194)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
        at java.lang.Thread.run(Unknown Source)
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Acesso Negado. Você nao tem permissão para executar esta operação.
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:241)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy40.resolveNamePath(Unknown Source)
        at org.alfresco.web.app.servlet.BaseServlet.resolveWebDAVPath(BaseServlet.java:297)
        at org.alfresco.web.app.servlet.BaseServlet.resolveWebDAVPath(BaseServlet.java:263)
        at org.alfresco.web.app.servlet.BaseServlet.resolveNamePath(BaseServlet.java:343)
        at org.alfresco.web.app.servlet.command.ScriptCommandProcessor.validateArguments(ScriptCommandProcessor.java:80)
        at org.alfresco.web.app.servlet.CommandServlet.service(CommandServlet.java:139)
        … 15 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access Denied
        at org.alfresco.repo.security.permissions.impl.acegi.ACLEntryAfterInvocationProvider.decide(ACLEntryAfterInvocationProvider.java:299)
        at org.alfresco.repo.security.permissions.impl.acegi.ACLEntryAfterInvocationProvider.decide(ACLEntryAfterInvocationProvider.java:316)
        at org.alfresco.repo.security.permissions.impl.acegi.ACLEntryAfterInvocationProvider.decide(ACLEntryAfterInvocationProvider.java:200)
        at net.sf.acegisecurity.afterinvocation.AfterInvocationProviderManager.decide(AfterInvocationProviderManager.java:107)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.afterInvocation(AbstractSecurityInterceptor.java:329)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:82)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)



What can I do?

Thanks!!