Apply Google-format Change-Id: Ie63debb4cba46c937eef5a87ed5e5752f163e325
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/jira/restapi/JiraRestApi.java b/src/main/java/com/googlesource/gerrit/plugins/its/jira/restapi/JiraRestApi.java index 581f40b..caafc7a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/its/jira/restapi/JiraRestApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/its/jira/restapi/JiraRestApi.java
@@ -15,11 +15,6 @@ package com.googlesource.gerrit.plugins.its.jira.restapi; import com.google.gson.Gson; - -import java.util.Base64; -import org.apache.commons.lang.ArrayUtils; -import org.eclipse.jgit.util.HttpSupport; - import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -27,10 +22,11 @@ import java.net.Proxy; import java.net.ProxySelector; import java.net.URL; +import java.util.Base64; +import org.apache.commons.lang.ArrayUtils; +import org.eclipse.jgit.util.HttpSupport; -/** - * Jira Rest Client. - */ +/** Jira Rest Client. */ public class JiraRestApi<T> { private static final String BASE_PREFIX = "/rest/api/2"; private final URL baseUrl; @@ -43,12 +39,13 @@ private int responseCode; /** + * Create a new Jira REST API client + * * @param url jira url * @param user username of the jira user * @param pass password of the jira user */ - JiraRestApi(URL url, String user, String pass, Class<T> classOfT, - String classPrefix) { + JiraRestApi(URL url, String user, String pass, Class<T> classOfT, String classPrefix) { String auth = user + ":" + pass; this.auth = new String(Base64.getEncoder().encodeToString(auth.getBytes())); this.baseUrl = url; @@ -62,16 +59,13 @@ } /** - * Do a simple GET request. Object of type 'T' is returned containing the - * parsed JSON data + * Do a simple GET request. Object of type 'T' is returned containing the parsed JSON data * * @param passCode HTTP response code required to mark this GET as success - * @param failCodes HTTP response codes allowed and not fail on unexcepted - * response + * @param failCodes HTTP response codes allowed and not fail on unexcepted response * @throws IOException generated if unexpected failCode is returned */ - public T doGet(String spec, int passCode, int[] failCodes) - throws IOException { + public T doGet(String spec, int passCode, int[] failCodes) throws IOException { HttpURLConnection conn = prepHttpConnection(spec, false); try { if (validateResponse(conn, passCode, failCodes)) { @@ -87,11 +81,8 @@ return doGet(spec, passCode, null); } - /** - * Do a simple POST request. - */ - public boolean doPost(String spec, String jsonInput, int passCode) - throws IOException { + /** Do a simple POST request. */ + public boolean doPost(String spec, String jsonInput, int passCode) throws IOException { HttpURLConnection conn = prepHttpConnection(spec, true); try { writePostData(jsonInput, conn); @@ -101,8 +92,8 @@ } } - private HttpURLConnection prepHttpConnection(String spec, - boolean isPostRequest) throws IOException { + private HttpURLConnection prepHttpConnection(String spec, boolean isPostRequest) + throws IOException { URL url = new URL(baseUrl, BASE_PREFIX + classPrefix + spec); ProxySelector proxySelector = ProxySelector.getDefault(); Proxy proxy = HttpSupport.proxyFor(proxySelector, url); @@ -118,11 +109,8 @@ return conn; } - /** - * Write the Read the returned data from the HTTP connection. - */ - private void writePostData(String postData, HttpURLConnection conn) - throws IOException { + /** Write the Read the returned data from the HTTP connection. */ + private void writePostData(String postData, HttpURLConnection conn) throws IOException { if (postData != null) { try (OutputStream os = conn.getOutputStream()) { os.write(postData.getBytes()); @@ -131,9 +119,7 @@ } } - /** - * Read the returned data from the HTTP connection. - */ + /** Read the returned data from the HTTP connection. */ private void readIncomingData(HttpURLConnection conn) throws IOException { try (InputStreamReader isr = new InputStreamReader(conn.getInputStream())) { data = gson.fromJson(isr, classOfT); @@ -141,19 +127,17 @@ } /** - * Checks if the connection returned one of the provides pass or fail Codes. - * If not, an IOException exception is thrown. If it was part of the list, - * then the actual response code is returned. returns true if valid response - * is returned, otherwise false + * Checks if the connection returned one of the provides pass or fail Codes. If not, an + * IOException exception is thrown. If it was part of the list, then the actual response code is + * returned. returns true if valid response is returned, otherwise false */ - private boolean validateResponse(HttpURLConnection conn, int passCode, - int[] failCodes) throws IOException { + private boolean validateResponse(HttpURLConnection conn, int passCode, int[] failCodes) + throws IOException { responseCode = conn.getResponseCode(); if (responseCode == passCode) { return true; } - if ((failCodes == null) - || (!ArrayUtils.contains(failCodes, responseCode))) { + if ((failCodes == null) || (!ArrayUtils.contains(failCodes, responseCode))) { throw new IOException("Request failed"); } return false;