Hello All,

 I am using Apache HTTPClient to create remote job in Jenkins. My Jenkins 
is running behind Apache.

I get the error message : "HTTP/4.1 401 Authorization Required" when I run 
the below code. I could login into Jenkins and create job via browser. But 
when I try to create job via Apache HTTP Client, it is failing. Please find 
my code here :

String input = getConfigJobXML();

CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(postUrl);

httpPost.setEntity(new 
StringEntity(input,ContentType.APPLICATION_ATOM_XML));
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials(username, password);
httpPost.addHeader(new BasicScheme().authenticate(creds, httpPost, null));

CloseableHttpResponse response = client.execute(httpPost);
System.out.println(response.getStatusLine());
Header[] allHeaders = response.getAllHeaders();

for (Header iterable_element : allHeaders) {
System.out.println(iterable_element);
}
System.out.println(response.getStatusLine().getStatusCode());
client.close();

My output is :

HTTP/1.1 401 Authorization Required
Date: Mon, 06 Apr 2015 09:17:56 GMT
WWW-Authenticate: NTLM
Content-Length: 401
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
401


I tried the code at below site. But, remote job creation failed.

https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients

Could you please help me?

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/fa201ee8-de63-4c2a-bebf-54f359c5c357%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to