]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Jun 2017 17:25:35 +0000 (19:25 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Jun 2017 17:25:35 +0000 (19:25 +0200)
- sadly, Glassfish and Payara are both not so super-flexible to allow JNDI
  lookups in constructors. You have to either move that code to a @PostConstruct
  annotated method in bean (=controller) classes or do it on-demand.
- @PostConstruct, @Observes and so on are not processed outside beans, next
  "limitation" (or not wanted/intended/possible?).

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/converter/businesscontact/FinancialsBusinessContactConverter.java
src/java/org/mxchange/jfinancials/converter/contact/FinancialsContactConverter.java
src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java
src/java/org/mxchange/jfinancials/converter/mobile/FinancialsMobileConverter.java
src/java/org/mxchange/jfinancials/converter/mobileprovider/FinancialsMobileProviderConverter.java
src/java/org/mxchange/jfinancials/converter/user/FinancialsUserConverter.java
src/java/org/mxchange/jfinancials/validator/birthday/FinancialsBirthdayValidator.java
src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java
src/java/org/mxchange/jfinancials/validator/privacy_terms/FinancialsPrivacyTermsCheckboxValidator.java
src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java

index b355670253a2961b76263a629b1fb29f13814950..398ade5b747b01e3065e5df77b6ce61ab871eaa6 100644 (file)
@@ -47,17 +47,6 @@ public class FinancialsBusinessContactConverter implements Converter {
         * Initialization of this converter
         */
        public FinancialsBusinessContactConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.businessContactBean = (BusinessContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/businessContact!org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -71,6 +60,23 @@ public class FinancialsBusinessContactConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.businessContactBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and user controller
+                                       this.businessContactBean = (BusinessContactSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/businessContact!org.mxchange.jcontactsbusiness.BusinessContactSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Init instance
                BusinessContact businessContact = null;
 
index e8d1535c405970bb22b1da230c87f934c95fdcb9..a90e831e3b61d1de0babc530393056c87e5a2f43 100644 (file)
@@ -46,17 +46,6 @@ public class FinancialsContactConverter implements Converter {
         * Initialization of this converter
         */
        public FinancialsContactConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -70,6 +59,23 @@ public class FinancialsContactConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.contactBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and user controller
+                                       this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Init instance
                Contact contact = null;
 
index 3b89772b3a47eddcd685d758c37f913e7a01de05..fcfbae8f5647ddf555a36bf6f398f930ff836cb4 100644 (file)
@@ -41,23 +41,12 @@ public class FinancialsCountryConverter implements Converter {
        /**
         * Country bean
         */
-       private CountrySingletonBeanRemote countryBean;
+       private CountrySingletonBeanRemote countryBean = null;
 
        /**
         * Initialization of this converter
         */
        public FinancialsCountryConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and country bean
-                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -71,6 +60,23 @@ public class FinancialsCountryConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.countryBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and country bean
+                                       this.countryBean = (CountrySingletonBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Get full list
                List<Country> countryList = this.countryBean.allCountries();
 
index 4e34f413f7c5e8f485dd13dc853ebda0c252be7c..6e2dd8658ac99c83d0c81bbd9611871e3b96a5c1 100644 (file)
@@ -47,17 +47,6 @@ public class FinancialsMobileConverter implements Converter {
         * Initialization of this converter
         */
        public FinancialsMobileConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -71,6 +60,23 @@ public class FinancialsMobileConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.phoneBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and user controller
+                                       this.phoneBean = (PhoneSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Init instance
                DialableMobileNumber mobile = null;
 
index 67c053756b6ab174c4ea72e2772dd427f465db7d..58788ff4fd2969130db356f3f486dea003e8f1d9 100644 (file)
@@ -47,17 +47,6 @@ public class FinancialsMobileProviderConverter implements Converter {
         * Initialization of this converter
         */
        public FinancialsMobileProviderConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       /// and mobile provider controller
-                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/jfinancials-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -71,6 +60,23 @@ public class FinancialsMobileProviderConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.mobileRemoteBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       /// and mobile provider controller
+                                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Get full list
                List<MobileProvider> providerList = this.mobileRemoteBean.allMobileProvider();
 
index d045dcefe4d6fa79647affd3e1f1b08cd653a478..c0d49b11e32fc158ef9e336cf56c36ee3e66b7e7 100644 (file)
@@ -46,17 +46,6 @@ public class FinancialsUserConverter implements Converter {
         * Initialization of this converter
         */
        public FinancialsUserConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
        }
 
        @Override
@@ -70,6 +59,23 @@ public class FinancialsUserConverter implements Converter {
                        return null;
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.userBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and user controller
+                                       this.userBean = (UserSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new RuntimeException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Init instance
                User user = null;
 
index 4a1c78359425e4de12fd0abca5231d7148bd6ba9..521d43b027e352fc65252e3e3ca7374935868f23 100644 (file)
@@ -49,10 +49,10 @@ public class FinancialsBirthdayValidator extends BaseDateValidator implements Va
                // Try to get it
                try {
                        // Get initial context
-                       Context context = new InitialContext();
+                       Context initialContext = new InitialContext();
                } catch (final NamingException ex) {
                        // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
                }
        }
 
index bd938371b22e9732a17cb5dc7f34d4f435086bd0..942dffe316e8ef29e7b017f908be37a156818c9f 100644 (file)
@@ -21,10 +21,10 @@ import java.util.regex.Pattern;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
 import javax.faces.validator.FacesValidator;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
-import javax.faces.view.facelets.FaceletException;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -47,23 +47,12 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme
        /**
         * Contact session-scoped bean
         */
-       private final ContactSessionBeanRemote contactBean;
+       private ContactSessionBeanRemote contactBean;
 
        /**
         * Default constructor
         */
        public FinancialsEmailAddressValidator () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
-               } catch (final NamingException e) {
-                       // Throw again
-                       throw new FaceletException(e);
-               }
        }
 
        @Override
@@ -91,6 +80,23 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme
                        throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
                }
 
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.contactBean) {
+                               // Try it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // Try to lookup
+                                       this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
+               }
+
                // Get client id (aka form id)
                String clientId = component.getClientId();
 
index 86424469441caf5bd6e48355040a877175988f8a..93c7d232b6d544c421f8334fd357f636b77fe8d7 100644 (file)
@@ -44,4 +44,5 @@ public class FinancialsPrivacyTermsCheckboxValidator extends BaseBooleanValidato
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, false);
        }
+
 }
index d65c47200572f03b5afaf92bc631659e14120b79..26dceeb5871a82b0c4dbbc4e2335366e91877647 100644 (file)
@@ -17,9 +17,6 @@
 package org.mxchange.jfinancials.validator.user;
 
 import java.text.MessageFormat;
-import java.util.Set;
-import java.util.TreeSet;
-import javax.enterprise.event.Observes;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -31,8 +28,6 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import org.mxchange.jcoreee.validator.number.BaseLongValidator;
-import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 
 /**
@@ -43,11 +38,6 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 @FacesValidator ("UserIdValidator")
 public class FinancialsUserIdValidator extends BaseLongValidator implements Validator {
 
-       /**
-        * Cached user status
-        */
-       private static final Set<Long> cachedStatus = new TreeSet<>();
-
        /**
         * Serial number
         */
@@ -62,45 +52,6 @@ public class FinancialsUserIdValidator extends BaseLongValidator implements Vali
         * Initialization of this converter
         */
        public FinancialsUserIdValidator () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw it
-                       throw new ConverterException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
-       }
-
-       /**
-        * Event fired when the user registration is complete
-        * <p>
-        * @param event User registration event
-        */
-       public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
-               // event should not be null
-               if (null == event) {
-                       // Throw NPE
-                       throw new NullPointerException("event is null"); //NOI18N
-               } else if (event.getRegisteredUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("event.user is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() == null) {
-                       // userId is null
-                       throw new NullPointerException("event.user.userId is null"); //NOI18N
-               } else if (event.getRegisteredUser().getUserId() < 1) {
-                       // Not avalid id
-                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
-               }
-
-               // Get user instance
-               User registeredUser = event.getRegisteredUser();
-
-               // Update cache
-               FinancialsUserIdValidator.cachedStatus.add(registeredUser.getUserId());
        }
 
        @Override
@@ -114,26 +65,31 @@ public class FinancialsUserIdValidator extends BaseLongValidator implements Vali
                // Cast value
                Long userId = (Long) value;
 
-               // Define variable
-               Boolean ifUserExists;
-
-               // Is a map entry there?
-               if (FinancialsUserIdValidator.cachedStatus.contains(userId)) {
-                       // Get from cache
-                       ifUserExists = Boolean.TRUE;
-               } else {
-                       // Get status
-                       ifUserExists = this.userBean.ifUserIdExists(userId);
+               synchronized (this) {
+                       // Is the EJB instanciated?
+                       if (null == this.userBean) {
+                               // Try to get it
+                               try {
+                                       // Get initial context
+                                       Context initialContext = new InitialContext();
+
+                                       // ... and user controller
+                                       this.userBean = (UserSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+                               } catch (final NamingException ex) {
+                                       // Continue to throw it
+                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+                               }
+                       }
                }
 
+               // Define variable
+               Boolean ifUserExists = this.userBean.ifUserIdExists(userId);
+
                // Is the user id valid?
                if (!ifUserExists) {
                        // Is not valid
                        throw new ValidatorException(new FacesMessage(MessageFormat.format("No user found with id {0}. Please check your link.", userId))); //NOI18N
                }
-
-               // Add to cache if valid
-               FinancialsUserIdValidator.cachedStatus.add(userId);
        }
 
 }