|
|
|
|
@ -212,7 +212,7 @@ public class PublicInfo extends AbstractComponent {
|
|
|
|
|
/** 응답본문 */
|
|
|
|
|
private String body;
|
|
|
|
|
/** 에러 */
|
|
|
|
|
private Throwable error;
|
|
|
|
|
private Fault fault;
|
|
|
|
|
|
|
|
|
|
/**응답코드를 반환한다.
|
|
|
|
|
* @return 응답코드
|
|
|
|
|
@ -269,26 +269,30 @@ public class PublicInfo extends AbstractComponent {
|
|
|
|
|
*/
|
|
|
|
|
public Response setBody(String body) {
|
|
|
|
|
this.body = peel(body);
|
|
|
|
|
if (Fault.included(this.body)) {
|
|
|
|
|
fault = new JSON().parse(this.body, Fault.class);
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean success() {
|
|
|
|
|
return error == null && status == 200;
|
|
|
|
|
return fault == null && status == 200;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**오류를 반환한다.
|
|
|
|
|
* @return 오류
|
|
|
|
|
*/
|
|
|
|
|
public Throwable getError() {
|
|
|
|
|
return error;
|
|
|
|
|
public Fault getFault() {
|
|
|
|
|
return fault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**오류를 설정한다.
|
|
|
|
|
* @param error 오류
|
|
|
|
|
* @param fault 오류
|
|
|
|
|
* @return 현재 Response
|
|
|
|
|
*/
|
|
|
|
|
public Response setError(Throwable error) {
|
|
|
|
|
this.error = error;
|
|
|
|
|
public Response setFault(Throwable throwable) {
|
|
|
|
|
this.fault = new Fault();
|
|
|
|
|
this.fault.setError(throwable);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -348,9 +352,9 @@ public class PublicInfo extends AbstractComponent {
|
|
|
|
|
return new Response()
|
|
|
|
|
.setStatus(statusCode)
|
|
|
|
|
.setHeaders(hresp.headers().map())
|
|
|
|
|
.setBody(200 == statusCode ? respBody(body) : body);
|
|
|
|
|
.setBody(respBody(statusCode, body));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return new Response().setError(rootCause(e));
|
|
|
|
|
return new Response().setFault(rootCause(e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -361,12 +365,14 @@ public class PublicInfo extends AbstractComponent {
|
|
|
|
|
return gpki == null ? str : gpki.encrypt(api.getProviderServerId(), str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String respBody(String str) {
|
|
|
|
|
private String respBody(int statusCode, String str) {
|
|
|
|
|
if (gpki == null)
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
|
|
String body = gpki.decrypt(str);
|
|
|
|
|
log(Client.class).debug("decrypted:\n{}", body);
|
|
|
|
|
boolean decrypt = 200 == statusCode;
|
|
|
|
|
String body = decrypt ? gpki.decrypt(str) : str;
|
|
|
|
|
if (decrypt)
|
|
|
|
|
log(Client.class).debug("decrypted:\n{}", body);
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -374,22 +380,20 @@ public class PublicInfo extends AbstractComponent {
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
public static class Fault {
|
|
|
|
|
private String
|
|
|
|
|
code,
|
|
|
|
|
loc;
|
|
|
|
|
private ErrorMessage message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
public static class ErrorMessage {
|
|
|
|
|
static final boolean included(String str) {
|
|
|
|
|
return str.contains("errorMessage")
|
|
|
|
|
&& str.contains("errorCode");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String
|
|
|
|
|
errorMessage,
|
|
|
|
|
errorCode;
|
|
|
|
|
return str.contains("\"message\":") || str.contains("\"message\" :");
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
static final boolean errorIncluded(String str) {
|
|
|
|
|
return str.contains("\"errorMessage\":")
|
|
|
|
|
|| str.contains("\"errorMessage\" :")
|
|
|
|
|
|| str.contains("\"errorCode\":")
|
|
|
|
|
|| str.contains("\"errorCode\" :");
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
private int code;
|
|
|
|
|
private String loc;
|
|
|
|
|
private Object message;
|
|
|
|
|
private Throwable error;
|
|
|
|
|
}
|
|
|
|
|
}
|