jenkinsci / java-client-api

A Jenkins API client for Java
MIT License
901 stars 470 forks source link

Getting HTTP HttpResponseException #354

Open ashishprajapat2 opened 6 years ago

ashishprajapat2 commented 6 years ago

Getting HTTP HttpResponseException for every API except getVersion(). Below is the exception i am getting: org.apache.http.client.HttpResponseException: at com.offbytwo.jenkins.client.validator.HttpResponseValidator.validateResponse(HttpResponseValidator.java:11) at com.offbytwo.jenkins.client.JenkinsHttpClient.get(JenkinsHttpClient.java:152) at com.offbytwo.jenkins.JenkinsServer.getJobs(JenkinsServer.java:169) at com.offbytwo.jenkins.JenkinsServer.getJobs(JenkinsServer.java:127) at Jenkins.main(Jenkins.java:70) I am just creating the JenkinsServer Object using the URI and username and password and hitting the methods, But getting the above exception. Seems like it is failing at validating the API. Please Help.

mivola commented 6 years ago

Which version of Jenkins are you using? What is the URI to create the JenkinsServer object? What is the content of the HttpResponseException (statusCode, message)?

ashishprajapat2 commented 6 years ago

Jenkins version: 2.121.2 URI is the Jenkins host address (https://*****.com) Status: 500

mivola commented 6 years ago

Is there any message in the Jenkins log that explains the 500 error?

ashishprajapat2 commented 6 years ago

it was saying "Internal Server Error" . Now i am using Rest APIs directly.

chongye89 commented 5 years ago

even getJobs can trigger this issue... This problem troubling me

at com.offbytwo.jenkins.client.validator.HttpResponseValidator.validateResponse(HttpResponseValidator.java:11) at com.offbytwo.jenkins.client.JenkinsHttpClient.get(JenkinsHttpClient.java:152) at com.offbytwo.jenkins.JenkinsServer.getJobs(JenkinsServer.java:169) at com.offbytwo.jenkins.JenkinsServer.getJobs(JenkinsServer.java:127)

MacroLove commented 5 years ago

got same 500 error

remmeier commented 5 years ago

I do have the same issue with a current Jenkins. Any update on this or information I can provide? I see it directly when fetching the getJobs. The request works fine when doing in the browser, but the browser asks for the login. It is a default jenkins with the admin user/password provided through the environment (the Kubernetes Helm chart from the official repository). If I disable the security, then everyhing works fine.

kumarshorav11 commented 4 years ago

@remmeier @chongye89 I have same issue related to createJob() method with/without crumb. I am not able to figure out what is causing this exception. I am getting 403 forbidden :

Exception in thread "main" org.apache.http.client.HttpResponseException: status code: 403, reason phrase: Forbidden
    at com.offbytwo.jenkins.client.validator.HttpResponseValidator.validateResponse(HttpResponseValidator.java:11)
    at com.offbytwo.jenkins.client.JenkinsHttpClient.post_xml(JenkinsHttpClient.java:375)
    at com.offbytwo.jenkins.JenkinsServer.createJob(JenkinsServer.java:389)
    at com.hcl.OffByTwoJenkins.main(OffByTwoJenkins.java:46)

I am using below code to create job:

HttpClientBuilder builder = HttpClientBuilder.create();
        JenkinsHttpClient client = new JenkinsHttpClient(uri, addAuthentication(builder, uri, userName, passwordOrToken));
        JenkinsServer jenkins = new JenkinsServer(client);
        String sourceXML = readFile("src/main/resources/config.xml");
        System.out.println(String.format("Installed Jenkins Version >> %s", jenkins.getVersion().getLiteralVersion()));
        jenkins.createJob(null,"test-nov1", sourceXML,false);

nothing worked for me so far. If any one of you are able to resolve, please help me too to overcome this issue. However @remmeier said, if I select option "any user can do any thing" in /configSecurity then it is working fine. I want when "Any logged in user can do any thing" option is selected in jenkins security and this should work.

vikas981 commented 3 years ago

org.apache.http.client.HttpResponseException: at com.offbytwo.jenkins.client.validator.HttpResponseValidator.validateResponse(HttpResponseValidator.java:11) at com.offbytwo.jenkins.client.JenkinsHttpClient.post(JenkinsHttpClient.java:261) at com.offbytwo.jenkins.client.JenkinsHttpClient.post(JenkinsHttpClient.java:221) at com.offbytwo.jenkins.model.Job.build(Job.java:88)