AnsweredAssumed Answered

CIFS - start simple workflow

Question asked by borys on Dec 14, 2007
Hi all,

I'm writing custom desktop action that starts a simple workflow.
Here's my Java code:



public class WorkflowAction extends DesktopAction {

   private Log log = LogFactory.getLog(WorkflowAction.class);

   public WorkflowAction() {
      super(AttrAnyFilesFolders, PreConfirmAction);
   }

   @Override
   public DesktopResponse runAction(DesktopParams arg0)
         throws DesktopActionException {
      
      String ticket = arg0.getTicket();

      for (int i = 0; i <= arg0.numberOfTargetNodes() - 1; i++) {
         DesktopTarget target = arg0.getTarget(i);
         approve(target.getNode(), ticket);
      }

      return new DesktopResponse(StsSuccess,
            "Approve action at " + new Date());
   }

   private void approve(NodeRef ref, String ticket) {
      String host = getWebappURL();
      String command = "command/workflow/approve/workspace/SpacesStore/";
      String URL = host + command + ref.getId() + "?ticket=" + ticket;
      
      try {
         log.info("HTTP " + URL);
         
         HttpClient client = new HttpClient();
         HttpMethod get = new GetMethod(URL);
         client.executeMethod(get);
         get.releaseConnection();
      } catch (Exception e) {
         log.error(e);
      }
   }
}

Whem I'm logged in (through web client) it works but if I'm not it throws this exception:


13:19:39,718 DEBUG [org.alfresco.web.app.servlet.CommandServlet] Processing URL: /alfresco/command/workflow/approve/workspace/SpacesStore/f405768f-aa26-11dc-a39c-2b6d627d7ce9?ticket=TICKET_166ace453e337886079d92dafbb586e9499e99f7
13:19:39,750 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco].[commandServlet]] Servlet.service() for servlet commandServlet threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
   at org.apache.catalina.connector.Request.doGetSession(Request.java:2221)
   at org.apache.catalina.connector.Request.getSession(Request.java:2031)
   at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:832)
   at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:843)
   at org.alfresco.web.app.servlet.BaseServlet.redirectToLoginPage(BaseServlet.java:187)
   at org.alfresco.web.app.servlet.BaseServlet.servletAuthenticate(BaseServlet.java:152)
   at org.alfresco.web.app.servlet.BaseServlet.servletAuthenticate(BaseServlet.java:117)
   at org.alfresco.web.app.servlet.CommandServlet.service(CommandServlet.java:62)
   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(Thread.java:619)


But after I've received this exception it works. I mean - i try start workflow -> receive exception -> try again -> it works ;)
Any ideas ?

Outcomes