Re: HTTP request using another method such as PATCH
On Tue, 2011-02-01 at 15:30 +0100, Grzegorz Szpetkowski wrote: > Hi, > > According to HttpClient Tutorial (1.1.1. HTTP request) there is > support for methods: GET, HEAD, POST, PUT, DELETE, TRACE and OPTIONS. > How I can make request using PATCH (RFC 5789) method or CONNECT ? You ought not execute CONNECT requests directly and let HttpClient take care of connection tunneling. > I > choosed Apache HttpClient library because I throught it provides much > more flexibility than JDK HttpURLConnection. > > I found there is one way to make new class, wchich extends one off > supported method (e.g. POST): > > class HttpPatch extends HttpPost { > public final static String METHOD_NAME = "PATCH"; > > public HttpPatch(final String uri) { > super(uri); > } > > public String getMethod() { > return "PATCH"; > } > } > > Is this "correct" way ? > Yes, it is. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
Re: OAuth support for HTTPCient
Hi Robert, Yes, sorry. The "client" is an instance of HttpClient (e.g. DefaultHttpClient). Cheers, Jon Jon Moore Comcast Interactive Media On 2/1/11 1:01 AM, "Robert Stagner" wrote: >Hi Jon, > >That is music to my ears! I assume that the "client" referred to in your >example > >client.addRequestInterceptor(oauthInterceptor, 0); > >points to an instance of HTTPClient. Would that be an accurate statement? > > >On Mon, Jan 31, 2011 at 10:48 AM, Moore, Jonathan < >jonathan_mo...@comcast.com> wrote: > >> Hi Robert, >> >> As it turns out, you can. You will want to use the "oauth-httpclient4" >> library available here: >> http://code.google.com/p/oauth/ >> >> If you are a Maven user, we use the following dependency: >> >> >> net.oauth.core >> oauth-httpclient4 >> 20090913 >> jar >> compile >> >> >> >> The trick is to add a request interceptor to your HttpClient (code >> included further down): >> >> OAuthCredentials creds = new OAuthCredentials(consumer,secret); >> HttpRequestInterceptor oauthInterceptor = new OAuthInterceptor(creds); >> client.addRequestInterceptor(oauthInterceptor, 0); >> >> >> Here's the code for OAuthInterceptor.java: >> >> >> import java.io.IOException; >> >> import net.oauth.client.httpclient4.OAuthCredentials; >> import net.oauth.client.httpclient4.OAuthSchemeFactory; >> >> import org.apache.http.HttpException; >> import org.apache.http.HttpRequest; >> import org.apache.http.HttpRequestInterceptor; >> import org.apache.http.auth.AuthScheme; >> import org.apache.http.auth.AuthState; >> import org.apache.http.auth.Credentials; >> import org.apache.http.client.protocol.ClientContext; >> import org.apache.http.params.BasicHttpParams; >> import org.apache.http.protocol.HttpContext; >> >> /** >> * An {@link HttpRequestInterceptor} that adds OAuth credentials to >> requests >> * that are passed to it. An instance of this class is associated with a >> * particular OAuth credential. >> */public class OAuthInterceptor implements HttpRequestInterceptor { >> >> private final OAuthCredentials credentials; >> /** >> * Creates an {@link OAuthInterceptor} using the given credentials. >> * @param credentials The OAuth credentials to add to HTTP requests >> */ >> public OAuthInterceptor(OAuthCredentials credentials) { >> this.credentials = credentials; >> } >> >> public void process(HttpRequest request, HttpContext context) >> throws HttpException, IOException { >> AuthState authState = (AuthState) >> context.getAttribute(ClientContext.TARGET_AUTH_STATE); >> if (authState != null && authState.getAuthScheme() == null) >>{ >> AuthScheme scheme = new >>OAuthSchemeFactory().newInstance( >> new BasicHttpParams()); >> Credentials cred = credentials; >> authState.setAuthScheme(scheme); >> authState.setCredentials(cred); >> } >>} >> } >> >> >> >> Jon Moore >> Comcast Interactive Media >> >> >> >> >> >> >> On 1/31/11 12:14 PM, "Robert Stagner" wrote: >> >> >Hi, >> > >> >I'm new to the list, and we've just begun testing a RESTful application >> >that >> >uses OAuth for its authentication. I see from the features supported >>by >> >HTTPClient that OAuth is not on the list >> > >> >Basic, Digest, NTLMv1, NTLMv2, NTLM2 Session, SNPNEGO/Kerberos >> >authentication schemes. >> > >> >Is there a way to support OAuth within HTTPClient? >> > >> >-- >> >Regards, >> >Robert >> >> >> - >> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org >> For additional commands, e-mail: httpclient-users-h...@hc.apache.org >> >> > > >-- >Regards, >Robert - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
HTTP request using another method such as PATCH
Hi, According to HttpClient Tutorial (1.1.1. HTTP request) there is support for methods: GET, HEAD, POST, PUT, DELETE, TRACE and OPTIONS. How I can make request using PATCH (RFC 5789) method or CONNECT ? I choosed Apache HttpClient library because I throught it provides much more flexibility than JDK HttpURLConnection. I found there is one way to make new class, wchich extends one off supported method (e.g. POST): class HttpPatch extends HttpPost { public final static String METHOD_NAME = "PATCH"; public HttpPatch(final String uri) { super(uri); } public String getMethod() { return "PATCH"; } } Is this "correct" way ? Thanks, Grzegorz Szpetkowski - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
RE: Problem with Proxy Basic Authentication
On Tue, 2011-02-01 at 05:19 -0800, Pifagor wrote: > > olegk wrote: > > > > > > it turns out that the ProxySelectorRoutePlanner did not pick up proxy > > settings correctly. > > > > Oleg > > > > > > > It correctly picks host and port but not username and password. Also JRE > does not provide http.proxyUser or http.proxyPassword, even if you provide > those while loading applet. There might be other ways to retrieve that > information from Java, but I don't know one. Per default Httpclient does not use system properties to obtain configuration settings. You need to extract user credentials using whatever mechanism you are comfortable with (be it system properties, configuration file or a UI dialog) and stick them into the CredentialsProvider used by HttpClient. Hope this helps. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
RE: Problem with Proxy Basic Authentication
olegk wrote: > > > it turns out that the ProxySelectorRoutePlanner did not pick up proxy > settings correctly. > > Oleg > > It correctly picks host and port but not username and password. Also JRE does not provide http.proxyUser or http.proxyPassword, even if you provide those while loading applet. There might be other ways to retrieve that information from Java, but I don't know one. -- View this message in context: http://old.nabble.com/RE%3A-Problem-with-Proxy-Basic-Authentication-tp30753803p30816056.html Sent from the HttpClient-User mailing list archive at Nabble.com. - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org
RE: Problem with Proxy Basic Authentication
On Mon, 2011-01-31 at 07:17 -0800, Pifagor wrote: > Oleg > > Your advice needed: > > When I import browser proxy settings into HttpClient in applet using: > > DefaultHttpClient hc = new DefaultHttpClient(); > ProxySelectorRoutePlanner routePlanner = new > ProxySelectorRoutePlanner( > hc.getConnectionManager().getSchemeRegistry(), > ProxySelector.getDefault() > ); > hc.setRoutePlanner(routePlanner); > hc.getProxyAuthenticationHandler(); > ... > HttpResponse resp = hc.execute(m); > > I get the following error: > > "Proxy Authentication Required" > > I tried both basic and digest authentication with Squid. When applet > initializes it shows a Java popup window > > "Authentication Required" > "Enter login details to access Squid proxy proxy-caching webserver > at ..." > > and username and password fields and accepts them which means, I assume, > that proxy authenticates applet. My .java.policy is here: > > grant { > permission java.io.FilePermission "<>", "read"; > permission java.net.NetPermission "getProxySelector"; > permission java.net.SocketPermission "*","connect,resolve"; > }; > > Applet is signed. What can cause this error? I know next to nothing about applets. I may take a look at a wire / context log of the session, if you produce one, but I will not be able to do much about applet specific stuff, if it turns out that the ProxySelectorRoutePlanner did not pick up proxy settings correctly. Oleg - To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org