long time = System.currentTimeMillis();
boolean success = false;
final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
try {
HttpRequestFactory requestFactory = HTTP_TRANSPORT
.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
}
});
GenericUrl url = new GenericUrl(_url);
HttpContent hc = new AbstractHttpContent("text/json") {
String content = serialize(jsonServiceRequest_);
@Override
public long getLength() throws IOException {
return content.getBytes("utf-8").length;
}
@Override
public void writeTo(OutputStream out_) throws IOException {
boolean logArgs = !servicesToNotLogArgs.contains(jsonServiceRequest_.getService());
if (logArgs) {
if (maxPayloadLengthToLog < 0 || content.length() <= maxPayloadLengthToLog) {
logger.info("calling service: {}", content);
} else {
if (logger.isDebugEnabled()) {
logger.info("calling service: {}", content);
} else {
String service = String.format("service: %s%s, reqId: %s, sessionId: %s, userId: %s",
_url, jsonServiceRequest_.getService(), jsonServiceRequest_.getReqId(),
jsonServiceRequest_.getSessionId(), jsonServiceRequest_.getUserId());
int argsLen = content.length();
String chunck = content.substring(0, maxPayloadLengthToLog);
logger.info(String.format("calling %s, payload: %s... %d chars (truncated - full content in debug level)",
service, chunck, argsLen));
}
}
} else {
String service = String.format("service: %s%s, reqId: %s, sessionId: %s, userId: %s",
_url, jsonServiceRequest_.getService(), jsonServiceRequest_.getReqId(),
jsonServiceRequest_.getSessionId(), jsonServiceRequest_.getUserId());
logger.info("calling {}, payload: /*censored*/",
service);
}
out_.write(content.getBytes("utf-8"));
out_.flush();
}
};
HttpRequest request = requestFactory.buildPostRequest(url, hc);
HttpResponse resp = request.execute();
InputStream is = resp.getContent();
String reqLogInfo = String.format("reqId: %s, sessionId: %s",
jsonServiceRequest_.getReqId(), jsonServiceRequest_.getSessionId());
StreamHandler jsh = getStreamHandler();