本文整理了Java中io.advantageous.boon.core.Exceptions.tryIt()
方法的一些代码示例,展示了Exceptions.tryIt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exceptions.tryIt()
方法的具体详情如下:
包路径:io.advantageous.boon.core.Exceptions
类名称:Exceptions
方法名:tryIt
暂无
代码示例来源:origin: advantageous/qbit
public static Response jsonRestCall(
final String url
) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, null, APPLICATION_JSON, null);
return extractResponseObject(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static Response postBodyTextWithContentTypeReturnResponse(final String url,
final String contentType,
final String body) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, null, contentType, null, body);
return extractResponseObject(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static Response putBodyTextWithContentTypeReturnResponse(final String url,
final String contentType,
final String body) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
connection = doPut(url, null, contentType, null, body);
return extractResponseObject(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String putBodyTextWithContentType(
final String url,
final String contentType,
final String body) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, null, contentType, null, body);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String postForm(final String url, final Map<String, ?> headers,
final Map<String, Object> formData
) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPostFormData(url, headers, formData);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String getWithCharSet(
final String url,
final Map<String, ?> headers,
final String contentType,
final String charSet) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, contentType, charSet);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String getJSON(
final String url,
final Map<String, ?> headers
) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, APPLICATION_JSON, null);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static Response jsonRestCallWithHeaders(
final String url,
final Map<String, ?> headers
) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, APPLICATION_JSON, null);
return extractResponseObject(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String getJSONWithParams(
final String url,
final Map<String, ?> headers, final Map<String, ?> params
) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, APPLICATION_JSON, null, params);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String postBodyTextWithContentType(
final String url,
final String contentType,
final String body) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, null, contentType, null, body);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String postWithHeaders(
final String url,
final Map<String, ?> headers,
final String body) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, headers, "text/plain", null, body);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static String postWithContentType(
final String url,
final Map<String, ?> headers,
final String contentType,
final String body) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, headers, contentType, null, body);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
public static Response deleteResponse(
final String url) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
final Map<String, String> accept = Maps.map(
"Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;"
);
connection = doDelete(url, accept, null, null);
return extractResponseObject(connection);
}
}
);
}
代码示例来源:origin: advantageous/qbit
public static String postWithCharset(
final String url,
final Map<String, ?> headers,
final String contentType,
final String charSet,
final String body) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doPost(url, headers, contentType, charSet, body);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
/**
* GET that expects contents back as a byte array.
*
* @param url url
* @param contentType contentType
* @return bytes from location
*/
public static byte[] getBytes(
final String url, final String contentType) {
return Exceptions.tryIt(byte[].class, new Exceptions.TrialWithReturn<byte[]>() {
@Override
public byte[] tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, null, contentType, null, true);
return extractResponseBytes(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
/**
* GET that expects contents back as a byte array and allows you to pass headers.
*
* @param url url
* @param contentType contentType
* @param headers to pass.
* @return bytes from location
*/
public static byte[] getBytesUsingHeaders(
final String url, final String contentType, final Map<String, ?> headers) {
return Exceptions.tryIt(byte[].class, new Exceptions.TrialWithReturn<byte[]>() {
@Override
public byte[] tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, contentType, null, true);
return extractResponseBytes(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
/**
* GET that expects contents back as a byte array and allows you to pass headers.
*
* @param url url
* @param headers to pass.
* @return string from location
*/
public static String getWithHeaders(
final String url,
final Map<String, ?> headers) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, null, null);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
/**
* Does a simple HTTP get
*
* @param url pass the URL you want to get.
* @return contents as UTF-8 string
*/
public static String get(
final String url) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
final Map<String, String> accept = Maps.map(
"Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;"
);
connection = doGet(url, accept, null, null);
return extractResponseString(connection);
}
});
}
代码示例来源:origin: advantageous/qbit
/**
* Does a get but you get a Response object
*
* @param url url
* @return Response object
*/
public static Response getResponse(
final String url) {
return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() {
@Override
public Response tryIt() throws Exception {
URLConnection connection;
final Map<String, String> accept = Maps.map(
"Accept", "text/html,application/xhtml+xml,application/xml,application/json,text/plain;"
);
connection = doGet(url, accept, null, null);
return extractResponseObject(connection);
}
}
);
}
代码示例来源:origin: advantageous/qbit
/**
* GET that expects contents back as a string and allows you to pass headers and content type.
*
* @param url url
* @param headers to pass.
* @param contentType contentType
* @return UTF-8 string from location
*/
public static String getWithContentTypeHeaders(
final String url,
final Map<String, ?> headers,
final String contentType) {
return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
URLConnection connection;
connection = doGet(url, headers, contentType, null);
return extractResponseString(connection);
}
});
}
内容来源于网络,如有侵权,请联系作者删除!