4 Replies Latest reply on Jan 4, 2007 8:15 PM by Norman Richards

    Problme in  LoggedInInterceptor..

    Waheed murad Newbie

      I am developing a " LoggedInInterceptor" but problem with it is that when i return the string it does not functon properly
      Interceptor code is here:
      ----------------------------------

      @Interceptor(around={BijectionInterceptor.class, ValidationInterceptor.class, ConversationInterceptor.class, BusinessProcessInterceptor.class},
      within=RemoveInterceptor.class)

      public class LoggedInInterceptor{

      @AroundInvoke
      public Object checkLoggedIn(InvocationContext invocation) throws Exception{

      System.out.println("LoggedInInterceptor...");

      Method m=invocation.getMethod();

      boolean isLoggedIn = Contexts.getSessionContext().get("loggedIn")!=null;

      if (isLoggedIn){
      return invocation.proceed();
      }else{
      return "loginpage";
      }
      }

      }

      when it return loginpage it seems that instead of going to login page it is trying to go on the same page actionbean on which it was invoked...

      navigation rule in faces-config.xml is

      <navigation-rule>
      <navigation-case>
      <from-outcome>loginpage</from-outcome>
      <to-view-id>/eregindex.jsp</to-view-id>

      </navigation-case>
      </navigation-rule>

      any help plzzz
      thanks in advance...

        • 1. Re: Problme in  LoggedInInterceptor..
          Norman Richards Master

          Can you show the code where you are using it?

          • 2. Re: Problme in  LoggedInInterceptor..
            Waheed murad Newbie

            This is my SessionBean class where i am using it what i am trying to achive is that if a user directly try to open the page by tying a URL e.g "http://localhost:8080/ereg/secretquestions.jsp" then the LoggedInIntercepter should check first that user is logged in or not if not that return to some specific page (navigation specified in the faces-config.xml )....


            @Stateful
            @Scope(SESSION)
            @Name("SecretQuestionsAction")

            @Interceptors(LoggedInInterceptor.class)

            public class SecretQuestionsAction implements SecretQuestionsLocal{


            @PersistenceContext(unitName="Database")
            protected EntityManager em;

            @In(required=false,value="SecretQuestions")
            @Out(required=false,value="SecretQuestions")
            private SecretQuestions secretQuestions;

            @DataModel
            private List allSecretQuestionsList;

            @DataModelSelection(value="allSecretQuestionsList")
            private SecretQuestions selectedSecretQuestion;

            @In
            private Context sessionContext;

            @In(create=true)
            FacesMessages facesMessages;

            int mode=0;

            String acknowledge = null;
            /*--------------------------------------------------------------------*/

            public String toSecretQuestionsPage(){
            System.out.println("toSecretQuestionsPage method...");
            return "/secretquestions.jsp";
            }

            public String addSecretQuestion(){

            try{
            if(!validateOpts()){
            em.persist(secretQuestions);
            secretQuestions=null;
            sessionContext.remove("SecretQuestions");
            getSecretQuestionsList();
            acknowledge = "The Record is added successfully.";
            }else{
            return null;
            }
            }catch(Exception e){
            System.out.println("Error Have accoured in\n\t SecretQuestions.java --> addSecretQuestion()? \n\t"+e.getMessage());
            }
            return "success";
            }
            /*--------------------------------------------------------------------*/
            public boolean validateOpts(){
            boolean isError=false;
            if(secretQuestions.getSecretQuestion()==""){
            facesMessages.add("secretQuestion",new FacesMessage("Please enter secret question"));
            isError=true;
            }

            return isError;
            }
            /*--------------------------------------------------------------------*/
            @Factory("allSecretQuestionsList")
            public String getSecretQuestionsList(){

            try{
            setMode(0);
            acknowledge = null;
            allSecretQuestionsList = em.createQuery("from SecretQuestions e where e.isDeleted=0").getResultList();
            }catch(Exception e){
            System.out.println("Error Have accoured in\n\t SecretQuestions.java --> getSecretQuestionsList()? \n\t"+e.getMessage());
            }
            return null;
            }
            /*--------------------------------------------------------------------*/

            public String deleteSecretQuestion(){

            try{
            SecretQuestions deleted = em.find(SecretQuestions.class, selectedSecretQuestion.getId());
            if(deleted != null){
            deleted.setIsDeleted(1);
            }
            deleted = null;
            sessionContext.remove("SecretQuestions");
            secretQuestions=null;
            getSecretQuestionsList();
            acknowledge = "The Record is deleted successfully.";
            System.out.println("getting the result list complete \n\t");

            }catch(Exception e){
            System.out.println("Error Have accoured in\n\t SecretQuestions.java --> deleteSecretQuestion()? \n\t"+e.getMessage());
            }

            return null;
            }
            /*--------------------------------------------------------------------*/

            public String updateSecretQuestion(){
            try{
            em.merge(secretQuestions);
            setMode(0);
            getSecretQuestionsList();
            acknowledge = "The record is updated successfully";

            }catch(org.hibernate.validator.InvalidStateException e){
            System.out.println(e.getMessage());
            System.out.println("error...");
            InvalidValue[] val=e.getInvalidValues();
            for(int i=0;i<val.length;i++){
            System.out.println(val.getPropertyName());
            }
            }
            return "successUpdate";
            }
            /*--------------------------------------------------------------------*/
            public String showSecretQuestionDetails(){
            try{
            setMode(1);
            acknowledge = null;
            secretQuestions = em.find(SecretQuestions.class, selectedSecretQuestion.getId());
            }catch(Exception e){
            setMode(0);
            System.out.println("Error Have accoured in\n\t SecretQuestionAction.java --> showSecretQuestionDetails()? \n\t"+e.getMessage());
            }

            return "/secretquestions_crud.jsp";
            }
            /*--------------------------------------------------------------------*/
            public String loadSecretQuestion(){
            System.out.println("in the getPricingOption method load");
            try{
            setMode(2);
            acknowledge = null;
            secretQuestions = em.find(SecretQuestions.class, selectedSecretQuestion.getId());
            }catch(Exception e){
            setMode(0);
            System.out.println("Error Have accoured in\n\t SecretQuestionAction.java --> loadSecretQuestion()? \n\t"+e.getMessage());
            }

            return "/secretquestions_crud.jsp";
            }
            /*--------------------------------------------------------------------*/
            public String toCreateForm(){
            acknowledge = null;
            resetMode();
            return "/secretquestions_crud.jsp";
            }
            /*--------------------------------------------------------------------*/

            public void resetMode(){
            try{
            if(secretQuestions != null){
            setMode(0);
            secretQuestions=null;
            sessionContext.remove("SecretQuestions");
            acknowledge = null;
            }
            }catch(Exception e){
            System.out.println("Error Have accoured in\n\t SecretQuestionAction.java --> reSetMode()? \n\t"+e.getMessage());
            }
            }
            /*--------------------------------------------------------------------*/

            public int getMode() {
            return mode;
            }
            public void setMode(int mode) {
            this.mode = mode;
            }

            /*--------------------------------------------------------------------*/
            public String getAcknowledge() {
            return acknowledge;
            }
            public void setAcknowledge(String acknowledge) {
            this.acknowledge = acknowledge;
            }

            /*--------------------------------------------------------------------*/
            @Remove @Destroy
            public void destroy(){}
            /*--------------------------------------------------------------------*/
            }

            • 3. Re: Problme in  LoggedInInterceptor..
              Ian White Newbie

              I use Intellij IDEA 6.0.2.
              When I created a project for the seam-booking ear, I got the following warning when compiling LoggedInInterceptor.java:

              Usage of java.lang.reflect.Method is not allowed in an EJB


              Hope this helpful to you.

              • 4. Re: Problme in  LoggedInInterceptor..
                Norman Richards Master

                Which call, specifically, is failing? I notice that you aren't checking whether or not the return value is a String before returning a string. You don't want to intercept "getMode", for example.