use of info.xiancloud.core.util.http.Response in project xian by happyyangyuan.
the class HttpUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
ObjectInputStream ois = null;
try {
String reqBase64 = msg.get("req", String.class);
ois = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(reqBase64)));
Request request = (Request) ois.readObject();
Response response;
try {
response = request.executeLocal();
} catch (ConnectException e) {
return UnitResponse.error(ISocketGroup.CODE_CONNECT_TIMEOUT, null, "Connect timeout: " + request.getUrl());
} catch (SocketTimeoutException e) {
return UnitResponse.error(ISocketGroup.CODE_SOCKET_TIMEOUT, null, "Read timeout: " + request.getUrl());
} catch (Throwable e) {
return UnitResponse.exception(e);
}
JSONObject retJson = new JSONObject();
retJson.put("status", response.getStatus());
retJson.put("headers", response.getHeaders());
retJson.put("entity", response.string());
return UnitResponse.success(retJson);
} catch (Throwable e) {
return UnitResponse.exception(e);
} finally {
}
}
Aggregations