It appears that initializing the OAuthClient with a HttpClientPool
solves the issue. The issue appears to be related to how the Java
OAuth library shared a single HttpClient but I'm not positive why this
causes issues.

Instead of:
client = new OAuthClient(new HttpClient4());

try:
HttpClientPool pool = new HttpClientPool() {
    public HttpClient getHttpClient(URL u) {
        return new DefaultHttpClient();
    }
};
client = new OAuthClient(new HttpClient4(pool));

Let me know if this resolves your issues.

Adam

On Jan 20, 3:14 am, Tane Piper <[email protected]> wrote:
> Hi Sean,
>
> I've added this to before the definitions of both my AndroidAccessor
> class and my PostNote class, however I'm not getting any additional
> debug statements.  Here is my Accessor, is this correct?
>
> package org.ifies.brightroid.oauth;
>
> import java.io.IOException;
> import java.net.URISyntaxException;
> import java.util.Collection;
> import java.util.List;
> import java.util.Map.Entry;
>
> import net.oauth.OAuth;
> import net.oauth.OAuthAccessor;
> import net.oauth.OAuthConsumer;
> import net.oauth.OAuthException;
> import net.oauth.OAuthMessage;
> import net.oauth.OAuthServiceProvider;
> import net.oauth.client.OAuthClient;
> import net.oauth.client.httpclient4.HttpClient4;
>
> public class AndroidAccessor {
>
>     private final String OAUTH_REQUEST_TOKEN_URL = "http://
> brightkite.com/oauth/request_token";
>     private final String OAUTH_AUTHORIZE_URL = "http://brightkite.com/
> oauth/authorize";
>     private final String OAUTH_ACCESS_TOKEN_URL = "http://
> brightkite.com/oauth/access_token";
>     private String CONSUMER_KEY = "";
>     private String CONSUMER_SECRET = "";
>
>     public OAuthServiceProvider provider;
>     public OAuthConsumer consumer;
>     public OAuthAccessor accessor;
>     public OAuthClient client;
>
>     static {
>         System.getProperties().put("org.apache.commons.logging.Log",
>                         "org.apache.commons.logging.impl.SimpleLog");
>         System.getProperties().put
> ("org.apache.commons.logging.simplelog.defaultlog",
>                         "trace");
>     }
>
>         /**
>          * @param args
>          */
>         public void main(String[] args) {
>                 // TODO Auto-generated method stub
>         }
>
>         public void createAccessor() {
>                 provider = new OAuthServiceProvider(
>                                 OAUTH_REQUEST_TOKEN_URL,
>                                 OAUTH_AUTHORIZE_URL,
>                                 OAUTH_ACCESS_TOKEN_URL);
>                 consumer = new OAuthConsumer(null // callback URL
>                     , CONSUMER_KEY // consumer key
>                     , CONSUMER_SECRET // consumer secret
>                     , provider);
>                 accessor = new OAuthAccessor(consumer);
>                 client = new OAuthClient(new HttpClient4());
>         }
>
>         public void setAccessToken(String access_token) {
>                 accessor.accessToken = access_token;
>         }
>
>         public String getAccessToken() {
>                 return accessor.accessToken;
>         }
>
>         public void requestAccessToken() throws IOException, OAuthException,
> URISyntaxException {
>                 client.getAccessToken(accessor, null, null);
>         }
>
>         public void getRequestToken() throws IOException, OAuthException,
> URISyntaxException {
>                 client.getRequestToken(accessor);
>         }
>
>         public String getAuthorisationUrl() throws IOException {
>                 return OAuth.addParameters
> (accessor.consumer.serviceProvider.userAuthorizationURL,
> "oauth_token", accessor.requestToken);
>         }
>
>         public OAuthMessage getMessage(String url, Collection<? extends
> Entry> parameters) throws IOException, OAuthException,
> URISyntaxException {
>                 return client.invoke(accessor, "GET", url, parameters);
>         }
>
>         public void postMessage(String url, Collection<? extends Entry>
> parameters) throws IOException, OAuthException, URISyntaxException {
>                 client.invoke(accessor, "POST", url, parameters);
>         }
>
> }
>
> On Jan 20, 9:40 am, "Sean Sullivan" <[email protected]> wrote:
>
> > Are you using the OAuth Java library with HttpClient 4 ?
>
> > If you are using HttpClient 4.x (or Http Client 3.x), you can enable
> > trace level logging
> > by adding this static initializer to your app:
>
> > static
>
> > {
>
> > System.getProperties().put("org.apache.commons.logging.Log",
> > "org.apache.commons.logging.impl.SimpleLog");
>
> > System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog",
> > "trace");
>
> > }
>
> > The trace output should help you debug this.
>
> > Sean
>
> > On Tue, Jan 20, 2009 at 10:33 AM, Tane Piper
>
> > <[email protected]> wrote:
>
> > > Hey folks,
>
> > > I'm adding some new features to my app - but have had some weird
> > > results recently.  In my new feature, I use OAuth to post a note to
> > > the Brightkite service.  I'm getting the exact same result each time
> > > here.  When I open the activity and try to post, I have to do it
> > > twice, every time.  And every time I get the exact same errors:
>
> > > 01-20 09:25:41.016: WARN/System.err(19409):
> > > org.apache.http.client.ClientProtocolException
> > > 01-20 09:25:41.026: WARN/System.err(19409):     at
> > > org.apache.http.impl.client.AbstractHttpClient.execute
> > > (AbstractHttpClient.java:557)
> > > 01-20 09:25:41.036: WARN/System.err(19409):     at
> > > org.apache.http.impl.client.AbstractHttpClient.execute
> > > (AbstractHttpClient.java:487)
> > > 01-20 09:25:41.036: WARN/System.err(19409):     at
> > > org.apache.http.impl.client.AbstractHttpClient.execute
> > > (AbstractHttpClient.java:465)
> > > 01-20 09:25:41.046: WARN/System.err(19409):     at
> > > net.oauth.client.httpclient4.HttpClient4.execute(HttpClient4.java:89)
> > > 01-20 09:25:41.056: WARN/System.err(19409):     at
> > > net.oauth.client.OAuthClient.invoke(OAuthClient.java:260)
> > > 01-20 09:25:41.056: WARN/System.err(19409):     at
> > > net.oauth.client.OAuthClient.invoke(OAuthClient.java:160)
> > > 01-20 09:25:41.066: WARN/System.err(19409):     at
> > > org.ifies.brightroid.oauth.AndroidAccessor.postMessage
> > > (AndroidAccessor.java:76)
> > > 01-20 09:25:41.066: WARN/System.err(19409):     at
> > > org.ifies.brightroid.me.PostNote$2.run(PostNote.java:77)
> > > 01-20 09:25:41.076: WARN/System.err(19409):     at
> > > android.os.Handler.handleCallback(Handler.java:542)
> > > 01-20 09:25:41.076: WARN/System.err(19409):     at
> > > android.os.Handler.dispatchMessage(Handler.java:86)
> > > 01-20 09:25:41.086: WARN/System.err(19409):     at
> > > android.os.Looper.loop(Looper.java:123)
> > > 01-20 09:25:41.086: WARN/System.err(19409):     at
> > > android.app.ActivityThread.main(ActivityThread.java:3742)
> > > 01-20 09:25:41.096: WARN/System.err(19409):     at
> > > java.lang.reflect.Method.invokeNative(Native Method)
> > > 01-20 09:25:41.096: WARN/System.err(19409):     at
> > > java.lang.reflect.Method.invoke(Method.java:515)
> > > 01-20 09:25:41.106: WARN/System.err(19409):     at
> > > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> > > (ZygoteInit.java:739)
> > > 01-20 09:25:41.106: WARN/System.err(19409):     at
> > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
> > > 01-20 09:25:41.116: WARN/System.err(19409):     at
> > > dalvik.system.NativeStart.main(Native Method)
> > > 01-20 09:25:41.116: WARN/System.err(19409): Caused by:
> > > org.apache.http.client.NonRepeatableRequestException: Cannot retry
> > > request with a non-repeatable request entity
> > > 01-20 09:25:41.136: WARN/System.err(19409):     at
> > > org.apache.http.impl.client.DefaultRequestDirector.execute
> > > (DefaultRequestDirector.java:402)
> > > 01-20 09:25:41.136: WARN/System.err(19409):     at
> > > org.apache.http.impl.client.AbstractHttpClient.execute
> > > (AbstractHttpClient.java:555)
> > > 01-20 09:25:41.146: WARN/System.err(19409):     ... 16 more
>
> > > 01-20 09:26:18.196: WARN/System.err(19409):
> > > net.oauth.OAuthProblemException: HTTP/1.1 201 Created
> > > 01-20 09:26:18.206: WARN/System.err(19409):     at
> > > net.oauth.client.OAuthClient.invoke(OAuthClient.java:264)
> > > 01-20 09:26:18.216: WARN/System.err(19409):     at
> > > net.oauth.client.OAuthClient.invoke(OAuthClient.java:160)
> > > 01-20 09:26:18.216: WARN/System.err(19409):     at
> > > org.ifies.brightroid.oauth.AndroidAccessor.postMessage
> > > (AndroidAccessor.java:76)
> > > 01-20 09:26:18.226: WARN/System.err(19409):     at
> > > org.ifies.brightroid.me.PostNote$2.run(PostNote.java:77)
> > > 01-20 09:26:18.226: WARN/System.err(19409):     at
> > > android.os.Handler.handleCallback(Handler.java:542)
> > > 01-20 09:26:18.236: WARN/System.err(19409):     at
> > > android.os.Handler.dispatchMessage(Handler.java:86)
> > > 01-20 09:26:18.236: WARN/System.err(19409):     at
> > > android.os.Looper.loop(Looper.java:123)
> > > 01-20 09:26:18.246: WARN/System.err(19409):     at
> > > android.app.ActivityThread.main(ActivityThread.java:3742)
> > > 01-20 09:26:18.246: WARN/System.err(19409):     at
> > > java.lang.reflect.Method.invokeNative(Native Method)
> > > 01-20 09:26:18.256: WARN/System.err(19409):     at
> > > java.lang.reflect.Method.invoke(Method.java:515)
> > > 01-20 09:26:18.256: WARN/System.err(19409):     at
> > > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> > > (ZygoteInit.java:739)
> > > 01-20 09:26:18.266: WARN/System.err(19409):     at
> > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
> > > 01-20 09:26:18.266: WARN/System.err(19409):     at
> > > dalvik.system.NativeStart.main(Native Method)
>
> > > The first one I have no idea why it's happening, but the second - I
> > > get a 201 created, which is a valid code - but the library still
> > > throws an exception. Does anyone have any ideas why it would do this,
> > > and how to handle it better?  Is it possibly a bug in the library and
> > > it's only expecting a 200??
>
> > > Any help would be appreciated.
>
> > > Regards,
> > > Tane
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to