05-18-2012 01:46 PM
from json import JSONEncoder
from 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}')
orfrom restful_lib import Connection
c = Connection('http://localhost:8080/activiti-rest/service')
c.request('login', method='POST', body=token, headers={'content-type': 'application/json;charset=UTF-8'})
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 can
get 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', 'c
ontent-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"'}}
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()));
}
}
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
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
Status page
Forbidden
Authentication is required
You can get technical details here.
Please continue your visit at our home page.
05-22-2012 06:46 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.