Class OkHttpClientHelper
-
- All Implemented Interfaces:
public class OkHttpClientHelperWho uses it, who should close it, in a try-close pattern.
- Since:
2020-06-02
trydofor
-
-
Field Summary
Fields Modifier and Type Field Description public final static RequestBodyEMPTY
-
Constructor Summary
Constructors Constructor Description OkHttpClientHelper()
-
Method Summary
Modifier and Type Method Description static OkHttpClientstaticClient()global static client static OkHttpClientspringClient()inject Spring Configured client static MultipartBody.BuilderpostFile(@NotNull() String key, @NotNull() File file)static MultipartBody.BuilderpostFile(@NotNull() String key, Array<byte> file, @NotNull() String fileName)static MultipartBody.BuilderpostFile(@NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)static StringpostFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, @NotNull() File file)static StringpostFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, @NotNull() File file)static StringpostFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, Array<byte> file, @NotNull() String fileName)static StringpostFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, Array<byte> file, @NotNull() String fileName)static StringpostFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)static StringpostFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)static StringpostFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() MultipartBody body)static StringpostFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() MultipartBody body)static StringpostJson(@NotNull() OkHttpClient client, @NotNull() String url, @Nullable() CharSequence json)static StringpostJson(@NotNull() Call.Factory callFactory, @NotNull() String url, @Nullable() CharSequence json)static ResponseBodyextract(@Nullable() Response response)static StringextractString(@Nullable() Response response)static StringextractString(@Nullable() Response response, boolean nullWhenThrow)static StringextractString(@Nullable() ResponseBody body)static StringextractString(@Nullable() ResponseBody body, boolean nullWhenThrow)static Array<byte>download(@NotNull() OkHttpClient client, @NotNull() String url)static Array<byte>download(@NotNull() Call.Factory callFactory, @NotNull() String url)static Array<byte>download(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String method)static RequestBodyemptyBody(@NotNull() String method)return empty body or null according to method static Array<byte>download(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String method)static StringgetText(@NotNull() OkHttpClient client, @NotNull() String url)static StringgetText(@NotNull() Call.Factory callFactory, @NotNull() String url)static StringexecuteString(@NotNull() OkHttpClient client, @NotNull() Request request, boolean nullWhenThrow)static StringexecuteString(@NotNull() Call.Factory callFactory, @NotNull() Request request, boolean nullWhenThrow)static StringexecuteJson(@NotNull() OkHttpClient client, @NotNull() String url, @Nullable() CharSequence json, @NotNull() String method)static StringexecuteJson(@NotNull() Call.Factory callFactory, @NotNull() String url, @Nullable() CharSequence json, @NotNull() String method)static Responseexecute(@NotNull() OkHttpClient client, @NotNull() Request request)static Responseexecute(@NotNull() Call.Factory callFactory, @NotNull() Request request)static Responseexecute(@NotNull() OkHttpClient client, @NotNull() Request request, boolean nullWhenThrow)static Responseexecute(@NotNull() Call.Factory callFactory, @NotNull() Request request, boolean nullWhenThrow)static <T> Texecute(@NotNull() OkHttpClient client, @NotNull() Request request, @NotNull() BiFunction<Response, IOException, T> fun)static <T> Texecute(@NotNull() Call.Factory callFactory, @NotNull() Request request, @NotNull() BiFunction<Response, IOException, T> fun)static Responseexecute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder)static Responseexecute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder)static Responseexecute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder, boolean nullWhenThrow)static Responseexecute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder, boolean nullWhenThrow)static <T> Texecute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder, @NotNull() BiFunction<Response, IOException, T> fun)static <T> Texecute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder, @NotNull() BiFunction<Response, IOException, T> fun)static voidclearCookie(@NotNull() OkHttpClient client, @NotNull() HttpUrl url)-
-
Method Detail
-
staticClient
@NotNull() static OkHttpClient staticClient()
global static client
-
springClient
@NotNull() static OkHttpClient springClient()
inject Spring Configured client
-
postFile
@NotNull() static MultipartBody.Builder postFile(@NotNull() String key, @NotNull() File file)
-
postFile
@NotNull() static MultipartBody.Builder postFile(@NotNull() String key, Array<byte> file, @NotNull() String fileName)
-
postFile
@NotNull() static MultipartBody.Builder postFile(@NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)
-
postFile
@NotNull() static String postFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, @NotNull() File file)
-
postFile
@NotNull() static String postFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, @NotNull() File file)
-
postFile
@NotNull() static String postFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, Array<byte> file, @NotNull() String fileName)
-
postFile
@NotNull() static String postFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, Array<byte> file, @NotNull() String fileName)
-
postFile
@NotNull() static String postFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)
-
postFile
@NotNull() static String postFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String key, @NotNull() InputStream file, @NotNull() String fileName)
-
postFile
@NotNull() static String postFile(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() MultipartBody body)
-
postFile
@NotNull() static String postFile(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() MultipartBody body)
-
postJson
@NotNull() static String postJson(@NotNull() OkHttpClient client, @NotNull() String url, @Nullable() CharSequence json)
-
postJson
@NotNull() static String postJson(@NotNull() Call.Factory callFactory, @NotNull() String url, @Nullable() CharSequence json)
-
extract
@Nullable() static ResponseBody extract(@Nullable() Response response)
-
extractString
@NotNull() static String extractString(@Nullable() Response response)
-
extractString
@Nullable()@Contract(value = "_,false->!null") static String extractString(@Nullable() Response response, boolean nullWhenThrow)
-
extractString
@NotNull() static String extractString(@Nullable() ResponseBody body)
-
extractString
@Nullable()@Contract(value = "_,false->!null") static String extractString(@Nullable() ResponseBody body, boolean nullWhenThrow)
-
download
static Array<byte> download(@NotNull() OkHttpClient client, @NotNull() String url, @NotNull() String method)
-
emptyBody
@Nullable() static RequestBody emptyBody(@NotNull() String method)
return empty body or null according to method
-
download
static Array<byte> download(@NotNull() Call.Factory callFactory, @NotNull() String url, @NotNull() String method)
-
getText
@NotNull() static String getText(@NotNull() Call.Factory callFactory, @NotNull() String url)
-
executeString
@Contract(value = "_,_,false->!null") static String executeString(@NotNull() OkHttpClient client, @NotNull() Request request, boolean nullWhenThrow)
-
executeString
@Contract(value = "_,_,false->!null") static String executeString(@NotNull() Call.Factory callFactory, @NotNull() Request request, boolean nullWhenThrow)
-
executeJson
static String executeJson(@NotNull() OkHttpClient client, @NotNull() String url, @Nullable() CharSequence json, @NotNull() String method)
-
executeJson
static String executeJson(@NotNull() Call.Factory callFactory, @NotNull() String url, @Nullable() CharSequence json, @NotNull() String method)
-
execute
@NotNull() static Response execute(@NotNull() OkHttpClient client, @NotNull() Request request)
-
execute
@NotNull() static Response execute(@NotNull() Call.Factory callFactory, @NotNull() Request request)
-
execute
@Contract(value = "_,_,false->!null") static Response execute(@NotNull() OkHttpClient client, @NotNull() Request request, boolean nullWhenThrow)
-
execute
@Contract(value = "_,_,false->!null") static Response execute(@NotNull() Call.Factory callFactory, @NotNull() Request request, boolean nullWhenThrow)
-
execute
@Nullable() static <T> T execute(@NotNull() OkHttpClient client, @NotNull() Request request, @NotNull() BiFunction<Response, IOException, T> fun)
-
execute
@Nullable() static <T> T execute(@NotNull() Call.Factory callFactory, @NotNull() Request request, @NotNull() BiFunction<Response, IOException, T> fun)
-
execute
@NotNull() static Response execute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder)
-
execute
@NotNull() static Response execute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder)
-
execute
@Contract(value = "_,_,false->!null") static Response execute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder, boolean nullWhenThrow)
-
execute
@Contract(value = "_,_,false->!null") static Response execute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder, boolean nullWhenThrow)
-
execute
@Nullable() static <T> T execute(@NotNull() OkHttpClient client, @NotNull() Request.Builder builder, @NotNull() BiFunction<Response, IOException, T> fun)
-
execute
static <T> T execute(@NotNull() Call.Factory callFactory, @NotNull() Request.Builder builder, @NotNull() BiFunction<Response, IOException, T> fun)
-
clearCookie
static void clearCookie(@NotNull() OkHttpClient client, @NotNull() HttpUrl url)
-
-
-
-