/** * Executes an HTTP GET with the given path. * * @param path Path to be appended to the URI supplied in the construtor * @param params Map of key value pairs * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON get(String path, Map<String, String> params) throws RestException, IOException, URISyntaxException { return get(buildURI(path, params)); }
/** * Creates an authenticated JIRA client. * * @param uri Base URI of the JIRA server * @param creds Credentials to authenticate with */ public JiraClient(String uri, ICredentials creds) { DefaultHttpClient httpclient = new DefaultHttpClient(); restclient = new RestClient(httpclient, creds, URI.create(uri)); if (creds != null) username = creds.getLogonName(); }
/** * Executes an HTTP DELETE with the given path. * * @param path Path to be appended to the URI supplied in the construtor * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON delete(String path) throws RestException, IOException, URISyntaxException { return delete(buildURI(path)); }
/** * Executes an HTTP POST with the given path and payload. * * @param path Path to be appended to the URI supplied in the construtor * @param payload JSON-encoded data to send to the remote service * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path, JSON payload) throws RestException, IOException, URISyntaxException { return post(buildURI(path), payload); }
/** * Executes an HTTP GET with the given path. * * @param path Path to be appended to the URI supplied in the construtor * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON get(String path) throws RestException, IOException, URISyntaxException { return get(path, null); }
/** * Casts a vote in favour of an issue. * * @throws JiraException when the voting fails */ public void vote() throws JiraException { try { restclient.post(getRestUri(key) + "/votes"); } catch (Exception ex) { throw new JiraException("Failed to vote on issue " + key, ex); } }
/** * Executes an HTTP DELETE with the given URI. * * @param uri Full URI of the remote endpoint * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs */ public JSON delete(URI uri) throws RestException, IOException { return request(new HttpDelete(uri)); }
/** * Downloads attachment to byte array * * @return a byte[] * * @throws JiraException when the download fails */ public byte[] download() throws JiraException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); try{ HttpGet get = new HttpGet(content); HttpResponse response = restclient.getHttpClient().execute(get); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); int next = inputStream.read(); while (next > -1) { bos.write(next); next = inputStream.read(); } bos.flush(); } }catch(IOException e){ throw new JiraException(String.format("Failed downloading attachment from %s: %s", this.content, e.getMessage())); } return bos.toByteArray(); }
/** * Executes an HTTP POST with the given path and file payload. * * @param path Full URI of the remote endpoint * @param file java.io.File * * @throws URISyntaxException * @throws IOException * @throws RestException */ public JSON post(String path, File file) throws RestException, IOException, URISyntaxException{ return request(new HttpPost(buildURI(path)), file); }
/** * Removes the current user's vote from the issue. * * @throws JiraException when the voting fails */ public void unvote() throws JiraException { try { restclient.delete(getRestUri(key) + "/votes"); } catch (Exception ex) { throw new JiraException("Failed to unvote on issue " + key, ex); } }
/** * Executes an HTTP PUT with the given path and payload. * * @param path Path to be appended to the URI supplied in the construtor * @param payload JSON-encoded data to send to the remote service * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON put(String path, JSON payload) throws RestException, IOException, URISyntaxException { return put(buildURI(path), payload); }
/** * Executes the update action. * * @throws JiraException when the update fails */ public void execute() throws JiraException { JSONObject fieldmap = new JSONObject(); JSONObject updatemap = new JSONObject(); if (fields.size() == 0 && fieldOpers.size() == 0) throw new JiraException("No fields were given for update"); for (Map.Entry<String, Object> ent : fields.entrySet()) { Object newval = Field.toJson(ent.getKey(), ent.getValue(), editmeta); fieldmap.put(ent.getKey(), newval); } for (Map.Entry<String, List> ent : fieldOpers.entrySet()) { Object newval = Field.toJson(ent.getKey(), ent.getValue(), editmeta); updatemap.put(ent.getKey(), newval); } JSONObject req = new JSONObject(); if (fieldmap.size() > 0) req.put("fields", fieldmap); if (updatemap.size() > 0) req.put("update", updatemap); try { restclient.put(getRestUri(key), req); } catch (Exception ex) { throw new JiraException("Failed to update issue " + key, ex); } }
/** * Build a URI from a path. * * @param path Path to append to the base URI * * @return the full URI * * @throws URISyntaxException when the path is invalid */ public URI buildURI(String path) throws URISyntaxException { return buildURI(path, null); }
RestClient client = RestClient.builder().build(); String url = ... Person person = client.get(url, null, Person.class); //no queryParams
/** * Executes an HTTP POST with the given path and payload. * * @param path Path to be appended to the URI supplied in the construtor * @param payload JSON-encoded data to send to the remote service * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs * @throws URISyntaxException when an error occurred appending the path to the URI */ public JSON post(String path, JSON payload) throws RestException, IOException, URISyntaxException { return post(buildURI(path), payload); }
/** * Casts a vote in favour of an issue. * * @throws JiraException when the voting fails */ public void vote() throws JiraException { try { restclient.post(getRestUri(key) + "/votes"); } catch (Exception ex) { throw new JiraException("Failed to vote on issue " + key, ex); } }
/** * Executes an HTTP GET with the given URI. * * @param uri Full URI of the remote endpoint * * @return JSON-encoded result or null when there's no content returned * * @throws RestException when an HTTP-level error occurs * @throws IOException when an error reading the response occurs */ public JSON get(URI uri) throws RestException, IOException { return request(new HttpGet(uri)); }
/** * Downloads attachment to byte array * * @return a byte[] * * @throws JiraException when the download fails */ public byte[] download() throws JiraException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); try{ HttpGet get = new HttpGet(content); HttpResponse response = restclient.getHttpClient().execute(get); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); int next = inputStream.read(); while (next > -1) { bos.write(next); next = inputStream.read(); } bos.flush(); } }catch(IOException e){ throw new JiraException(String.format("Failed downloading attachment from %s: %s", this.content, e.getMessage())); } return bos.toByteArray(); }
/** * Executes an HTTP POST with the given path and file payload. * * @param uri Full URI of the remote endpoint * @param file java.io.File * * @throws URISyntaxException * @throws IOException * @throws RestException */ public JSON post(String path, File file) throws RestException, IOException, URISyntaxException{ return request(new HttpPost(buildURI(path)), file); }
/** * Deletes this issue link record. * * @throws JiraException when the delete fails */ public void delete() throws JiraException { try { restclient.delete(getBaseUri() + "issueLink/" + id); } catch (Exception ex) { throw new JiraException("Failed to delete issue link " + id, ex); } }