下面列出了org.springframework.boot.configurationprocessor.json.JSONObject#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() throws IOException {
return 200;
}
@Override
public String getStatusText() throws IOException {
return "OK";
}
@Override
public void close() {
}
@Override
public InputStream getBody() {
SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
String data = "";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("code", resultEnum.getCode());
jsonObject.put("msg", resultEnum.getMessage());
jsonObject.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
data = jsonObject.toString();
logger.error(data);
return new ByteArrayInputStream(data.getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() throws IOException {
return 200;
}
@Override
public String getStatusText() throws IOException {
return "OK";
}
@Override
public void close() {
}
@Override
public InputStream getBody() {
SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
String data = "";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("code", resultEnum.getCode());
jsonObject.put("msg", resultEnum.getMessage());
jsonObject.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
data = jsonObject.toString();
logger.error(data);
return new ByteArrayInputStream(data.getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() throws IOException {
return 200;
}
@Override
public String getStatusText() throws IOException {
return "OK";
}
@Override
public void close() {
}
@Override
public InputStream getBody() {
SophiaHttpStatus resultEnum = SophiaHttpStatus.SERVER_TIMEOUT;
String data = "";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("code", resultEnum.getCode());
jsonObject.put("msg", resultEnum.getMessage());
jsonObject.put("data", data);
} catch (JSONException e) {
e.printStackTrace();
}
data = jsonObject.toString();
logger.error(data);
return new ByteArrayInputStream(data.getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}