Tabnine Logo
JenkinsHttpClient
Code IndexAdd Tabnine to your IDE (free)

How to use
JenkinsHttpClient
in
com.offbytwo.jenkins.client

Best Java code snippets using com.offbytwo.jenkins.client.JenkinsHttpClient (Showing top 20 results out of 315)

origin: Verigreen/verigreen

/**
 * Create a new Jenkins server reference given the address and credentials
 *
 * @param serverUri address of jenkins server (ex. http://localhost:8080/jenkins)
 * @param username username to use when connecting
 * @param passwordOrToken password (not recommended) or token (recommended)
 */
public JenkinsServer(URI serverUri, String username, String passwordOrToken) {
  this(new JenkinsHttpClient(serverUri, username, passwordOrToken));
}
origin: Verigreen/verigreen

public JobWithDetails details() throws IOException {
  return client.get(url, JobWithDetails.class);
}
origin: com.offbytwo.jenkins/jenkins-client

/**
 * {@inheritDoc}
 */
@Override
public void post(String path) throws IOException {
  post(path, null, null, null, false);
}
origin: com.offbytwo.jenkins/jenkins-client

/**
 * {@inheritDoc}
 */
@Override
public String post_text(String path, String textData, ContentType contentType, boolean crumbFlag)
    throws IOException {
  HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path));
  if (crumbFlag == true) {
    Crumb crumb = get("/crumbIssuer", Crumb.class);
    if (crumb != null) {
      request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
    }
  }
  if (textData != null) {
    request.setEntity(new StringEntity(textData, contentType));
  }
  HttpResponse response = client.execute(request, localContext);
  jenkinsVersion = ResponseUtils.getJenkinsVersion(response);
  try {
    httpResponseValidator.validateResponse(response);
    return IOUtils.toString(response.getEntity().getContent());
  } finally {
    EntityUtils.consume(response.getEntity());
    releaseConnection(request);
  }
}
origin: com.offbytwo.jenkins/jenkins-client

/**
 * {@inheritDoc}
 */
@Override
public String post_xml(String path, String xml_data) throws IOException {
  return post_xml(path, xml_data, true);
}
origin: com.offbytwo.jenkins/jenkins-client

HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path));
if (crumbFlag == true) {
  Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
  if (crumb != null) {
    request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
      responseObject = (R) location;
    } else {
      responseObject = objectFromResponse(cls, response);
  releaseConnection(request);
origin: Verigreen/verigreen

/**
 * Perform a GET request and parse the response to the given class
 * 
 * @param path
 *            path to request, can be relative or absolute
 * @param cls
 *            class of the response
 * @param <T>
 *            type of the response
 * @return an instance of the supplied class
 * @throws IOException
 *             , HttpResponseException
 */
public <T extends BaseModel> T get(String path, Class<T> cls) throws IOException,
    HttpResponseException {
  HttpResponse response = client.execute(new HttpGet(api(path)), localContext);
  int status = response.getStatusLine().getStatusCode();
  if (status < 200 || status >= 300) {
    throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase());
  }
  try {
    return objectFromResponse(cls, response);
  } finally {
    EntityUtils.consume(response.getEntity());
  }
}

origin: com.offbytwo.jenkins/jenkins-client

/**
 * {@inheritDoc}
 */
@Override
public String post_xml(String path, String xml_data, boolean crumbFlag) throws IOException {
  HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path));
  if (crumbFlag == true) {
    Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
    if (crumb != null) {
      request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
    }
  }
  if (xml_data != null) {
    request.setEntity(new StringEntity(xml_data, ContentType.create("text/xml", "utf-8")));
  }
  HttpResponse response = client.execute(request, localContext);
  jenkinsVersion = ResponseUtils.getJenkinsVersion(response);
  try {
    httpResponseValidator.validateResponse(response);
    return IOUtils.toString(response.getEntity().getContent());
  } finally {
    EntityUtils.consume(response.getEntity());
    releaseConnection(request);
  }
}
origin: com.offbytwo.jenkins/jenkins-client

/**
 * Create an unauthenticated Jenkins HTTP client
 *
 * @param uri Location of the jenkins server (ex. http://localhost:8080)
 * @param client Configured CloseableHttpClient to be used
 */
public JenkinsHttpClient(URI uri, CloseableHttpClient client) {
  this.context = uri.getPath();
  if (!context.endsWith("/")) {
    context += "/";
  }
  this.uri = uri;
  this.mapper = getDefaultMapper();
  this.client = client;
  this.httpResponseValidator = new HttpResponseValidator();
  // this.contentExtractor = new HttpResponseContentExtractor();
  this.jenkinsVersion = EMPTY_VERSION;
  LOGGER.debug("uri={}", uri.toString());
}
origin: Verigreen/verigreen

