On 26/09/2009, [email protected] <[email protected]> wrote: > Author: olegk > Date: Sat Sep 26 11:56:06 2009 > New Revision: 819114 > > URL: http://svn.apache.org/viewvc?rev=819114&view=rev > Log: > Cleaned up examples
Ah - I wondered why it was necessary to register the http/https schemes, seemed like those should have been done by default. > Modified: > > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java > > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java > > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java > > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java > > Modified: > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java?rev=819114&r1=819113&r2=819114&view=diff > > ============================================================================== > --- > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java > (original) > +++ > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java > Sat Sep 26 11:56:06 2009 > @@ -31,18 +31,9 @@ > import org.apache.http.HttpEntity; > import org.apache.http.HttpHost; > import org.apache.http.HttpResponse; > -import org.apache.http.HttpVersion; > import org.apache.http.client.HttpClient; > import org.apache.http.client.methods.HttpGet; > -import org.apache.http.conn.ClientConnectionManager; > -import org.apache.http.conn.scheme.PlainSocketFactory; > -import org.apache.http.conn.scheme.Scheme; > -import org.apache.http.conn.scheme.SchemeRegistry; > import org.apache.http.impl.client.DefaultHttpClient; > -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; > -import org.apache.http.params.BasicHttpParams; > -import org.apache.http.params.HttpParams; > -import org.apache.http.params.HttpProtocolParams; > import org.apache.http.util.EntityUtils; > > /** > @@ -53,27 +44,9 @@ > public class ClientExecuteDirect { > > public static void main(String[] args) throws Exception { > + DefaultHttpClient httpclient = new DefaultHttpClient(); > > HttpHost target = new HttpHost("www.apache.org", 80, "http"); > - > - // general setup > - SchemeRegistry supportedSchemes = new SchemeRegistry(); > - > - // Register the "http" protocol scheme, it is required > - // by the default operator to look up socket factories. > - supportedSchemes.register(new Scheme("http", > - PlainSocketFactory.getSocketFactory(), 80)); > - > - // prepare parameters > - HttpParams params = new BasicHttpParams(); > - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); > - HttpProtocolParams.setContentCharset(params, "UTF-8"); > - HttpProtocolParams.setUseExpectContinue(params, true); > - > - ClientConnectionManager connMgr = new > ThreadSafeClientConnManager(params, > - supportedSchemes); > - DefaultHttpClient httpclient = new DefaultHttpClient(connMgr, > params); > - > HttpGet req = new HttpGet("/"); > > System.out.println("executing request to " + target); > > Modified: > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java?rev=819114&r1=819113&r2=819114&view=diff > > ============================================================================== > --- > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java > (original) > +++ > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java > Sat Sep 26 11:56:06 2009 > @@ -31,20 +31,10 @@ > import org.apache.http.HttpEntity; > import org.apache.http.HttpHost; > import org.apache.http.HttpResponse; > -import org.apache.http.HttpVersion; > import org.apache.http.client.HttpClient; > import org.apache.http.client.methods.HttpGet; > -import org.apache.http.conn.ClientConnectionManager; > import org.apache.http.conn.params.ConnRoutePNames; > -import org.apache.http.conn.scheme.PlainSocketFactory; > -import org.apache.http.conn.scheme.Scheme; > -import org.apache.http.conn.scheme.SchemeRegistry; > -import org.apache.http.conn.ssl.SSLSocketFactory; > import org.apache.http.impl.client.DefaultHttpClient; > -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; > -import org.apache.http.params.BasicHttpParams; > -import org.apache.http.params.HttpParams; > -import org.apache.http.params.HttpProtocolParams; > import org.apache.http.util.EntityUtils; > > /** > @@ -55,34 +45,12 @@ > public class ClientExecuteProxy { > > public static void main(String[] args)throws Exception { > - > - // make sure to use a proxy that supports CONNECT > - HttpHost target = new HttpHost("issues.apache.org", 443, "https"); > HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); > > - // general setup > - SchemeRegistry supportedSchemes = new SchemeRegistry(); > - > - // Register the "http" and "https" protocol schemes, they are > - // required by the default operator to look up socket factories. > - supportedSchemes.register(new Scheme("http", > - PlainSocketFactory.getSocketFactory(), 80)); > - supportedSchemes.register(new Scheme("https", > - SSLSocketFactory.getSocketFactory(), 443)); > - > - // prepare parameters > - HttpParams params = new BasicHttpParams(); > - HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); > - HttpProtocolParams.setContentCharset(params, "UTF-8"); > - HttpProtocolParams.setUseExpectContinue(params, true); > - > - ClientConnectionManager ccm = new > ThreadSafeClientConnManager(params, > - supportedSchemes); > - > - DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params); > - > + DefaultHttpClient httpclient = new DefaultHttpClient(); > httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, > proxy); > > + HttpHost target = new HttpHost("issues.apache.org", 443, "https"); > HttpGet req = new HttpGet("/"); > > System.out.println("executing request to " + target + " via " + > proxy); > > Modified: > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java?rev=819114&r1=819113&r2=819114&view=diff > > ============================================================================== > --- > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java > (original) > +++ > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java > Sat Sep 26 11:56:06 2009 > @@ -41,8 +41,7 @@ > /** > * Kerberos auth example. > * > - * <p>Takes one arguement args[0] = 'http://examplehost/path/'</p> > - * <h5>Information</h5> > + * <p><b>Information</b></p> > * <p>For the best compatibility use Java >= 1.6 as it supports SPNEGO > authentication more > completely.</p> > * <p><em>NegotiateSchemeFactory</em></p> > @@ -60,7 +59,7 @@ > * Requires use of <a href="http://www.bouncycastle.org/java.html">bouncy > castle libs</a> > * </p> > * > - * <h6>Addtional Config Files</h6> > + * <p><b>Addtional Config Files</b></p> > * <p>Two files control how Java uses/configures Kerberos. Very basic > examples are below. There > * is a large amount of information on the web.</p> > * <p><a > href="http://java.sun.com/j2se/1.5.0/docs/guide/security/jaas/spec/com/sun/security/auth/module/Krb5LoginModule.html">http://java.sun.com/j2se/1.5.0/docs/guide/security/jaas/spec/com/sun/security/auth/module/Krb5LoginModule.html</a> > @@ -98,6 +97,29 @@ > * com.sun.security.auth.module.Krb5LoginModule required client=TRUE > useTicketCache=true debug=true; > *}; > * </pre> > + * <p><b>Windows specific configuration</b></p> > + * <p> > + * The registry key <em>allowtgtsessionkey</em> should be added, and set > correctly, to allow > + * session keys to be sent in the Kerberos Ticket-Granting Ticket. > + * </p> > + * <p> > + * On the Windows Server 2003 and Windows 2000 SP4, here is the required > registry setting: > + * </p> > + * <pre> > + * > HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters > + * Value Name: allowtgtsessionkey > + * Value Type: REG_DWORD > + * Value: 0x01 > + * </pre> > + * <p> > + * Here is the location of the registry setting on Windows XP SP2: > + * </p> > + * <pre> > + * HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\ > + * Value Name: allowtgtsessionkey > + * Value Type: REG_DWORD > + * Value: 0x01 > + * </pre> > * > * @since 4.1 > */ > @@ -110,27 +132,6 @@ > System.setProperty("sun.security.krb5.debug", "true"); > > System.setProperty("javax.security.auth.useSubjectCredsOnly","false"); > > - /* > - * Below is helpful on windows. > - * Solution 2: You need to update the Windows registry to disable > this new feature. > - * The registry key allowtgtsessionkey should be added--and set > correctly--to allow > - * session keys to be sent in the Kerberos Ticket-Granting Ticket. > - * > - * On the Windows Server 2003 and Windows 2000 SP4, here is the > required registry setting: > - * > - * > HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters > - * Value Name: allowtgtsessionkey > - * Value Type: REG_DWORD > - * Value: 0x01 > - * > - * Here is the location of the registry setting on Windows XP SP2: > - * > - * HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\ > - * Value Name: allowtgtsessionkey > - * Value Type: REG_DWORD > - * Value: 0x01 > - */ > - > DefaultHttpClient httpclient = new DefaultHttpClient(); > > /* > > Modified: > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java?rev=819114&r1=819113&r2=819114&view=diff > > ============================================================================== > --- > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java > (original) > +++ > httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java > Sat Sep 26 11:56:06 2009 > @@ -50,8 +50,8 @@ > // Create a response handler > ResponseHandler<String> responseHandler = new BasicResponseHandler(); > String responseBody = httpclient.execute(httpget, responseHandler); > + System.out.println("----------------------------------------"); > System.out.println(responseBody); > - > System.out.println("----------------------------------------"); > > // When HttpClient instance is no longer needed, > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
