cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use REST web application as standalone server?

goto_tony
Champ in-the-making
Champ in-the-making
Dear all:
      Hi. The activiti REST web application is appreciated as a standalone process middleware server so I don't need to couple too many codes for Activiti engine. And since I am using Microsoft .net to develop application so that I can't use activiti API. By adapting RESTful api, it seems feasible to initiate work process, query tasks by HTTP post/get method without any coding.
      But my first obstacle is REST authentication. Even I read the user guide several times and googled information, I didn't get the example for REST authentication for reference. How can I prepare authentication before post/get the REST url?
     It would be grateful that you can give me some example with Java and .net language for the REST application.
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
The Activiti REST API uses basic authentication (http://en.wikipedia.org/wiki/Basic_access_authentication),
so it's just a matter of setting the 'Authorization' header and encoding the username + password with base64.

goto_tony
Champ in-the-making
Champ in-the-making
hi, jbarrez, thanks for your reply.
I've used Apache HttpClient 4.x to prepare basic authentication as below, but it doesn't work. Please kindly instruct me the reason and next step.
public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(
              AuthScope.ANY,
                    new UsernamePasswordCredentials("kermit", "kermit"));

            HttpGet httpget = new HttpGet("http://localhost:8080/activiti-rest/service/process-engine");

            System.out.println("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();

            System.out.println("—————————————-");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
            }
            EntityUtils.consume(entity);
        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }

The result is always 403 code.
executing requestGET http://localhost:8080/activiti-rest/service/process-engine HTTP/1.1
—————————————-
HTTP/1.1 403 Forbidden
Response content length: 407

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Reason: authentication fails
Next step: debug the http requestvand check if the credentials are acutally passed on

goto_tony
Champ in-the-making
Champ in-the-making
hi, I am sure the account/password is fine since I can use firefox REST Client with such credencial. What I got is 403 response code instead of 200 response code. It seems such HttpClient program doesn't work yet.

I've compared Http Client and Firefox according to the tomcat log console. It didn't tell me some exception happened.

goto_tony
Champ in-the-making
Champ in-the-making
Now I've learnt the reason, i.e. Activiti Basic Authentication needs "preemptive mode" for Basic Authentication.

Now I use the Httpclient as:

        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
             HttpGet httpget = new HttpGet("http://localhost:8080/activiti-rest/service/tasks?assignee=kermit");
           
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials("kermit", "kermit");
           
            httpget.addHeader(new BasicScheme().authenticate(creds, httpget));
            System.out.println("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
         …..  

And the response.getStatusLine() is 200,ok.

jbarrez
Star Contributor
Star Contributor
ok, thanks for following up with the solution.