Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions agrirouter-sdk-java-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.dke.data.agrirouter.api.service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import static java.lang.String.valueOf;

/**
* Interface to encapsulate logging capabilities. Logging will be done using LOG4J2, ruleset should
* be:
*
* <ul>
* <li>Log method entry on level DEBUG.
* <li>Log method steps on level TRACE.
* <li>Log method result on level TRACE.
* <li>Log method exit on level DEBUG.
* </ul>
*
* Please be aware of the rule "Log or throw" regarding exceptions.
*/
public interface HasLogger {

Marker METHOD_BEGIN = MarkerFactory.getMarker("METHOD_BEGIN");
Marker METHOD_END = MarkerFactory.getMarker("METHOD_END");

Map<String, Logger> loggerCache = new HashMap<>();

/**
* Returns the native LOG4J2 logger for further logging.
*
* @return -
*/
default Logger getNativeLogger() {
if (null == loggerCache.get(this.getClass().getName())) {
final Logger logger = LoggerFactory.getLogger(this.getClass());
loggerCache.put(this.getClass().getName(), logger);
}
return loggerCache.get(this.getClass().getName());
}

/**
* Log method begin. Will log all given parameters as well.
*/
default void logMethodBegin(Object... objects) {
getNativeLogger().debug(METHOD_BEGIN, "BEGIN | Start of method.");
Arrays.stream(objects).forEach(o -> getNativeLogger().trace(valueOf(o)));
}

/**
* Log method exit. Will log all given results as well.
*
* @param objects The results of the method.
*/
default void logMethodEnd(Object... objects) {
Arrays.stream(objects).forEach(o -> getNativeLogger().trace(valueOf(o)));
getNativeLogger().debug(METHOD_END, "END | End of method.");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import com.dke.data.agrirouter.api.exception.IllegalParameterDefinitionException;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/** Parameter validation using bean validation. */
public interface ParameterValidation {

Logger LOGGER = LogManager.getLogger();
public interface ParameterValidation extends HasLogger {

/**
* Validation of the parameters. If there are any constraint violations, there will be a
Expand All @@ -18,10 +14,10 @@ public interface ParameterValidation {
* @throws IllegalParameterDefinitionException -
*/
default void validate() {
LOGGER.debug("Validating parameters.");
LOGGER.trace("Technical validation.");
getNativeLogger().debug("Validating parameters.");
getNativeLogger().trace("Technical validation.");
this.technicalValidation();
LOGGER.trace("Business validation.");
getNativeLogger().trace("Business validation.");
this.businessValidation();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.dke.data.agrirouter.api.service;

import javax.ws.rs.core.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public interface RequestLogging {

Logger logger = LogManager.getLogger(RequestLogging.class);
public interface RequestLogging extends HasLogger {

default void logRequest(String className, Response response) {
String logMessage = "\n" + "# [" + className + "] " + "\n" + response + "\n";
this.logger.info(() -> logMessage);
this.getNativeLogger().info(logMessage);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dke.data.agrirouter.impl;

import com.dke.data.agrirouter.api.env.Environment;
import com.dke.data.agrirouter.api.service.LoggingEnabledService;
import com.dke.data.agrirouter.api.service.HasLogger;

/** Internal implementation for an environmental service. */
public abstract class EnvironmentalService implements LoggingEnabledService {
public abstract class EnvironmentalService implements HasLogger {

/** The current environment. */
protected final Environment environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dke.data.agrirouter.impl;

import com.dke.data.agrirouter.api.service.LoggingEnabledService;
import com.dke.data.agrirouter.api.service.HasLogger;

/** Internal implementation for an environmental service. */
public abstract class NonEnvironmentalService implements LoggingEnabledService {}
public abstract class NonEnvironmentalService implements HasLogger {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dke.data.agrirouter.api.exception.CouldNotCreatePrivateKeyException;
import com.dke.data.agrirouter.api.exception.CouldNotCreatePublicKeyException;
import com.dke.data.agrirouter.api.service.LoggingEnabledService;
import com.dke.data.agrirouter.api.service.HasLogger;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
Expand All @@ -12,7 +12,7 @@
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;

public class SecurityKeyCreationService implements LoggingEnabledService {
public class SecurityKeyCreationService implements HasLogger {

public PrivateKey createPrivateKey(String privateKey) {
this.logMethodBegin(privateKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dke.data.agrirouter.impl.common.ssl;

import com.dke.data.agrirouter.api.exception.CouldNotCreateDynamicKeyStoreException;
import com.dke.data.agrirouter.api.service.LoggingEnabledService;
import com.dke.data.agrirouter.api.service.HasLogger;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -19,7 +19,7 @@
import javax.net.SocketFactory;
import javax.net.ssl.*;

public class KeyStoreCreationService implements LoggingEnabledService {
public class KeyStoreCreationService implements HasLogger {

public static final String TEMPORARY_KEY_PASSWORD = "changeit";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import com.dke.data.agrirouter.api.dto.encoding.EncodedMessage;
import com.dke.data.agrirouter.api.enums.SystemMessageType;
import com.dke.data.agrirouter.api.enums.TechnicalMessageType;
import com.dke.data.agrirouter.api.service.LoggingEnabledService;
import com.dke.data.agrirouter.api.service.HasLogger;
import com.dke.data.agrirouter.api.service.messaging.encoding.EncodeMessageService;
import com.dke.data.agrirouter.api.service.parameters.*;
import com.dke.data.agrirouter.api.util.TimestampUtil;
import com.dke.data.agrirouter.impl.common.MessageIdService;
import java.util.Objects;

public interface MessageEncoder extends LoggingEnabledService {
public interface MessageEncoder extends HasLogger {

/**
* Encode a message to delete messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public List<String> encode(List<MessageParameterTuple> messageParameterTuples) {

/**
* Chunk and add the Base64 encoding for a message if necessary. If there is only one chunk, the
* single chunk will be returned as Base64 encoded value. The chunk information and all IDs
* will be set by the SDK and are no longer in control of the application.
* single chunk will be returned as Base64 encoded value. The chunk information and all IDs will
* be set by the SDK and are no longer in control of the application.
*
* @param messageHeaderParameters -
* @param payloadParameters Content of the message. It shall not be Base64 encoded before.
Expand Down Expand Up @@ -171,8 +171,8 @@ public List<MessageParameterTuple> chunkAndEncode(
} else {
if (messageHeaderParameters.getTechnicalMessageType().getNeedsBase64Encoding()) {
getNativeLogger()
.debug(
"The message type needs to be base64 encoded, therefore we are encoding the raw value.");
.debug(
"The message type needs to be base64 encoded, therefore we are encoding the raw value.");
final PayloadParameters payload = new PayloadParameters();
payload.copyFrom(payloadParameters);
payload.setValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

import com.dke.data.agrirouter.api.cancellation.CancellationToken;
import com.dke.data.agrirouter.api.enums.CertificationType;
import com.dke.data.agrirouter.api.service.HasLogger;
import com.dke.data.agrirouter.api.service.parameters.FetchMessageParameters;
import com.dke.data.agrirouter.impl.RequestFactory;
import com.dke.data.agrirouter.impl.validation.ResponseValidator;
import java.util.Objects;
import java.util.Optional;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/** Interface to fetch messages for the HTTP implementation by polling the outbox. */
public interface MessageFetcher extends ResponseValidator {

Logger LOGGER = LogManager.getLogger();
public interface MessageFetcher extends ResponseValidator, HasLogger {

int MAX_TRIES_BEFORE_FAILURE = 10;
long DEFAULT_INTERVAL = 500;
Expand All @@ -34,9 +31,10 @@ default Optional<String> poll(
fetchMessageParameters.validate();
int nrOfTries = 1;
while (cancellationToken.isNotCancelled()) {
LOGGER.debug(
"The cancellation token is not cancelled, we have another try. This is try number {}.",
nrOfTries);
getNativeLogger()
.debug(
"The cancellation token is not cancelled, we have another try. This is try number {}.",
nrOfTries);
Response response =
RequestFactory.securedRequest(
Objects.requireNonNull(fetchMessageParameters.getOnboardingResponse())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.google.gson.Gson;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.message.ObjectArrayMessage;

public abstract class AbstractOnboardingService extends EnvironmentalService {

Expand All @@ -25,10 +24,6 @@ protected OnboardingRequest getOnboardRequest(
String gatewayId,
CertificationType certificationType) {
this.getNativeLogger().info("BEGIN | Creating onboard request.");
this.getNativeLogger()
.debug(
new ObjectArrayMessage(
uuid, applicationId, certificationType, gatewayId, certificationType));

OnboardingRequest onboardingRequest = new OnboardingRequest();
onboardingRequest.setId(uuid);
Expand Down
Loading