package net.yxy.chukonu.rest;

public class WSAuthenticationClient {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

@@ -24,16 +24,722 @@
 .rest;%0A%0A
+import java.io.IOException;%0Aimport java.net.URL;%0A%0Aimport org.apache.http.HttpHost;%0Aimport org.apache.http.auth.AuthScope;%0Aimport org.apache.http.auth.UsernamePasswordCredentials;%0Aimport org.apache.http.client.AuthCache;%0Aimport org.apache.http.client.CredentialsProvider;%0Aimport org.apache.http.client.methods.CloseableHttpResponse;%0Aimport org.apache.http.client.methods.HttpGet;%0Aimport org.apache.http.client.protocol.HttpClientContext;%0Aimport org.apache.http.impl.auth.BasicScheme;%0Aimport org.apache.http.impl.client.BasicAuthCache;%0Aimport org.apache.http.impl.client.BasicCredentialsProvider;%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.HttpClientBuilder;%0A%0A
 public c
@@ -768,16 +768,17 @@
 lient %7B%0A
+%09
 %0A%09public
@@ -789,71 +789,1634 @@
 tic 
-void main(String%5B%5D args) %7B%0A%09%09// TODO Auto-generated method stub
+boolean validateWithBasicAuth(String url, String username, String password)%7B%0A%09%09HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();%0A%09%09CloseableHttpClient httpclient = httpClientBuilder.build();%0A%09%09URL urlObj = null;%0A%09%09CloseableHttpResponse response = null;%0A%09%09try %7B%0A%09%09%09urlObj = new URL(url);%0A%09%09%09HttpHost targetHost = new HttpHost(urlObj.getHost(), 80, %22http%22);%0A%09%09%09CredentialsProvider credsProvider = new BasicCredentialsProvider();%0A%09%09%09credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),%0A%09%09%09%09%09new UsernamePasswordCredentials(username, password));%0A%09%0A%09%09%09// Create AuthCache instance%0A%09%09%09AuthCache authCache = new BasicAuthCache();%0A%09%09%09// Generate BASIC scheme object and add it to the local auth cache%0A%09%09%09BasicScheme basicAuth = new BasicScheme();%0A%09%09%09authCache.put(targetHost, basicAuth);%0A%09%0A%09%09%09// Add AuthCache to the execution context%0A%09%09%09HttpClientContext context = HttpClientContext.create();%0A%09%09%09context.setCredentialsProvider(credsProvider);%0A%09%09%09context.setAuthCache(authCache);%0A%09%0A%09%09%09HttpGet httpget = new HttpGet(urlObj.getPath());%0A%09%09%09%09response = httpclient.execute(targetHost, httpget, context);%0A%09%09%09%09int code = response.getStatusLine().getStatusCode();%0A%09%09%09%09if (code %3C 400) %7B%0A%09%09%09%09%09return true;%0A%09%09%09%09%7D%0A%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09return false;%0A%09%09%7D finally %7B%0A%09%09%09if (response != null) %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09response.close();%0A%09%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return false;%0A%09%7D%0A%09%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09System.out.println(validateWithBasicAuth(%22http://httpbin.org/basic-auth/aaa/aaa%22, %22aaa%22, %22bbb%22));
 %0A%0A%09%7D

enhance basic authentication client