Java -Twitter API Access issue on websphere


#1

Im trying to impliment twitter login in Java web application. Following is the code im using. Also, im using twitter4j 4.02 Library.

import java.util.logging.Logger;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
//import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;

public class TwitterApplication {
private final Logger logger = Logger.getLogger(TwitterApplication.class.getName());

public static void main(String[] args) {
new TwitterApplication().publish();
}

private void publish(){
String message=“Twitter application using Java http://www.java-tutorial.ch/architecture/twitter-with-java-tutorial”;
try {
//Twitter twitter = new TwitterFactory().getInstance();
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(“My app ConsumerKey”);
builder.setOAuthConsumerSecret(“My app ConsumerSecret”).setHttpConnectionTimeout(500000);

   Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();

   try {
       RequestToken requestToken = twitter.getOAuthRequestToken();
       AccessToken accessToken = null;
       while (null == accessToken) {
           logger.fine("Open the following URL and grant access to your account:");
           logger.fine(requestToken.getAuthorizationURL());
           try {
                   accessToken = twitter.getOAuthAccessToken(requestToken);
           } catch (TwitterException te) {
               if (401 == te.getStatusCode()) {
                   logger.severe("Unable to get the access token.");
               } else {
                   te.printStackTrace();
               }
           }
       }
       logger.info("Got access token.");
       logger.info("Access token: " + accessToken.getToken());
       logger.info("Access token secret: " + accessToken.getTokenSecret());
   } catch (IllegalStateException ie) {
       // access token is already available, or consumer key/secret is not set.
       if (!twitter.getAuthorization().isEnabled()) {
           logger.severe("OAuth consumer key/secret is not set.");
           return;
       }
   }
   Status status = twitter.updateStatus(message);
   logger.info("Successfully updated the status to [" + status.getText() + "].");

} catch (TwitterException te) {
te.printStackTrace();
logger.severe("Failed to get timeline: " + te.getMessage());
}
}
}

This code Works on another SERVER which has full access of internet without any proxy issues. With tomcat server.

But now when i hosted the same code on websphere… It gives me following Error

com.ibm.jsse2.util.g: PKIX path building failed: java.security.cert.CertPathBuilderException: PKIXCertPathBuilderImpl could not build a valid CertPath.; internal cause is:
java.security.cert.CertPathValidatorException: The certificate issued by CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU=“© 2006 VeriSign, Inc. - For authorized use only”, OU=VeriSign Trust Network, O=“VeriSign, Inc.”, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=3cc69290 or
http://www.google.co.jp/search?q=161493db
TwitterException{exceptionCode=[3cc69290-161493db 3cc69290-161493b1 3cc69290-161493b1 3cc69290-161493b1 3cc69290-161493b1 3cc69290-161493b1], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.2}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:178)
at twitter4j.HttpClientBase.request(HttpClientBase.java:53)
at twitter4j.HttpClientBase.post(HttpClientBase.java:82)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:107)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:92)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:263)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:258)
at com.ibm._jsp._test_5F_twitterapi._jspService(_test_5F_twitterapi.java:121)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:790)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:121)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:234)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:859)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
Caused by: javax.net.ssl.SSLHandshakeException: com.ibm.jsse2.util.g: PKIX path building failed: java.security.cert.CertPathBuilderException: PKIXCertPathBuilderImpl could not build a valid CertPath.; internal cause is:
java.security.cert.CertPathValidatorException: The certificate issued by CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU=“© 2006 VeriSign, Inc. - For authorized use only”, OU=VeriSign Trust Network, O=“VeriSign, Inc.”, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
at com.ibm.jsse2.n.a(n.java:42)
at com.ibm.jsse2.sc.a(sc.java:277)
at com.ibm.jsse2.gb.a(gb.java:354)
at com.ibm.jsse2.gb.a(gb.java:292)
at com.ibm.jsse2.hb.a(hb.java:118)
at com.ibm.jsse2.hb.a(hb.java:162)
at com.ibm.jsse2.gb.n(gb.java:262)
at com.ibm.jsse2.gb.a(gb.java:177)
at com.ibm.jsse2.sc.a(sc.java:71)
at com.ibm.jsse2.sc.g(sc.java:167)
at com.ibm.jsse2.sc.a(sc.java:357)
at com.ibm.jsse2.sc.startHandshake(sc.java:97)
at com.ibm.net.ssl.www2.protocol.https.c.afterConnect(c.java:79)
at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:8)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:827)
at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:40)
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:136)
Caused by: com.ibm.jsse2.util.g: PKIX path building failed: java.security.cert.CertPathBuilderException: PKIXCertPathBuilderImpl could not build a valid CertPath.; internal cause is:
java.security.cert.CertPathValidatorException: The certificate issued by CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU=“© 2006 VeriSign, Inc. - For authorized use only”, OU=VeriSign Trust Network, O=“VeriSign, Inc.”, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
at com.ibm.jsse2.util.e.b(e.java:78)
at com.ibm.jsse2.util.e.b(e.java:45)
at com.ibm.jsse2.util.d.a(d.java:12)
at com.ibm.jsse2.gc.a(gc.java:15)
at com.ibm.jsse2.gc.checkServerTrusted(gc.java:48)
at com.ibm.ws.ssl.core.WSX509TrustManager.checkServerTrusted(WSX509TrustManager.java:310)
at com.ibm.jsse2.hb.a(hb.java:116)
Caused by: java.security.cert.CertPathBuilderException: PKIXCertPathBuilderImpl could not build a valid CertPath.; internal cause is:
java.security.cert.CertPathValidatorException: The certificate issued by CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU=“© 2006 VeriSign, Inc. - For authorized use only”, OU=VeriSign Trust Network, O=“VeriSign, Inc.”, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
at com.ibm.security.cert.PKIXCertPathBuilderImpl.engineBuild(PKIXCertPathBuilderImpl.java:411)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:258)
at com.ibm.jsse2.util.e.b(e.java:51)
Caused by: java.security.cert.CertPathValidatorException: The certificate issued by CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU=“© 2006 VeriSign, Inc. - For authorized use only”, OU=VeriSign Trust Network, O=“VeriSign, Inc.”, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
at com.ibm.security.cert.BasicChecker.(BasicChecker.java:111)
at com.ibm.security.cert.PKIXCertPathValidatorImpl.engineValidate(PKIXCertPathValidatorImpl.java:176)
at com.ibm.security.cert.PKIXCertPathBuilderImpl.myValidator(PKIXCertPathBuilderImpl.java:732)
at com.ibm.security.cert.PKIXCertPathBuilderImpl.buildCertPath(PKIXCertPathBuilderImpl.java:649)


#2

All I can really say is that by looking at the stacktrace this appears to be a Java certificate issue. Maybe check with IBM whether the version of WebSphere App Server you are running on needs an update?