]> git.mxchange.org Git - pizzaservice-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:44:59 +0000 (19:44 +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/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java
src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java
src/java/org/mxchange/pizzaapplication/converter/mobile/PizzaMobileConverter.java
src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java
src/java/org/mxchange/pizzaapplication/converter/user/PizzaUserConverter.java
src/java/org/mxchange/pizzaapplication/validator/birthday/PizzaBirthdayValidator.java
src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java
src/java/org/mxchange/pizzaapplication/validator/privacy_terms/PizzaPrivacyTermsCheckboxValidator.java
src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java

index b6acfa1a4ff9533d0f37a8b83e65fdaa8d3c64f3..da791cd9e9378fc62f621dbf7335ba2472508fea 100644 (file)
@@ -33,9 +33,9 @@ import javax.naming.NamingException;
 import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.contact.ContactUtils;
 import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jcontacts.contact.title.PersonalTitle;
-import org.mxchange.jcontacts.contact.ContactUtils;
 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
@@ -67,6 +67,11 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
         */
        private static final long serialVersionUID = 542_145_347_916L;
 
+       /**
+        * Academic academicTitle
+        */
+       private String academicTitle;
+
        /**
         * An event fired when the administrator has added a new contact
         */
@@ -226,11 +231,6 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
         */
        private String street;
 
-       /**
-        * Academic academicTitle
-        */
-       private String academicTitle;
-
        /**
         * An event fired when the administrator has updated contact data
         */
@@ -542,6 +542,16 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                return number;
        }
 
+       @Override
+       public String getAcademicTitle () {
+               return this.academicTitle;
+       }
+
+       @Override
+       public void setAcademicTitle (final String academicTitle) {
+               this.academicTitle = academicTitle;
+       }
+
        @Override
        @SuppressWarnings ("ReturnOfDateField")
        public Date getBirthday () {
@@ -785,16 +795,6 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                this.street = street;
        }
 
-       @Override
-       public String getAcademicTitle () {
-               return this.academicTitle;
-       }
-
-       @Override
-       public void setAcademicTitle (final String academicTitle) {
-               this.academicTitle = academicTitle;
-       }
-
        @Override
        public Integer getZipCode () {
                return this.zipCode;
index 2265954fb8d83a6c589bc31d67aa43104a9b1396..af15d8387acd6ce6d0db0849e725bcef4ef9dd0f 100644 (file)
@@ -46,17 +46,6 @@ public class PizzaContactConverter implements Converter {
         * Initialization of this converter
         */
        public PizzaContactConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaContactConverter 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/pizzaservice-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 6ccfa5c7cb00b5dded5b659c409d35994f0e2945..21e844c0a7b1fd994a9a2f1f62153541deefd0fd 100644 (file)
@@ -41,23 +41,12 @@ public class PizzaCountryConverter implements Converter {
        /**
         * Country bean
         */
-       private CountrySingletonBeanRemote countryBean;
+       private CountrySingletonBeanRemote countryBean = null;
 
        /**
         * Initialization of this converter
         */
        public PizzaCountryConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and country bean
-                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaCountryConverter 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/pizzaservice-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 70287ae97ec430c7feef94577bf7a3641c0fc5f5..e448d8f91b09778cee6e3341cf6ffd758465af96 100644 (file)
@@ -47,17 +47,6 @@ public class PizzaMobileConverter implements Converter {
         * Initialization of this converter
         */
        public PizzaMobileConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaMobileConverter 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/pizzaservice-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 87f9ac6bac3bcda400d6ef29e0ab1e8194487219..602e4641487b56b3b84916bc4ca31814297696c1 100644 (file)
@@ -47,17 +47,6 @@ public class PizzaMobileProviderConverter implements Converter {
         * Initialization of this converter
         */
        public PizzaMobileProviderConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       /// and SMS provider controller
-                       this.mobileRemoteBean = (MobileProviderSingletonBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaMobileProviderConverter 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/pizzaservice-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 d33bafe1cffcbad267560a5714bc97872f30d8ad..e1749402145006018ad5f8ed96802a7912fe53ea 100644 (file)
@@ -46,17 +46,6 @@ public class PizzaUserConverter implements Converter {
         * Initialization of this converter
         */
        public PizzaUserConverter () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaUserConverter 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/pizzaservice-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 1a3fbdfedf32fbd87f87b008b1dbdfbc45e0e157..888b5b75c1011a1f9b48019a22d5a7cb7cd2a429 100644 (file)
@@ -49,10 +49,10 @@ public class PizzaBirthdayValidator extends BaseDateValidator implements Validat
                // 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 fff7640fca0c3e35073eb04dfffd3b86b1f6379f..1a0ceff4e6c184cbe69e90bd32d1ea696192ddcb 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 PizzaEmailAddressValidator extends BaseStringValidator implements V
        /**
         * Contact session-scoped bean
         */
-       private final ContactSessionBeanRemote contactBean;
+       private ContactSessionBeanRemote contactBean;
 
        /**
         * Default constructor
         */
        public PizzaEmailAddressValidator () {
-               // Try it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-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 PizzaEmailAddressValidator extends BaseStringValidator implements V
                        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/pizzaservice-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 ba3f108da598bd468b587708b36d5167cd464399..378c968abd22417c2e304f1fcb216c89ace5988e 100644 (file)
@@ -44,4 +44,5 @@ public class PizzaPrivacyTermsCheckboxValidator extends BaseBooleanValidator imp
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, false);
        }
+
 }
index ba8df1a7dad073e7348ff22c08b1047301538da1..aa6e1de80a3e5cae45fd969dd5fbdeea1c724862 100644 (file)
@@ -17,9 +17,6 @@
 package org.mxchange.pizzaapplication.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 PizzaUserIdValidator extends BaseLongValidator implements Validator {
 
-       /**
-        * Cached user status
-        */
-       private static final Set<Long> cachedStatus = new TreeSet<>();
-
        /**
         * Serial number
         */
@@ -62,46 +52,6 @@ public class PizzaUserIdValidator extends BaseLongValidator implements Validator
         * Initialization of this converter
         */
        public PizzaUserIdValidator () {
-               // Try to get it
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // ... and user controller
-                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-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
-               PizzaUserIdValidator.cachedStatus.add(registeredUser.getUserId());
-
        }
 
        @Override
@@ -115,26 +65,31 @@ public class PizzaUserIdValidator extends BaseLongValidator implements Validator
                // Cast value
                Long userId = (Long) value;
 
-               // Define variable
-               Boolean ifUserExists;
-
-               // Is a map entry there?
-               if (PizzaUserIdValidator.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/pizzaservice-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
-               PizzaUserIdValidator.cachedStatus.add(userId);
        }
 
 }