Skip to content

Commit

Permalink
Merge pull request #545 from SDCISA-13736-ApplyFindings-20240105-1355
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha authored Jan 9, 2024
2 parents 0817082 + ad65cea commit b72ba30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public abstract class ConfigurationResourceConsumer implements ConfigurationResourceObserver {

private final Logger log = LoggerFactory.getLogger(ConfigurationResourceConsumer.class);
private static final Logger log = LoggerFactory.getLogger(ConfigurationResourceConsumer.class);

private final ConfigurationResourceManager configurationResourceManager;
private final String configResourceUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.gateleen.core.json.JsonUtil;
import org.swisspush.gateleen.core.util.StringUtils;
import org.swisspush.gateleen.core.validation.ValidationResult;
Expand All @@ -22,6 +21,8 @@
import java.io.IOException;
import java.util.Set;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Validates the configuration resources
*
Expand All @@ -30,9 +31,9 @@
class ConfigurationResourceValidator {

private static final String SCHEMA_DECLARATION = "http://json-schema.org/draft-04/schema#";
private Logger log = LoggerFactory.getLogger(ConfigurationResourceValidator.class);
private static final Logger log = getLogger(ConfigurationResourceValidator.class);

private Vertx vertx;
private final Vertx vertx;

public ConfigurationResourceValidator(Vertx vertx) {
this.vertx = vertx;
Expand Down Expand Up @@ -86,23 +87,23 @@ public void validateConfigurationResource(Buffer configurationResource, String r
}
} catch (IOException e) {
String message = "Cannot read JSON";
log.warn(message, e.getMessage());
log.warn("{}", message, e);
future.complete(new ValidationResult(ValidationStatus.VALIDATED_NEGATIV, message));
}
} else {
String message = "Invalid schema: Expected property '$schema' with content '"+SCHEMA_DECLARATION+"'";
log.warn(message);
log.warn("{}", message);
future.complete(new ValidationResult(ValidationStatus.VALIDATED_NEGATIV, message));
}
}, resultHandler);
}

private JsonArray extractMessagesAsJson(Set<ValidationMessage> valMsgs){
JsonArray resultArray = new JsonArray();
valMsgs.forEach(msg -> {
log.warn(msg.toString());
for (ValidationMessage msg : valMsgs) {
log.warn("{}", msg);
resultArray.add(JsonObject.mapFrom(msg));
});
}
return resultArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.bridge.BridgeEventType;
Expand Down Expand Up @@ -138,6 +139,7 @@ public boolean handle(final HttpServerRequest request) {
try {
message.put(PAYLOAD, new JsonObject(buffer.toString()));
} catch (DecodeException e) {
requestLog.info("{}", request.uri(), e);
request.response().setStatusCode(BAD_REQUEST);
request.response().end(e.getMessage());
return;
Expand All @@ -152,14 +154,15 @@ public boolean handle(final HttpServerRequest request) {
if (HttpMethod.GET == request.method() || Boolean.TRUE.toString().equals(request.headers().get(SYNC))) {
requestLog.debug("This is a synchronous request");
vertx.eventBus().request(address, message, new DeliveryOptions().setSendTimeout(TIMEOUT), (Handler<AsyncResult<Message<JsonObject>>>) reply -> {
HttpServerResponse rsp = request.response();
if (reply.succeeded()) {
requestLog.debug("Got response");
JsonObject response = reply.result().body();
MultiMap headers = null;
try {
if (response.fieldNames().contains(HEADERS)) {
headers = JsonMultiMap.fromJson(response.getJsonArray(HEADERS));
request.response().headers().setAll(headers);
rsp.headers().setAll(headers);
}
} catch (DecodeException e) {
requestLog.warn("Wrong headers in reply", e);
Expand All @@ -173,28 +176,28 @@ public boolean handle(final HttpServerRequest request) {
}
requestLog.debug("Response content type is {}", responseContentType);
try {
request.response().setChunked(true);
rsp.setChunked(true);
if (responseContentType != null && responseContentType.contains(APPLICATION_JSON)) {
request.response().end(response.getJsonObject(PAYLOAD).encode());
rsp.end(response.getJsonObject(PAYLOAD).encode());
} else if (responseContentType != null && responseContentType.contains(TEXT)) {
request.response().end(response.getString(PAYLOAD));
rsp.end(response.getString(PAYLOAD));
} else {
request.response().end(Buffer.buffer(response.getBinary(PAYLOAD)));
rsp.end(Buffer.buffer(response.getBinary(PAYLOAD)));
}
} catch (DecodeException e) {
requestLog.warn("Wrong payload in reply for content-type " + responseContentType, e);
request.response().setStatusCode(500);
request.response().end("Wrong payload in reply for content-type " + responseContentType + ": ", e.getMessage());
requestLog.warn("Wrong payload in reply for content-type {}", responseContentType, e);
rsp.setStatusCode(500);
rsp.end("Wrong payload in reply for content-type " + responseContentType + ": "+ e.getMessage());
}
} else {
requestLog.debug("No payload in response");
request.response().end();
rsp.end();
}
} else {
requestLog.debug("Timeout");
request.response().setStatusCode(GATEWAY_TIMEOUT);
request.response().setChunked(true);
request.response().end("Gateway Timeout");
requestLog.debug("Timeout", reply.cause());
rsp.setStatusCode(GATEWAY_TIMEOUT);
rsp.setChunked(true);
rsp.end("Gateway Timeout");
}
});
} else {
Expand Down

0 comments on commit b72ba30

Please sign in to comment.