/** * 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)); }
private JSON request(HttpEntityEnclosingRequestBase req, JSON payload) throws RestException, IOException { return request(req, payload != null ? payload.toString() : null); }
/** * 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)); }
/** * Executes an HTTP PUT with the given URI and payload. * * @param uri Full URI of the remote endpoint * @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 */ public JSON put(URI uri, JSON payload) throws RestException, IOException { return request(new HttpPut(uri), payload); }
/** * 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)); }
/** * Executes an HTTP PUT with the given URI and payload. * * @param uri Full URI of the remote endpoint * @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 */ public JSON put(URI uri, JSON payload) throws RestException, IOException { return request(new HttpPut(uri), payload); }
private JSON request(HttpEntityEnclosingRequestBase req, JSON payload) throws RestException, IOException { return request(req, payload != null ? payload.toString() : null); }
/** * 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)); }
/** * Executes an HTTP POST with the given URI and payload. * * @param uri Full URI of the remote endpoint * @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 */ public JSON post(URI uri, JSON payload) throws RestException, IOException { return request(new HttpPost(uri), payload); }
/** * Executes an HTTP POST with the given URI and payload. * * @param uri Full URI of the remote endpoint * @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 */ public JSON post(URI uri, JSON payload) throws RestException, IOException { return request(new HttpPost(uri), payload); }
/** * 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); }
/** * 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); }
/** * Executes an HTTP POST with the given path and file payloads. * * @param path Full URI of the remote endpoint * @param attachments the name of the attachment * * @throws URISyntaxException * @throws IOException * @throws RestException */ public JSON post(String path, Issue.NewAttachment... attachments) throws RestException, IOException, URISyntaxException { return request(new HttpPost(buildURI(path)), attachments); }
/** * Executes an HTTP POST with the given URI and payload. * * At least one JIRA REST endpoint expects malformed JSON. The payload * argument is quoted and sent to the server with the application/json * Content-Type header. You should not use this function when proper JSON * is expected. * * @see https://jira.atlassian.com/browse/JRA-29304 * * @param uri Full URI of the remote endpoint * @param payload Raw string 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 */ public JSON post(URI uri, String payload) throws RestException, IOException { String quoted = null; if(payload != null && !payload.equals(new JSONObject())){ quoted = String.format("\"%s\"", payload); } return request(new HttpPost(uri), quoted); }
/** * Executes an HTTP POST with the given URI and payload. * * At least one JIRA REST endpoint expects malformed JSON. The payload * argument is quoted and sent to the server with the application/json * Content-Type header. You should not use this function when proper JSON * is expected. * * @see https://jira.atlassian.com/browse/JRA-29304 * * @param uri Full URI of the remote endpoint * @param payload Raw string 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 */ public JSON post(URI uri, String payload) throws RestException, IOException { String quoted = null; if(payload != null && !payload.equals(new JSONObject())){ quoted = String.format("\"%s\"", payload); } return request(new HttpPost(uri), quoted); }
private JSON request(HttpEntityEnclosingRequestBase req, String payload) throws RestException, IOException { if (payload != null) { StringEntity ent = null; try { ent = new StringEntity(payload, "UTF-8"); ent.setContentType("application/json"); } catch (UnsupportedEncodingException ex) { /* utf-8 should always be supported... */ } req.addHeader("Content-Type", "application/json"); req.setEntity(ent); } return request(req); }
private JSON request(HttpEntityEnclosingRequestBase req, String payload) throws RestException, IOException { if (payload != null) { StringEntity ent = null; try { ent = new StringEntity(payload, "UTF-8"); ent.setContentType("application/json"); } catch (UnsupportedEncodingException ex) { /* utf-8 should always be supported... */ } req.addHeader("Content-Type", "application/json"); req.setEntity(ent); } return request(req); }
private JSON request(HttpEntityEnclosingRequestBase req, File file) throws RestException, IOException { if (file != null) { File fileUpload = file; req.setHeader("X-Atlassian-Token", "nocheck"); MultipartEntity ent = new MultipartEntity(); ent.addPart("file", new FileBody(fileUpload)); req.setEntity(ent); } return request(req); }
private JSON request(HttpEntityEnclosingRequestBase req, File file) throws RestException, IOException { if (file != null) { File fileUpload = file; req.setHeader("X-Atlassian-Token","nocheck"); MultipartEntity ent = new MultipartEntity(); ent.addPart("file", new FileBody(fileUpload)); req.setEntity(ent); } return request(req); }
private JSON request(HttpEntityEnclosingRequestBase req, Issue.NewAttachment... attachments) throws RestException, IOException { if (attachments != null) { req.setHeader("X-Atlassian-Token", "nocheck"); MultipartEntity ent = new MultipartEntity(); for(Issue.NewAttachment attachment : attachments) { String filename = attachment.getFilename(); Object content = attachment.getContent(); if (content instanceof byte[]) { ent.addPart("file", new ByteArrayBody((byte[]) content, filename)); } else if (content instanceof InputStream) { ent.addPart("file", new InputStreamBody((InputStream) content, filename)); } else if (content instanceof File) { ent.addPart("file", new FileBody((File) content, filename)); } else if (content == null) { throw new IllegalArgumentException("Missing content for the file " + filename); } else { throw new IllegalArgumentException( "Expected file type byte[], java.io.InputStream or java.io.File but provided " + content.getClass().getName() + " for the file " + filename); } } req.setEntity(ent); } return request(req); }