public class JenkinsHttpClient extends Object implements JenkinsHttpConnection
| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY_VERSION |
| Constructor and Description |
|---|
JenkinsHttpClient(URI uri)
Create an unauthenticated Jenkins HTTP client
|
JenkinsHttpClient(URI uri,
org.apache.http.impl.client.CloseableHttpClient client)
Create an unauthenticated Jenkins HTTP client
|
JenkinsHttpClient(URI uri,
org.apache.http.impl.client.HttpClientBuilder builder)
Create an unauthenticated Jenkins HTTP client
|
JenkinsHttpClient(URI uri,
org.apache.http.impl.client.HttpClientBuilder builder,
String username,
String password)
Create an authenticated Jenkins HTTP client
|
JenkinsHttpClient(URI uri,
String username,
String password)
Create an authenticated Jenkins HTTP client
|
| Modifier and Type | Method and Description |
|---|---|
protected static org.apache.http.impl.client.HttpClientBuilder |
addAuthentication(org.apache.http.impl.client.HttpClientBuilder builder,
URI uri,
String username,
String password)
Add authentication to supplied builder.
|
void |
close()
Closes underlying resources.
|
String |
get(String path)
Perform a GET request and parse the response and return a simple string
of the content
|
<T extends BaseModel> |
get(String path,
Class<T> cls)
Perform a GET request and parse the response to the given class
|
InputStream |
getFile(URI path)
Perform a GET request and return the response as InputStream
|
String |
getJenkinsVersion()
Get the Jenkins server version.
|
protected org.apache.http.protocol.HttpContext |
getLocalContext()
Get the local context.
|
<T extends BaseModel> |
getQuietly(String path,
Class<T> cls)
Perform a GET request and parse the response to the given class, logging
any IOException that is thrown rather than propagating it.
|
boolean |
isJenkinsVersionSet()
Check to see if the Jenkins version has been set to something different
than the initialisation value from the constructor.
|
org.apache.http.HttpResponse |
post_form_with_result(String path,
List<org.apache.http.NameValuePair> data,
boolean crumbFlag)
Perform a POST request using form url encoding and return HttpResponse
object This method is not performing validation and can be used for more
generic queries to jenkins.
|
void |
post_form(String path,
Map<String,String> data,
boolean crumbFlag)
Perform a POST request using form url encoding.
|
String |
post_text(String path,
String textData,
boolean crumbFlag)
Post a text entity to the given URL using the default content type
|
String |
post_text(String path,
String textData,
org.apache.http.entity.ContentType contentType,
boolean crumbFlag)
Post a text entity to the given URL with the given content type
|
String |
post_xml(String path,
String xml_data)
Perform a POST request of XML (instead of using json mapper) and return a
string rendering of the response entity.
|
String |
post_xml(String path,
String xml_data,
boolean crumbFlag)
Perform a POST request of XML (instead of using json mapper) and return a
string rendering of the response entity.
|
void |
post(String path)
Perform POST request that takes no parameters and returns no response
|
void |
post(String path,
boolean crumbFlag)
Perform POST request that takes no parameters and returns no response
|
<R extends BaseModel,D> |
post(String path,
D data,
Class<R> cls)
Perform a POST request and parse the response to the given class
|
<R extends BaseModel,D> |
post(String path,
D data,
Class<R> cls,
boolean crumbFlag)
Perform a POST request and parse the response to the given class
|
<R extends BaseModel,D> |
post(String path,
D data,
Class<R> cls,
Map<String,File> fileParams,
boolean crumbFlag)
Perform a POST request and parse the response to the given class
|
protected void |
setLocalContext(org.apache.http.protocol.HttpContext localContext)
Set the local context.
|
public static final String EMPTY_VERSION
public JenkinsHttpClient(URI uri, org.apache.http.impl.client.CloseableHttpClient client)
uri - Location of the jenkins server (ex. http://localhost:8080)client - Configured CloseableHttpClient to be usedpublic JenkinsHttpClient(URI uri, org.apache.http.impl.client.HttpClientBuilder builder)
uri - Location of the jenkins server (ex. http://localhost:8080)builder - Configured HttpClientBuilder to be usedpublic JenkinsHttpClient(URI uri)
uri - Location of the jenkins server (ex. http://localhost:8080)public JenkinsHttpClient(URI uri, String username, String password)
uri - Location of the jenkins server (ex. http://localhost:8080)username - Username to use when connectingpassword - Password or auth token to use when connectingpublic JenkinsHttpClient(URI uri, org.apache.http.impl.client.HttpClientBuilder builder, String username, String password)
uri - Location of the jenkins server (ex. http://localhost:8080)builder - Configured HttpClientBuilder to be usedusername - Username to use when connectingpassword - Password or auth token to use when connectingpublic <T extends BaseModel> T get(String path, Class<T> cls) throws IOException
get in interface JenkinsHttpConnectionT - type of the responsepath - path to request, can be relative or absolutecls - class of the responseIOException - in case of an error.public String get(String path) throws IOException
get in interface JenkinsHttpConnectionpath - path to request, can be relative or absoluteIOException - in case of an error.public <T extends BaseModel> T getQuietly(String path, Class<T> cls)
getQuietly in interface JenkinsHttpConnectionT - type of the responsepath - path to request, can be relative or absolutecls - class of the responsepublic InputStream getFile(URI path) throws IOException
getFile in interface JenkinsHttpConnectionpath - path to request, can be relative or absoluteIOException - in case of an error.public <R extends BaseModel,D> R post(String path, D data, Class<R> cls) throws IOException
post in interface JenkinsHttpConnectionR - type of the responseD - type of the datapath - path to request, can be relative or absolutedata - data to postcls - class of the responseIOException - in case of an error.public <R extends BaseModel,D> R post(String path, D data, Class<R> cls, boolean crumbFlag) throws IOException
post in interface JenkinsHttpConnectionR - type of the responseD - type of the datapath - path to request, can be relative or absolutedata - data to postcls - class of the responsecrumbFlag - true / false.IOException - in case of an error.public <R extends BaseModel,D> R post(String path, D data, Class<R> cls, Map<String,File> fileParams, boolean crumbFlag) throws IOException
post in interface JenkinsHttpConnectionR - type of the responseD - type of the datapath - path to request, can be relative or absolutedata - data to postcls - class of the responsefileParams - file parameterscrumbFlag - true / false.IOException - in case of an error.public void post_form(String path, Map<String,String> data, boolean crumbFlag) throws IOException
post_form in interface JenkinsHttpConnectionpath - path to request, can be relative or absolutedata - data to postcrumbFlag - true / false.IOException - in case of an error.public org.apache.http.HttpResponse post_form_with_result(String path, List<org.apache.http.NameValuePair> data, boolean crumbFlag) throws IOException
post_form_with_result in interface JenkinsHttpConnectionpath - path to request, can be relative or absolutedata - data to postcrumbFlag - true / false.IOException - in case of an error.public String post_xml(String path, String xml_data) throws IOException
post_xml in interface JenkinsHttpConnectionpath - path to request, can be relative or absolutexml_data - data data to postIOException - in case of an error.public String post_xml(String path, String xml_data, boolean crumbFlag) throws IOException
post_xml in interface JenkinsHttpConnectionpath - path to request, can be relative or absolutexml_data - data data to postcrumbFlag - true or false.IOException - in case of an error.public String post_text(String path, String textData, boolean crumbFlag) throws IOException
post_text in interface JenkinsHttpConnectionpath - The path.textData - data.crumbFlag - true/false.IOException - in case of an error.public String post_text(String path, String textData, org.apache.http.entity.ContentType contentType, boolean crumbFlag) throws IOException
post_text in interface JenkinsHttpConnectionpath - The path.textData - The data.contentType - ContentTypecrumbFlag - true or false.IOException - in case of an error.public void post(String path) throws IOException
post in interface JenkinsHttpConnectionpath - path to requestIOException - in case of an error.public void post(String path, boolean crumbFlag) throws IOException
post in interface JenkinsHttpConnectionpath - path to requestcrumbFlag - true / false.IOException - in case of an error.public String getJenkinsVersion()
getJenkinsVersion in interface JenkinsHttpConnectionpublic boolean isJenkinsVersionSet()
isJenkinsVersionSet in interface JenkinsHttpConnectionpublic void close()
close in interface JenkinsHttpConnectionclose in interface Closeableclose in interface AutoCloseableprotected static org.apache.http.impl.client.HttpClientBuilder addAuthentication(org.apache.http.impl.client.HttpClientBuilder builder,
URI uri,
String username,
String password)
builder - the builder to configureuri - the server URIusername - the usernamepassword - the passwordprotected org.apache.http.protocol.HttpContext getLocalContext()
protected void setLocalContext(org.apache.http.protocol.HttpContext localContext)
localContext - the contextCopyright © 2018. All rights reserved.