Problem with json-rpc in client side

Jeremy Chiang June 25, 2014

Hi all,

I am new to confluence. I am try to use json-rpc api to create a new space on confluence via java prgram.

(The confluence is running on the virtual box on my computer)

here is my code:

import com.thetransactioncompany.jsonrpc2.client.*;

import com.thetransactioncompany.jsonrpc2.*;

import net.minidev.json.*;

import java.net.*;

public class JsonRpcClient {

static {

javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(

new javax.net.ssl.HostnameVerifier(){

public boolean verify(String hostname,

javax.net.ssl.SSLSession sslSession) {

if (hostname.equals("myserver")) {

return true;

}

return false;

}

});

}

public void createSpace(){

URL serverURL = null;

try{

serverURL = new URL ("https://myserver/rpc/json-rpc/confluenceservice-v2");

}catch(MalformedURLException e){

e.printStackTrace();

}

JSONRPC2Session mySession = new JSONRPC2Session(serverURL);

mySession.setConnectionConfigurator(new BasicAuthenticator());

String jsonString = "{\"jsonrpc\" : \"2.0\", \"method\" : \"addSpace\", \"params\" : \n" +

" {\"key\" : \"DS\", \"name\" : \"Document Space\",\"description\" : \"This is a test\" },\"id\":\"12345\"}";

JSONRPC2Request request = null;

try{

request = JSONRPC2Request.parse(jsonString);

}catch(JSONRPC2ParseException e){

e.printStackTrace();

}

JSONRPC2Response response = null;

try {

response = mySession.send(request);

} catch (JSONRPC2SessionException e) {

System.err.println(e.getMessage());

// handle exception...

}

// Print response result / error

if (response.indicatesSuccess())

System.out.println(response.getResult());

else

System.out.println(response.getError().getMessage());

}

public static void main (String[] args){

JsonRpcClient client = new JsonRpcClient();

client.createSpace();

}

}

Then, I will get
Network exception: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
What should I do ?
Thanks alot

3 answers

1 accepted

1 vote
Answer accepted
Sabine Winkler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2014

Hi,

your keystore is not containing a certificate for the SSL handshake. Please review this page for further instructions

https://confluence.atlassian.com/display/JIRAKB/Unable+to+Connect+to+SSL+Services+due+to+PKIX+Path+Building+Failed+sun.security.provider.certpath.SunCertPathBuilderException

HTH, Sabine

0 votes
Sabine Winkler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2014

Hi Jeremy,

this sounds good. If the answer helped you please mark it to close this thread.

Thanks, Sabine

0 votes
Jeremy Chiang June 26, 2014

Hi Sabine,

Appreciate for your response, I figure ou the problem, I also review the following link

https://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services

I waste lots of time because I put the certificate in the wrong keystore !

Sincerely,

Jeremy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events