It's all about the answers!

Ask a question

RTC Rest API authentication issue

Jia Jia Li (8057152192) | asked Apr 09 '12, 10:33 a.m.
Hi, I want to use RTC Rest API to create/modify work item in java program.
The URL I use for auth is:

My JTS server is 3.0.1 with Tomcat and self certificated.

Can anyone help? Thanks!

But I got the exception: peer not authenticated
at org.apache.http.conn.ssl.AbstractVerifier.verify(
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(
at org.apache.http.impl.client.DefaultRequestDirector.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(
at org.apache.http.impl.client.AbstractHttpClient.execute(


The sample code is :

private Cookie authenticate() {

if(cookie!=null && !cookie.isExpired(Calendar.getInstance().getTime())){
return cookie;

DefaultHttpClient httpClient = new DefaultHttpClient();

HttpPost postMethod = null;

try {
postMethod = new HttpPost(authURL);
postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpClient.execute(postMethod);
HttpEntity responseEntity = response.getEntity();

cookie = httpClient.getCookieStore().getCookies().get(0);

} catch (IOException e) {

return cookie;

One answer

permanent link
Jia Jia Li (8057152192) | answered Apr 09 '12, 10:51 a.m.
Download the workshop and run Example3.

static public void setupLazySSLSupport(HttpClient httpClient) {
ClientConnectionManager connManager = httpClient.getConnectionManager();
SchemeRegistry schemeRegistry = connManager.getSchemeRegistry();
/** Create a trust manager that does not validate certificate chains */
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted([] certs, String authType) {
/** Ignore Method Call */

public void checkServerTrusted([] certs, String authType) {
/** Ignore Method Call */

public[] getAcceptedIssuers() {
return null;
} };

SSLContext sc = null;
try {
sc = SSLContext.getInstance("SSL"); //$NON-NLS-1$
sc.init(null, trustAllCerts, new;
} catch (NoSuchAlgorithmException e) {
/* Fail Silently */
} catch (KeyManagementException e) {
/* Fail Silently */

SSLSocketFactory sf = new SSLSocketFactory(sc);
Scheme https = new Scheme("https", sf, 443);


Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.