public class JenkinsHttpClient extends Object
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,
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) |
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() |
protected org.apache.http.protocol.HttpContext |
getLocalContext() |
<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.
|
void |
post_form_json(String path,
Map<String,Object> data,
boolean crumbFlag)
Perform a POST request using form url encoding.
|
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.
|
void |
post_multipart_form_json(String path,
Map<String,Object> data,
boolean crumbFlag)
Perform a POST request using multipart-form.
|
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) |
void |
post(String path)
Perform POST request that takes no parameters and returns no response
|
void |
post(String path,
boolean crumbFlag) |
<R extends BaseModel,D> |
post(String path,
D data,
Class<R> cls) |
<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
|
protected void |
setLocalContext(org.apache.http.protocol.HttpContext localContext) |
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 <T extends BaseModel> T get(String path, Class<T> cls) throws IOException
T
- 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
path
- path to request, can be relative or absoluteIOException
- in case of an error.public <T extends BaseModel> T getQuietly(String path, Class<T> cls)
T
- type of the responsepath
- path to request, can be relative or absolutecls
- class of the responsepublic InputStream getFile(URI path) throws IOException
path
- 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
IOException
public <R extends BaseModel,D> R post(String path, D data, Class<R> cls, boolean crumbFlag) throws IOException
R
- 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 void post_form(String path, Map<String,String> data, boolean crumbFlag) throws IOException
path
- 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
path
- path to request, can be relative or absolutedata
- data to postIOException
- the HttpResponseExceptionpublic void post_form_json(String path, Map<String,Object> data, boolean crumbFlag) throws IOException
path
- path to request, can be relative or absolutedata
- data to postcrumbFlag
- true / false.IOException
- in case of an error.public void post_multipart_form_json(String path, Map<String,Object> data, boolean crumbFlag) throws IOException
path
- 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
path
- 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
IOException
public String post_text(String path, String textData, boolean crumbFlag) throws IOException
path
- 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
path
- The path.textData
- The data.contentType
- ContentType
crumbFlag
- true or false.IOException
- in case of an error.public void post(String path) throws IOException
path
- path to requestIOException
- in case of an error.public void post(String path, boolean crumbFlag) throws IOException
IOException
public String getJenkinsVersion()
protected static org.apache.http.impl.client.HttpClientBuilder addAuthentication(org.apache.http.impl.client.HttpClientBuilder builder, URI uri, String username, String password)
protected org.apache.http.protocol.HttpContext getLocalContext()
protected void setLocalContext(org.apache.http.protocol.HttpContext localContext)
Copyright © 2017 JBoss by Red Hat. All rights reserved.