Code example for AuthState

Methods: getAuthScheme

0
			throws IOException { 
			 
			AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
			 
			// If no auth scheme avaialble yet, try to initialize it preemptively 
			if (authState.getAuthScheme() == null) {
				AuthScheme authScheme = (AuthScheme)context.getAttribute("preemptive-auth");
				CredentialsProvider credsProvider =
					(CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
				HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
				if (authScheme != null) {
					Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), 
																				   targetHost.getPort()));
					if (creds == null) {
						throw new IOException("No credentials for preemptive authentication");
					} 
					authState.setAuthScheme(authScheme);
					authState.setCredentials(creds);
				} 
			} 
Stop searching for code, let great code find you!  Add Codota to your java IDE