cancel
Showing results for 
Search instead for 
Did you mean: 

RESTful API, deploying and starting a process

jmiller
Champ in-the-making
Champ in-the-making
Hello.  We are using the RESTful interface with Activiti 5.9.  We changed org.activiti.rest.api.repository.DeploymentUploadResource to return a DeploymentResponse (thus JSON) instead of an HTML string.

We are attempting the simplest case to deploy a process definition and then start a process instance from that definition.  The documentation and code indicate we can start a process instance by process definition ID or key.  When we deploy a process definition we get back the deployment ID not the process definition ID, and it looks like it's hard to get the process definition ID and key.  What's the easiest way to get the process definition ID and/or key so that we can start the process?

Thank you very much for your thoughts.

Joe Miller
2 REPLIES 2

gumba
Champ in-the-making
Champ in-the-making
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;

public class RestAPI {

/**
  * @param args
  */
public static void main(String[] args) {
  try {
   // TODO Auto-generated method stub
   DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080),
            new UsernamePasswordCredentials("kermit", "kermit"));
                
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local auth cache
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(new HttpHost("localhost", 8080, "http"), basicAuth);

        // Add AuthCache to the execution context
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
        HttpPost postMethod = new HttpPost("http://localhost:8080/activiti-rest/service/process-instance");
     
           postMethod.setEntity(new StringEntity("{\"processDefinitionKey\":\"MailSender\"}", "UTF-8"));
           HttpResponse response = client.execute(postMethod, localcontext);
           System.out.println(IOUtils.toString(response.getEntity().getContent()));
           client.getConnectionManager().shutdown();
        } catch (Exception e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        }
 
       
       
}

}

This code returns the following error:
<html>
<head>
   <title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Internal Server Error</p>
<p>Failed to retrieve the process definition parameters</p>
<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>

what is wrong with it?

jmiller
Champ in-the-making
Champ in-the-making
Just to respond to my original post…

I worked around this by implementing my own service that creates a deployment then returns a ProcessDefinitionResponse containing the process definition ID.
Here are the last few lines of code:


    Deployment deployment = deploymentBuilder.deploy();

    ProcessDefinition processDefinition = ActivitiUtil.getRepositoryService().
        createProcessDefinitionQuery().
        deploymentId(deployment.getId()).
        singleResult();

    return new ProcessDefinitionResponse((ProcessDefinitionEntity) processDefinition);

Joe