Cleaned up examples
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@819114 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
af4b944189
commit
09601a328f
|
@ -31,18 +31,9 @@ import org.apache.http.Header;
|
|||
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 @@ import org.apache.http.util.EntityUtils;
|
|||
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);
|
||||
|
|
|
@ -31,20 +31,10 @@ import org.apache.http.Header;
|
|||
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 @@ import org.apache.http.util.EntityUtils;
|
|||
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);
|
||||
|
|
|
@ -41,8 +41,7 @@ import org.apache.http.util.EntityUtils;
|
|||
/**
|
||||
* 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 @@ import org.apache.http.util.EntityUtils;
|
|||
* 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 @@ import org.apache.http.util.EntityUtils;
|
|||
* 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 @@ public class ClientKerberosAuthentication {
|
|||
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();
|
||||
|
||||
/*
|
||||
|
|
|
@ -50,8 +50,8 @@ public class ClientWithResponseHandler {
|
|||
// 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,
|
||||
|
|
Loading…
Reference in New Issue