/**
 * Perform a GET request and parse the response and return a simple string of the content
 * 
 * @param path
 *            path to request, can be relative or absolute
 * @return the entity text
 * @throws IOException
 *             , HttpResponseException
 */
public String get(String path) throws IOException, HttpResponseException {
  HttpResponse response = client.execute(new HttpGet(api(path)), localContext);
  int status = response.getStatusLine().getStatusCode();
  if (status < 200 || status >= 300) {
    throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase());
  }
  Scanner s = new Scanner(response.getEntity().getContent(), CHARSET_UTF_8);
  s.useDelimiter("\\z");
  StringBuffer sb = new StringBuffer();
  while (s.hasNext()) {
    sb.append(s.next());
  }
  return sb.toString();
}

origin: com.offbytwo.jenkins/jenkins-client

/**
 * Create an authenticated Jenkins HTTP client
 *
 * @param uri Location of the jenkins server (ex. http://localhost:8080)
 * @param builder Configured HttpClientBuilder to be used
 * @param username Username to use when connecting
 * @param password Password or auth token to use when connecting
 */
public JenkinsHttpClient(URI uri, HttpClientBuilder builder, String username, String password) {
  this(uri, addAuthentication(builder, uri, username, password));
  if (isNotBlank(username)) {
    localContext = new BasicHttpContext();
    localContext.setAttribute("preemptive-auth", new BasicScheme());
  }
}
origin: Verigreen/verigreen

  public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException {
    //We can't just put the artifact's relative path at the end of the url string,
    //as there could be characters that need to be escaped.
    URI uri = new URI(getUrl());
    String artifactPath = uri.getPath() + "artifact/" + a.getRelativePath();
    URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), artifactPath, "", "");
    return client.getFile(artifactUri);
  }
}
origin: com.offbytwo.jenkins/jenkins-client

  Crumb crumb = get("/crumbIssuer", Crumb.class);
  if (crumb != null) {
    request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
} finally {
  EntityUtils.consume(response.getEntity());
  releaseConnection(request);
origin: Verigreen/verigreen

/**
 * Update the xml description of an existing job
 *
 * @return the new job object
 * @throws IOException
 */
public void updateJob(String jobName, String jobXml) throws IOException {
  client.post_xml("/job/" + encode(jobName) + "/config.xml", jobXml);
}
origin: Verigreen/verigreen

HttpPost request = new HttpPost(api(path));
if (data != null) {
  StringEntity stringEntity =
    return objectFromResponse(cls, response);
  } else {
    return null;
origin: Verigreen/verigreen

/**
 * Create an unauthenticated Jenkins HTTP client
 * 
 * @param uri
 *            Location of the jenkins server (ex. http://localhost:8080)
 */
public JenkinsHttpClient(URI uri) {
  this.context = uri.getPath();
  if (!context.endsWith("/")) {
    context += "/";
  }
  this.uri = uri;
  this.mapper = getDefaultMapper();
  HttpParams httpParameters = new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
  HttpConnectionParams.setSoTimeout(httpParameters, 10000);
  this.client = new DefaultHttpClient(new PoolingClientConnectionManager(), httpParameters);
}

origin: Verigreen/verigreen

HttpPost request = new HttpPost(api(path));
if (xml_data != null) {
  request.setEntity(new StringEntity(xml_data, ContentType.APPLICATION_XML));
origin: Verigreen/verigreen

public BuildWithDetails details() throws IOException {
  return client.get(url, BuildWithDetails.class);
}

origin: Verigreen/verigreen

/**
 * Create a new Jenkins server reference given only the server address
 *
 * @param serverUri address of jenkins server (ex. http://localhost:8080/jenkins)
 */
public JenkinsServer(URI serverUri) {
  this(new JenkinsHttpClient(serverUri));
}
origin: com.offbytwo.jenkins/jenkins-client

/**
 * {@inheritDoc}
 */
@Override
public <R extends BaseModel, D> R post(String path, D data, Class<R> cls) throws IOException {
  return post(path, data, cls, null, true);
}
com.offbytwo.jenkins.clientJenkinsHttpClient

Most used methods

  • <init>
    Create an authenticated Jenkins HTTP client
  • get
  • post
  • post_xml
  • addAuthentication
    Add authentication to supplied builder.
  • api
  • getDefaultMapper
  • getFile
  • getQuietly
  • objectFromResponse
  • post_text
  • releaseConnection
  • post_text,
  • releaseConnection,
  • urlJoin

Popular in Java

  • Updating database using SQL prepared statement
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • getApplicationContext (Context)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now