DefaultHttpClient dhc = new DefaultHttpClient();
dhc.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials("demo", "demo"));
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("localhost", 8080, "http"), basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
HttpGet hp =new HttpGet("http://localhost:8080/engine-rest/engine/engine/process-definition");
try{
HttpResponse processResponse = dhc.execute(hp,localcontext);
BufferedReader br = new BufferedReader(
new InputStreamReader((processResponse.getEntity().getContent())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
dhc.getConnectionManager().shutdown();
}
catch(Exception e){
e.printStackTrace();
}
Please provide me solution for this.
regards,
suresh
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.3.3</version> </dependency> CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("demo", "demo"));
AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache authCache.put(new HttpHost("localhost", 8080, "http"), new BasicScheme());
HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); HttpClient client = httpClientBuilder.build();
HttpGet hp = new HttpGet("http://localhost:8080/engine-rest/engine/default/process-definition");
try{ HttpResponse processResponse = client.execute(hp, context); BufferedReader br = new BufferedReader( new InputStreamReader((processResponse.getEntity().getContent())));
String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } } catch(Exception e){ e.printStackTrace(); }regards,
suresh