]> git.mxchange.org Git - jjobs-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:32:14 +0000 (19:32 +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/jjobs/converter/businesscontact/JobsBusinessContactConverter.java
src/java/org/mxchange/jjobs/converter/contact/JobsContactConverter.java
src/java/org/mxchange/jjobs/converter/country/JobsCountryConverter.java
src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java
src/java/org/mxchange/jjobs/converter/mobileprovider/JobsMobileProviderConverter.java
src/java/org/mxchange/jjobs/converter/user/JobsUserConverter.java
src/java/org/mxchange/jjobs/validator/birthday/JobsBirthdayValidator.java
src/java/org/mxchange/jjobs/validator/emailaddress/JobsEmailAddressValidator.java
src/java/org/mxchange/jjobs/validator/privacy_terms/JobsPrivacyTermsCheckboxValidator.java
src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java

index 18175b157bd6bb71ac2a1eb460041c28192c6ebb..e809f7b7509019a749d467ea3d013155ea9bcf45 100644 (file)
@@ -47,17 +47,6 @@ public class JobsBusinessContactConverter implements Converter {
         * Initialization of this converter
         */
        public JobsBusinessContactConverter () {
-               // 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 JobsBusinessContactConverter 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/jjobs-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 23b42ebb0bd02b5d9015bba753af034dddab13b8..c15454dfd387ffa064ed2cb9af75ba2641d34164 100644 (file)
@@ -46,17 +46,6 @@ public class JobsContactConverter implements Converter {
         * Initialization of this converter
         */
        public JobsContactConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-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 JobsContactConverter 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/jjobs-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 cc9a476700d5f7163ca995b87299d98b4a79dd19..9f0fe4d10c3bafc972486f0a7b278dab0d02db56 100644 (file)
@@ -41,23 +41,12 @@ public class JobsCountryConverter implements Converter {
        /**
         * Country bean
         */
-       private CountrySingletonBeanRemote countryBean;
+       private CountrySingletonBeanRemote countryBean = null;
 
        /**
         * Initialization of this converter
         */
        public JobsCountryConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and country bean
-                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/jjobs-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 JobsCountryConverter 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/jjobs-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 6e4bb25db6bfcccd7b93e24c92832fd7d179921b..8f084b4d8563648dcd04dba33ee7bc1ff9bc983a 100644 (file)
@@ -47,17 +47,6 @@ public class JobsMobileNumberConverter implements Converter {
         * Initialization of this converter
         */
        public JobsMobileNumberConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jjobs-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 JobsMobileNumberConverter 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/jjobs-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 mobileNumber = null;
 
index 2989270da6fdbcad6a830f1d676d409185a5d636..713dc54c831167546947b8e4fd44f5193c1a4acc 100644 (file)
@@ -47,17 +47,6 @@ public class JobsMobileProviderConverter implements Converter {
         * Initialization of this converter
         */
        public JobsMobileProviderConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       /// and mobile provider controller
-                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/jjobs-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 JobsMobileProviderConverter 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/jjobs-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 8e5c81903fddaa09962ed41b6117b4e5b449c9bb..92579ad14662dd5976f06b6ae21805a0614477de 100644 (file)
@@ -46,17 +46,6 @@ public class JobsUserConverter implements Converter {
         * Constructor of this converter
         */
        public JobsUserConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-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 JobsUserConverter 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/jjobs-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 4f6f24887e2708e4a9b1dde76f1916de4da8f5db..ffeff2aa8bf182ac2f4edb24233177425844f6a7 100644 (file)
@@ -49,10 +49,10 @@ public class JobsBirthdayValidator extends BaseDateValidator implements Validato
                // 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 2893d6c3aa78a5234e9acaaf9321d9b9a080367e..feb195d83f14b15259cdffb4f3c2afb6e716e47a 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 JobsEmailAddressValidator extends BaseStringValidator implements Va
        /**
         * Contact session-scoped bean
         */
-       private final ContactSessionBeanRemote contactBean;
+       private ContactSessionBeanRemote contactBean;
 
        /**
         * Default constructor
         */
        public JobsEmailAddressValidator () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-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 JobsEmailAddressValidator extends BaseStringValidator implements Va
                        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/jjobs-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 a567dcadde63aab34550ff23a72211cbaf7072ee..508772695dc699c27354054f7c6859a1e0e42d69 100644 (file)
@@ -44,4 +44,5 @@ public class JobsPrivacyTermsCheckboxValidator extends BaseBooleanValidator impl
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, false);
        }
+
 }
index a9e16c17ee0141344fd00392d5c10c9ec724061f..c56a07faba339bc258478ef9704214aeb1442f2c 100644 (file)
@@ -17,9 +17,6 @@
 package org.mxchange.jjobs.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 JobsUserIdValidator extends BaseLongValidator implements Validator {
 
-       /**
-        * Cached user status
-        */
-       private static final Set<Long> cachedStatus = new TreeSet<>();
-
        /**
         * Serial number
         */
@@ -62,45 +52,6 @@ public class JobsUserIdValidator extends BaseLongValidator implements Validator
         * Initialization of this converter
         */
        public JobsUserIdValidator () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-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
-               JobsUserIdValidator.cachedStatus.add(registeredUser.getUserId());
        }
 
        @Override
@@ -114,26 +65,31 @@ public class JobsUserIdValidator extends BaseLongValidator implements Validator
                // Cast value
                Long userId = (Long) value;
 
-               // Define variable
-               Boolean ifUserExists;
-
-               // Is a map entry there?
-               if (JobsUserIdValidator.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/jjobs-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
-               JobsUserIdValidator.cachedStatus.add(userId);
        }
 
 }