@Override public NameValuePair apply(Tuple<String, String> p) { return param(p); } };
public static HttpPost post(NameValuePair... formParams) { final HttpPost post = new HttpPost(); setFormParams(post, formParams); return post; }
@Override public String getMountPoint() { for (HttpResponse r : option(getResponse(get("mountpoint"), HttpStatus.SC_OK))) { try { return EntityUtils.toString(r.getEntity()); } catch (IOException e) { logger.error("Cannot contact remote service", e); return chuck(e); } } throw new RuntimeException("Cannot contact remote service"); } }
/** * Return the content of the response as a string if its status code equals one of the given statuses. Throw an * exception on an unexpected status. * <p> * Function composition of {@link #getContentFn} and {@link #expect(int...)}. */ public static Function<HttpResponse, String> getContentOn(final int... status) { return getContentFn.o(expect(status)); }
private void waitForResource(final URI uri, final int expectedStatus, final String errorMsg) throws IOException { if (waitForResourceFlag) { HttpUtil.waitForResource(trustedHttpClient, uri, expectedStatus, TIMEOUT, INTERVAL) .fold(Misc.<Exception, Void> chuck(), new Effect.X<Integer>() { @Override public void xrun(Integer status) throws Exception { if (ne(status, expectedStatus)) { final String msg = format(errorMsg, uri.toString()); logger.warn(msg); throw new IOException(msg); } } }); } }
public static String getContentOn(final RequestRunner<String> runner, final int... status) { final Either<Exception, String> res = runner.run(getContentOn(status)); if (res.isRight()) { return res.right().value(); } else { return chuck(res.left().value()); } }
@Override public boolean hasRepo(String id) { for (HttpResponse r : option(getResponse(get(UrlSupport.concat("hasrepo", id)), HttpStatus.SC_OK))) { try { return Boolean.parseBoolean(EntityUtils.toString(r.getEntity())); } catch (IOException e) { logger.error("Cannot contact remote service", e); chuck(e); } } return false; }
public static HttpPost post(String uri, NameValuePair... formParams) { final HttpPost post = new HttpPost(uri); setFormParams(post, formParams); return post; }
public static HttpPost post(String uri, List<NameValuePair> formParams) { final HttpPost post = new HttpPost(uri); setFormParams(post, Collections.toArray(NameValuePair.class, formParams)); return post; }