cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API - unable to do anything except login

tshirtman
Champ in-the-making
Champ in-the-making
Hi, i'm trying to use the rest api from python, with http://tcchou.tumblr.com/post/3164541478/activiti-process-is-controlled-by-pyrestclient (does'nt work currently) as a starting point i tried with various rest modules, i can get a successful login with methods like:

from json import JSONEncoderfrom restclient.transport import HTTPLib2Transport  token = JSONEncoder().encode({'userId': 'kermit','password': 'kermit'})httpclient.request('http://localhost:8080/activiti-rest/service/login', body=token, method='POST')‍‍‍‍‍‍
i get

(<HTTPResponse status 200 for http://localhost:8080/activiti-rest/service/login>, '{"success":true}')‍‍
or

from restful_lib import Connectionc = Connection('http://localhost:8080/activiti-rest/service')c.request('login', method='POST', body=token, headers={'content-type': 'application/json;charset=UTF-8'})‍‍‍

i get :
u'body': u'{"success":true}', u'headers': {'status': '200', 'transfer-encoding': 'chunked', 'accept-ranges': 'bytes', 'vary': 'Accept-Charset, Accept-Encoding, Accept-Language, Accept', 'server': 'Restlet-Framework/2.0.8', 'date': 'Fri, 18 May 2012 17:28:56 GMT', 'content-type': 'application/json;charset=UTF-8'}}‍‍
but if i do :
c.request('process-engine', method='GET', body=token, headers={'content-type': 'application/json;charset=UTF-8'})‍‍
i get :
{u'body': u'<html>\n<head>\n   <title>Status page</title>\n</head>\n<body style="font-family: sans-serif;">\n<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Forbidden</p>\n<p>Authentication is required</p>\n<p>You canget technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4">here</a>.<br>\nPlease continue your visit at our <a href="/">home page</a>.\n</p>\n</body>\n</html>\n', u'headers': {'status': '403', 'content-length': '407', 'accept-ranges': 'bytes', 'server': 'Restlet-Framework/2.0.8', 'date': 'Fri, 18 May 2012 17:32:08 GMT', 'content-type': 'text/html;charset=UTF-8', 'www-authenticate': 'Basic realm="Activiti Realm"'}}‍‍‍


and similar results with other methods:

now i saw most libs have a way to give username/password to use for automatic authentication, but the fact is the server require «userId» instead of «username», and i think that's why it doesn't work.

Just to be sure, i tried a java version from here (not very good at java but i did it) :
http://www.mastertheboss.com/component/content/article/82-activiti/311-activiti-faqs.html

and got similar (bad) results :

import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.auth.AuthScope;import org.apache.http.entity.StringEntity;import org.apache.commons.io.IOUtils;import org.apache.http.HttpResponse;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import java.io.IOException;class TestApp {public static void main(String[] args) throws IOException {DefaultHttpClient dhc = new DefaultHttpClient();dhc.getCredentialsProvider().setCredentials(new AuthScope( AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),new UsernamePasswordCredentials("kermit", "kermit"));HttpPost hp = new HttpPost("http://localhost:8080/activiti-rest/service/process-instance");hp.setEntity(new StringEntity("{\"processDefinitionId\":\"helloworld:1\"}", "UTF-8"));HttpResponse processResponse = dhc.execute(hp);System.out.println(IOUtils.toString(processResponse.getEntity().getContent()));}}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

compilation :
javac -cp lib/apache-mime4j-0.6.jar:lib/commons-codec-1.3.jar:lib/commons-logging-1.1.1.jar:lib/httpclient-4.0.3.jar:lib/httpcore-4.0.1.jar:lib/httpmime-4.0.3.jar:lib/org.apache.servicemix.bundles.commons-io-1.3.2_1.jar test.java‍

running :
 java -cp .:lib/apache-mime4j-0.6.jar:lib/commons-codec-1.3.jar:lib/commons-logging-1.1.1.jar:lib/httpclient-4.0.3.jar:lib/httpcore-4.0.1.jar:lib/httpmime-4.0.3.jar:lib/org.apache.servicemix.bundles.commons-io-1.3.2_1.jar TestApp‍

result :
Status pageForbiddenAuthentication is requiredYou can get technical details here.Please continue your visit at our home page.‍‍‍‍‍‍‍‍‍


now, i'm wondering, is anybody using the Rest API successfully?
1 REPLY 1

tshirtman
Champ in-the-making
Champ in-the-making
Ok, i understood /login was only to use as a check of credentials, and to pass the auth as basic auth header, the best lib i found for all that are restkit and requests (the last one mostly for easyness for deployments uploading).
https://github.com/benoitc/restkit/
http://docs.python-requests.org/en/latest/user/quickstart/

Hope this will help somebody.