|
|
|
|
@ -268,6 +268,32 @@ public class WebClient extends AbstractComponent {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**데이터 및 파일의 업로드 요청을 전송한다.
|
|
|
|
|
* @param <T> 요청의 body 핸들러 유형
|
|
|
|
|
* @param configurer 업로드 요청의 설정자
|
|
|
|
|
* @return http 응답
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public <T> HttpResponse<T> upload(Consumer<Request> configurer) {
|
|
|
|
|
Request req = new Request().multipart();
|
|
|
|
|
req.charset = charset();
|
|
|
|
|
configurer.accept(req);
|
|
|
|
|
HttpRequest hreq = req.post();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (req.download)
|
|
|
|
|
return (HttpResponse<T>)handleRequest(req.async, hreq, HttpResponse.BodyHandlers.ofInputStream(), req.downloadHandler);
|
|
|
|
|
else
|
|
|
|
|
return (HttpResponse<T>)handleRequest(req.async, hreq, HttpResponse.BodyHandlers.ofString(), req.textHandler);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
if (req.async) {
|
|
|
|
|
req.errorHandler.accept(rootCause(e));
|
|
|
|
|
return null;
|
|
|
|
|
} else
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**응답 유형이 다운로드한 파일일 경우, 해당 파일을 지정한 경로로 저장한다.
|
|
|
|
|
* @param inputStream 다운로드한 파일
|
|
|
|
|
* @param path 저장할 경로
|
|
|
|
|
@ -432,6 +458,13 @@ public class WebClient extends AbstractComponent {
|
|
|
|
|
return contentType(ContentType.JSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**content-type 헤더를 멀티파트로 설정한다.
|
|
|
|
|
* @return 현재 Request
|
|
|
|
|
*/
|
|
|
|
|
public Request multipart() {
|
|
|
|
|
return contentType(ContentType.MULTIPART);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSON json() {
|
|
|
|
|
return ifEmpty(json, () -> json = new JSON());
|
|
|
|
|
}
|
|
|
|
|
|