Am using oauth in java and getting error


#1
org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
	at org.scribe.model.Request.send(Request.java:66)
	at org.scribe.model.OAuthRequest.send(OAuthRequest.java:12)
	at com.en.pen.gc.oauthservice.Twitter.twitterTweetsWrite(Twitter.java:67)
	at com.en.pen.gc.oauthservice.Twitter.main(Twitter.java:53)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
	at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
	at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
	at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
	at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
	at org.scribe.model.Request.addBody(Request.java:125)
	at org.scribe.model.Request.doSend(Request.java:104)
	at org.scribe.model.Request.send(Request.java:62)
	... 3 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:294)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:200)
	at sun.security.validator.Validator.validate(Validator.java:218)
	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
	at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1014)
	... 17 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:289)
	... 23 more

#2

Are you able to share any code which demonstrates this issue?

Which Java library are you using?


#3

Am using oauth-signature-1.7-ea05.jar
sample code:

Token shortLiveTkn = new Token("xxxxx","yyyy");
String msg="hello";
OAuthService Oauthsrvc=ServiceBuilder().provider(TwitterApi.Authenticate.SSL.class).apiKey("zzzzzz").apiSecret("aaaaaaa").build();
String tweet = URLEncoder.encode(msg, "UTF-8");
String urlTweet = "https://api.twitter.com/1.1/statuses/update.json?status=" + tweet;           
OAuthRequest request2 = new OAuthRequest(Verb.POST, urlTweet);
Oauthsrvc.signRequest(shortLiveTkn, request2);           
Response response2 = request2.send();

#4

Reminder not to post your real tokens on this forum to prevent others from using them - you should always keep them secret.

I’m not familiar with that library, but I will take a look. Maybe someone else who has used the Scribe library can help here.

Have you looked at Twitter4J or any other Java libraries as alternatives?


#5

Thanks FYI i didn’t look at Twitte4j or any other library.We are using oauth-signature library only


#6

I have been having same problem.
Did you find the solution? Need Help please


#7

Recently we have encountered a similar issue but not related to SSLHandshakeException.

The error thrown in log is :

org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.

Unfortunately we don’t have the full stack trace from log files.

We are using scribe 1.3.3 library in java and connecting twitter api using Java Timer Task to pull data for multiple twitter accounts.

Is this related to the number of concurrent connection? Is there any limitation at twitter end to connect concurrently for a given oauth token?


#8

Yes, for the streaming API you can only have a couple of connections.


#9

Thank you for your reply Andy,

We are using api.twitter.com/1.1
Our app has several twitter accounts registered and authorized.
Timer task periodically takes the list of twitter accounts and update the account details as well twitter home, twittes and direct messages.
One Timer is running to update all the accounts sequentially.

We observed the below recently:
Recently total number of registered accounts grows more than 70.
With this the system hangs very often and throws error as
org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
Unfortunately our log files captures only the above exception and not the full stack trace.

What could be the issue in the above scenario?


#10

@andypiper Any Help or advise is greatly appreciated Please.