Rationalized logs
This commit is contained in:
parent
af3c099fd5
commit
2d74631416
|
@ -30,9 +30,7 @@ public class HTTPEventSender implements EventSender {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Event event) {
|
public void send(Event event) {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Starting HTTP POST thread to: {}", baseEnndpointURL);
|
||||||
log.debug("Starting HTTP POST thread to: " + baseEnndpointURL);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
URL eventEndpoint = new URL(baseEnndpointURL, event.getName());
|
URL eventEndpoint = new URL(baseEnndpointURL, event.getName());
|
||||||
new Thread(new HTTPost(eventEndpoint, event.toJSONString())).start();
|
new Thread(new HTTPost(eventEndpoint, event.toJSONString())).start();
|
||||||
|
@ -58,59 +56,40 @@ public class HTTPEventSender implements EventSender {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Getting OIDC token for client: {}", clientId);
|
||||||
log.debug("Getting OIDC token for client: " + clientId);
|
|
||||||
}
|
|
||||||
JWTToken token = null;
|
JWTToken token = null;
|
||||||
if (clientId != null && clientSecret != null && tokenURL != null) {
|
if (clientId != null && clientSecret != null && tokenURL != null) {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Getting OIDC token for clientId '{}' from: {}", clientId, tokenURL);
|
||||||
log.debug("Getting OIDC token for clientId '" + clientId + "' from: " + tokenURL);
|
|
||||||
}
|
|
||||||
token = OpenIdConnectRESTHelper.queryClientToken(clientId, clientSecret, tokenURL);
|
token = OpenIdConnectRESTHelper.queryClientToken(clientId, clientSecret, tokenURL);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Performing HTTP POST to: {}", endpoint);
|
||||||
log.debug("Performing HTTP POST to: " + endpoint);
|
|
||||||
}
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) endpoint.openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setConnectTimeout(CONNECTION_TIMEOUT);
|
connection.setConnectTimeout(CONNECTION_TIMEOUT);
|
||||||
if (log.isTraceEnabled()) {
|
log.trace("HTTP connection timeout set to: {}", connection.getConnectTimeout());
|
||||||
log.trace("HTTP connection timeout set to: " + connection.getConnectTimeout());
|
|
||||||
}
|
|
||||||
connection.setReadTimeout(READ_TIMEOUT);
|
connection.setReadTimeout(READ_TIMEOUT);
|
||||||
if (log.isTraceEnabled()) {
|
log.trace("HTTP connection Read timeout set to: {}", connection.getReadTimeout());
|
||||||
log.trace("HTTP connection Read timeout set to: " + connection.getReadTimeout());
|
|
||||||
}
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
// Commented out as per the Conductor issue: https://github.com/Netflix/conductor/issues/376
|
// Commented out as per the Conductor issue: https://github.com/Netflix/conductor/issues/376
|
||||||
// connection.setRequestProperty("Accept", "application/json");
|
// connection.setRequestProperty("Accept", "application/json");
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Setting authorization header as: {}", token.getAsBearer());
|
||||||
log.debug("Setting authorization header as: " + token.getAsBearer());
|
|
||||||
}
|
|
||||||
connection.setRequestProperty("Authorization", token.getAsBearer());
|
connection.setRequestProperty("Authorization", token.getAsBearer());
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Sending request without authorization header");
|
||||||
log.debug("Sending request without authorization header");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
OutputStream os = connection.getOutputStream();
|
OutputStream os = connection.getOutputStream();
|
||||||
if (log.isTraceEnabled()) {
|
log.trace("Sending event JSON: {}", jsonString);
|
||||||
log.trace("Sending event JSON: " + jsonString);
|
|
||||||
}
|
|
||||||
os.write(jsonString.getBytes("UTF-8"));
|
os.write(jsonString.getBytes("UTF-8"));
|
||||||
os.flush();
|
os.flush();
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
int httpResultCode = connection.getResponseCode();
|
int httpResultCode = connection.getResponseCode();
|
||||||
if (log.isTraceEnabled()) {
|
log.trace("HTTP Response code: {}", httpResultCode);
|
||||||
log.trace("HTTP Response code: " + httpResultCode);
|
|
||||||
}
|
log.trace("Reading response");
|
||||||
if (log.isTraceEnabled()) {
|
|
||||||
log.trace("Reading response");
|
|
||||||
}
|
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
InputStreamReader isr = null;
|
InputStreamReader isr = null;
|
||||||
if (httpResultCode == HttpURLConnection.HTTP_OK) {
|
if (httpResultCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
@ -127,11 +106,9 @@ public class HTTPEventSender implements EventSender {
|
||||||
br.close();
|
br.close();
|
||||||
isr.close();
|
isr.close();
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("[{}] Event publish OK. Results: {}", httpResultCode, sb.toString());
|
||||||
log.debug("[" + httpResultCode + "] Event publish OK. Results: " + sb.toString());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("[" + httpResultCode + "] Event publish is not OK. Results: " + sb.toString());
|
log.warn("[{}] Event publish is not OK. Results: {}", httpResultCode, sb.toString());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("POSTing JSON to: " + endpoint, e);
|
log.error("POSTing JSON to: " + endpoint, e);
|
||||||
|
|
Loading…
Reference in New Issue