Skip to content

Commit 86265e5

Browse files
committed
Merge pull request jenkinsci#116 from hamaron/hotfix/crumbissuer
jenkinsci#39: Don't propagate IOException when GET for /CrumbIssuer fails.
2 parents 6105dcd + ee80670 commit 86265e5

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ public String get(String path) throws IOException {
171171
}
172172
}
173173

174+
/**
175+
* Perform a GET request and parse the response to the given class,
176+
* logging any IOException that is thrown rather than propagating it.
177+
*
178+
* @param path path to request, can be relative or absolute
179+
* @param cls class of the response
180+
* @param <T> type of the response
181+
* @return an instance of the supplied class
182+
*/
183+
public <T extends BaseModel> T getQuietly(String path, Class<T> cls) {
184+
T value;
185+
try {
186+
value = get(path, cls);
187+
return value;
188+
} catch (IOException e) {
189+
e.printStackTrace();
190+
return null;
191+
}
192+
}
193+
174194
/**
175195
* Perform a GET request and return the response as InputStream
176196
*
@@ -203,7 +223,7 @@ public <R extends BaseModel, D> R post(String path, D data, Class<R> cls) throws
203223
public <R extends BaseModel, D> R post(String path, D data, Class<R> cls, boolean crumbFlag) throws IOException {
204224
HttpPost request = new HttpPost(api(path));
205225
if (crumbFlag == true) {
206-
Crumb crumb = get("/crumbIssuer", Crumb.class);
226+
Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
207227
if (crumb != null) {
208228
request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
209229
}
@@ -303,7 +323,7 @@ public String post_xml(String path, String xml_data) throws IOException {
303323
public String post_xml(String path, String xml_data, boolean crumbFlag) throws IOException {
304324
HttpPost request = new HttpPost(api(path));
305325
if (crumbFlag == true) {
306-
Crumb crumb = get("/crumbIssuer", Crumb.class);
326+
Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
307327
if (crumb != null) {
308328
request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
309329
}

0 commit comments

Comments
 (0)