aboutsummaryrefslogtreecommitdiff
path: root/modules/core_common_webapp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core_common_webapp')
-rw-r--r--modules/core_common_webapp/pom.xml31
-rw-r--r--modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/provider/StatusMessageProvider.java95
-rw-r--r--modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/storage/EidasCacheTransactionStoreDecorator.java2
3 files changed, 92 insertions, 36 deletions
diff --git a/modules/core_common_webapp/pom.xml b/modules/core_common_webapp/pom.xml
index b36153e6..27dab9d1 100644
--- a/modules/core_common_webapp/pom.xml
+++ b/modules/core_common_webapp/pom.xml
@@ -21,6 +21,10 @@
<groupId>at.asitplus.eidas.ms_specific</groupId>
<artifactId>core_common_lib</artifactId>
</dependency>
+ <dependency>
+ <groupId>at.asitplus.eidas.ms_specific.modules</groupId>
+ <artifactId>eidas_proxy-sevice</artifactId>
+ </dependency>
<dependency>
<groupId>at.gv.egiz.eaaf</groupId>
@@ -60,9 +64,25 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>mockwebserver</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>at.asitplus.eidas.ms_specific</groupId>
+ <artifactId>core_common_lib</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
</dependency>
<dependency>
<groupId>at.gv.egiz.eaaf</groupId>
@@ -92,14 +112,7 @@
<artifactId>eaaf_module_pvp2_idp</artifactId>
<scope>test</scope>
<type>test-jar</type>
- </dependency>
- <dependency>
- <groupId>com.squareup.okhttp3</groupId>
- <artifactId>mockwebserver</artifactId>
- <scope>test</scope>
</dependency>
-
-
</dependencies>
<build>
diff --git a/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/provider/StatusMessageProvider.java b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/provider/StatusMessageProvider.java
index e86d50d3..b47c0b63 100644
--- a/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/provider/StatusMessageProvider.java
+++ b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/provider/StatusMessageProvider.java
@@ -31,13 +31,18 @@ import java.util.ResourceBundle;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.MessageSource;
+import org.springframework.context.MessageSourceAware;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import at.gv.egiz.eaaf.core.api.IStatusMessenger;
import at.gv.egiz.eaaf.core.exceptions.EaafException;
+import at.gv.egiz.eaaf.core.impl.logging.LogMessageProviderFactory;
@Service("StatusMessageProvider")
-public class StatusMessageProvider implements IStatusMessenger {
+public class StatusMessageProvider implements IStatusMessenger, MessageSourceAware {
private static final Logger log = LoggerFactory.getLogger(StatusMessageProvider.class);
private static final String ERROR_MESSAGES_UNAVAILABLE =
@@ -48,49 +53,78 @@ public class StatusMessageProvider implements IStatusMessenger {
"External error-codes can NOT be load from application. Only internal errorCode: {0} is availabe";
private static final String ERROR_NO_EXTERNALERROR_CODE =
"No external error for internal error with number.={0}";
-
- // internal messanges
- private static final String DEFAULT_MESSAGE_RESOURCES = "properties/status_messages_en";
- private static final Locale DEFAULT_MESSAGE_LOCALES = new Locale("en", "GB");
- private ResourceBundle messages;
-
+ private static final String MSG_WARN_NO_SOURCE = "MessageCode: {} is NOT SET for locale: {}";
+ private static final String MSG_INFO = "Use locale: {} as default";
+
// external error codes
private static final String DEFAULT_EXTERNALERROR_RESOURCES = "properties/external_statuscodes_map";
private static final Locale DEFAULT_EXTERNALERROR_LOCALES = new Locale("en", "GB");
private ResourceBundle externalError = null;
+ //internal messanges
+ private MessageSource messageSource;
+
@Override
- public String getMessageWithoutDefault(String messageId, Object[] parameters) {
- // initialize messages
- if (messages == null) {
- this.messages = ResourceBundle.getBundle(
- DEFAULT_MESSAGE_RESOURCES,
- DEFAULT_MESSAGE_LOCALES);
+ public String getMessageWithoutDefault(final String messageId, final Object[] parameters) {
+ if (messageSource == null) {
+ return null;
- }
+ } else {
+ try {
+ final Locale locale = LocaleContextHolder.getLocale();
+ return messageSource.getMessage(messageId, parameters, locale);
- // create the message
- if (messages == null) {
- return MessageFormat.format(ERROR_MESSAGES_UNAVAILABLE, new Object[] { messageId });
+ } catch (final NoSuchMessageException e) {
+ log.info(MSG_WARN_NO_SOURCE, messageId, LocaleContextHolder.getLocale());
+ log.debug(MSG_INFO, Locale.ENGLISH);
- } else {
- final String rawMessage = messages.getString(messageId);
- return MessageFormat.format(rawMessage, parameters);
+ try {
+ return messageSource.getMessage(messageId, parameters, Locale.ENGLISH);
+
+ } catch (final NoSuchMessageException e2) {
+ log.info(MSG_WARN_NO_SOURCE, messageId, Locale.ENGLISH);
+
+ }
+ } catch (final MissingResourceException e2) {
+ log.warn("No message source", e2);
+
+ }
}
+
+ return null;
+
}
@Override
- public String getMessage(String messageId, Object[] parameters) {
- try {
- return getMessageWithoutDefault(messageId, parameters);
+ public String getMessage(final String messageId, final Object[] parameters) {
+ if (messageSource == null) {
+ return MessageFormat.format(ERROR_MESSAGES_UNAVAILABLE, new Object[]{messageId});
+
+ } else {
+ try {
+ final Locale locale = LocaleContextHolder.getLocale();
+ return messageSource.getMessage(messageId, parameters, locale);
+
+ } catch (final NoSuchMessageException e) {
+ log.info(MSG_WARN_NO_SOURCE, messageId, LocaleContextHolder.getLocale());
+ log.debug(MSG_INFO, Locale.ENGLISH);
+
+ try {
+ return messageSource.getMessage(messageId, parameters, Locale.ENGLISH);
+
+ } catch (final NoSuchMessageException e2) {
+ return MessageFormat.format(ERROR_NO_MESSAGE, new Object[]{messageId});
+
+ }
- } catch (final MissingResourceException e2) {
- return MessageFormat.format(ERROR_NO_MESSAGE, new Object[] { messageId });
+ } catch (final MissingResourceException e2) {
+ return MessageFormat.format(ERROR_NO_MESSAGE, new Object[]{messageId});
+ }
}
}
-
+
@Override
public String getResponseErrorCode(Throwable throwable) {
String errorCode = IStatusMessenger.CODES_EXTERNAL_ERROR_GENERIC;
@@ -136,4 +170,13 @@ public class StatusMessageProvider implements IStatusMessenger {
}
}
+ @Override
+ public void setMessageSource(MessageSource messageSource) {
+ this.messageSource = messageSource;
+
+ log.info("Injecting 'StatusMessanger' into 'LogMessageProviderFactory'");
+ LogMessageProviderFactory.setStatusMessager(this);
+
+ }
+
}
diff --git a/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/storage/EidasCacheTransactionStoreDecorator.java b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/storage/EidasCacheTransactionStoreDecorator.java
index 9b1c8eae..5a59a4e0 100644
--- a/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/storage/EidasCacheTransactionStoreDecorator.java
+++ b/modules/core_common_webapp/src/main/java/at/asitplus/eidas/specific/core/storage/EidasCacheTransactionStoreDecorator.java
@@ -171,7 +171,7 @@ public class EidasCacheTransactionStoreDecorator implements ITransactionStorage,
@Override
public void remove(String key) {
if (containsKey(key)) {
- log.debug("Remove element with key: " + key + " from " + ITransactionStorage.class.getName());
+ log.trace("Remove element with key: " + key + " from " + ITransactionStorage.class.getName());
boolean delResult = storage.remove(key);
log.trace("Object: {} removed from cache: {}", key, delResult);