Narender007 / oauth-signpost

Automatically exported from code.google.com/p/oauth-signpost
0 stars 0 forks source link

Oauth java.lang.ClassNotFoundException: org.apache.http.HttpRequest #63

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
im tryng get hattrick data using Oauth

Hattrick implements OAuth Core 1.0a as specified in the standard, so if you use 
a client library that supports this it should work out of the box. You will 
need the following details to specify or configure the library to be able to 
use OAuth at Hattrick.
- ConsumerKey and ConsumerSecret: Can be found on the OAuth page for your 
product (in the menu on the right)
- Request Token path: https://chpp.hattrick.org/oauth/request_token.ashx
- Authorize path: https://chpp.hattrick.org/oauth/authorize.aspx
- Access Token path: https://chpp.hattrick.org/oauth/access_token.ashx
- Path to protected resources: All CHPP XML files are downloaded from 
http://chpp.hattrick.org/chppxml.ashx, specifying which file is requested using 
the parameter file=teamdetails (for example). See API Documentation for more 
info.
- Use GET method for all requests
- Use HMAC-SHA1 to sign all requests
- Always provide oauth_callback in the request to request_token.ashx. If your 
product cannot receive a callback, use oauth_callback=oob 

this is my code:

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.exception.*;
import oauth.signpost.basic.*;
import oauth.signpost.commonshttp.*;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.MalformedURLException;
import oauth.signpost.http.HttpResponse;

OAuthConsumer consumer = new CommonsHttpOAuthConsumer(YOUR_API_KEY, 
YOUR_API_SECRET);

CommonsHttpOAuthProvider(tokenRequestPath, accessRequestPath, authorizePath);

OAuthProvider provider = new DefaultOAuthProvider(tokenRequestPath, 
accessRequestPath, authorizePath);

   String url = "";
   try{
    //url = provider.retrieveRequestToken(consumer, "http://chpp.hattrick.org/chppxml.ashx");
       url = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
   }
   catch (OAuthMessageSignerException omse) {
       System.out.println(omse);
       url="nop";
   }
   catch (OAuthNotAuthorizedException onae) {
       System.out.println(onae);
       url="nop";
   }
   catch (OAuthCommunicationException oce) {
       System.out.println(oce);
       url="nop";
   }
   catch (OAuthExpectationFailedException oefe) {
        System.out.println(oefe);
       url="nop";

   }
    System.out.println("Request token: " + consumer.getToken());
    System.out.println("Token secret: " + consumer.getTokenSecret());

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String oauth_verifier ="";
        try{
            oauth_verifier = br.readLine();
        }catch(IOException  ioe){
            System.out.println(ioe);
        }
        System.out.println(oauth_verifier);
    //retrieveAccessToken
    try{
        provider.retrieveAccessToken(consumer, oauth_verifier);
        //provider.retrieveAccessToken(consumer, rRT);
    } catch(OAuthMessageSignerException omse){
        System.out.println(omse+"\n");
    }catch(OAuthNotAuthorizedException onae){
        System.out.println(onae+"\n");
    }catch(OAuthExpectationFailedException oefe){
        System.out.println(oefe+"\n");
    }
    catch(OAuthCommunicationException oce){
        System.out.println(oce+"\n");
    }
 System.out.println("Access token: " + consumer.getToken());
 System.out.println("Token secret: " + consumer.getTokenSecret());

        URL url1 = null;
        try {
            //try{
             url1 = new URL("https://chpp.hattrick.org/oauth/authorize.aspx?oauth_token="+consumer.getTokenSecret()+"&file=teamdetails&version=2.4");

            //} catch(){
        } catch (MalformedURLException ex) {
            //Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
            System.out.print(ex);
        }

        HttpURLConnection request = null;
        try {
            request = (HttpURLConnection) url1.openConnection();
        } catch (IOException ex) {
            //Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
            System.out.print(ex);
        }

        try {
            consumer.sign(request);
        } catch (OAuthMessageSignerException ex) {
            System.out.print(ex);
Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
        } catch (OAuthExpectationFailedException ex) {
            System.out.print(ex);
            // Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
        } catch (OAuthCommunicationException ex) {
            System.out.print(ex);
            // Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println("Sending request...");
        try {
            request.connect();
        } catch (IOException ex) {
             System.out.print(ex);
            // Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
        } catch (IOException ex) {
             System.out.print(ex);
            // Logger.getLogger(JMA_MAIN.class.getName()).log(Level.SEVERE, null, ex);
        }

it gives the following error i think when trying consumer.sign(request):

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: 
org/apache/http/HttpRequest
        at oauth.signpost.commonshttp.CommonsHttpOAuthConsumer.wrap(CommonsHttpOAuthConsumer.java:35)
        at oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:119)
        at jma.JMA_MAIN.jToggleButton1ActionPerformed(JMA_MAIN.java:202)
        at jma.JMA_MAIN.access$000(JMA_MAIN.java:43)
        at jma.JMA_MAIN$1.actionPerformed(JMA_MAIN.java:82)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:291)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequest
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        ... 30 more

Original issue reported on code.google.com by rpgome...@gmail.com on 17 Dec 2010 at 11:37