Announcement Announcement Module
Collapse
No announcement yet.
Validation Exception and Properties not getting set using <aop:scoped-proxy/> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation Exception and Properties not getting set using <aop:scoped-proxy/>

    Hi All

    I am trying to use session beans (i.e. scope="session") in a web app that uses a SimpleFormController. The Controller which is a singleton has a collaborator i.e. the session bean that I have set up session beans as defined below. Requests to this controller use a "POST" method so they are validated using my custom validator as described below. However, when the validation stage is reached, the execption below is thrown and I am not sure how to go about solving this.

    I can get around the problem by creating a new instance(using the new operator see commented out code below) of the scoped session bean in the formBackingObject method of the controller and then passing that to the validator. However, this is not what I want, I want the scoped session bean(i.e. the form backing object) to be injected into the controller.

    Also, when I set the properties on the scoped session objects, they do not get set.I have stepped through the code using a debugger and what happens is when the the debugger is in the setter method of the property, the property does changes value to whatever you set it to however, when you return from the setter method to the method that called the property's setter method, the property's value returns to the original value as though you havent called the setter method. e.g. Lets say in my scoped session bean (lets call it loginFormObject), I have a property called username which is of type string hence the the setter on the property name is
    Code:
    public void setUsername(String newUsername){this.username=newUsername;}
    . In my controller if I call
    Code:
    loginFormObject.setUsername("myNewName");
    , the method returns without setting the username property to "myNewName". The username doesnt get changed to "myNewName". However, if I step through the code using the debugger, in the setUsername method, I can see the the value of username property changed to "myNewName" I dont understand how that happens.
    I am using eclipse galileo debugger and i have cglib-nodep-2.1_3.jar on my build path

    Exception

    Code:
    java.lang.IllegalArgumentException: Validator [class com.raptorsoftdynamics.iBankUI.validators.LoginFormValidator] does not support [class com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject$$EnhancerByCGLIB$$6e9ef8d]
    	at org.springframework.validation.ValidationUtils.invokeValidator(ValidationUtils.java:60)
    	at org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(BaseCommandController.java:395)
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:263)
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
    	at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:623)
    	at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    	at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    	at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    	at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    	at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    	at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    	at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    	at java.lang.Thread.run(Thread.java:595)
    [servletname]-servlet.xml

    Code:
    <bean id="loginFormObject" class ="com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject" scope="session">
    	<aop:scoped-proxy/>
    </bean>
    
    <bean id = "loginController" class="com.raptorsoftdynamics.iBankUI.controllers.LoginController">
    	<property name="sessionForm" value="true"/> 
    	<property name="formView" value="login"/> 
    	<property name="successView" value="redirect:home.html"/>
    	<property name="commandClass" value="com.raptorsoftdynamics.iBankUI.formObjects.LoginFormObject" />
    	<property name="commandName" value="loginForm"/>
    	<property name="validator">
    <bean class ="com.raptorsoftdynamics.iBankUI.validators.LoginFormValidator"/>
    </property>
    	<property name="loginFormObject" ref ="loginFormObject"/>  
    </bean>
    Controller.java

    Code:
    protected Object formBackingObject(HttpServletRequest request) throws Exception{
    	// loginFormObject = new LoginFormObject(); If uncommented, code works
    	 HashMap<Object,Object> map = new HashMap<Object,Object>();
    	
    
    	 Map<String,Integer> securityDigitsToSeclect = new HashMap<String,Integer>();
    	 String suffix = "";
    	 int digitIndexesToMatch = 3;
    	 int []randomSecurityDigits = randomSecurityDigitSelector(digitIndexesToMatch);
    	 
    	 for (int i = 0;i<randomSecurityDigits.length;i++){ 
    		 suffix = getSuffix(randomSecurityDigits[i]);
    		 suffix = ((Integer)randomSecurityDigits[i]).toString()+suffix;
    		 securityDigitsToSeclect.put(suffix,((Integer)randomSecurityDigits[i]));
    		 
    	 }
    	 loginFormObject.setSecurityDigits(loginFormObject.getSecurityDigits());
    	return loginFormObject;
    	}
    	
    protected void onBind(HttpServletRequest request, Object command, BindException errors) {
    		  
    		  loginFormObject = (LoginFormObject)command; 
    			String username = loginFormObject.getUsername();
    			String password =  loginFormObject.getPassword();
    			String digits = loginFormObject.getDigits(); 
    			List<SecurityDigit> securityDigits = new ArrayList<SecurityDigit>();
    			securityDigits = loginFormObject.getSecurityDigits();
    			long formLoginTime = loginFormObject.getFormLoginTime();
    			HttpSession session = request.getSession();
    			boolean loggedIn = false; 
    			
    			try {
    				loggedIn= doLogin(username, password, formLoginTime);
    				loginFormObject.setLoggedIn(loggedIn);
    				session.setAttribute("username", username);
    				if(!loggedIn){
    //At this point, this, the call to setUsername returns without 
    //changing the value of "username" (oringinal value being "")to "Annonymous"
    
    loginFormObject.setUsername("Annonymous");					
    			}
    				else{
    					loginFormObject.setUsername(username); 
    				}
    			} catch (ClassCastException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			} catch (NamingException e) { 
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		
    		  session.setAttribute("loggedIn", loggedIn);
    		  setLoginFormObject(loginFormObject);
    }  
    public void setLoginFormObject(LoginFormObject loginFormObject) {
    		this.loginFormObject=loginFormObject;
    		
    	}
    LoginFormValidor.java

    Code:
    public boolean supports(Class aClass){
    		return aClass.equals(LoginFormObject.class);
    	}
    public void validate(Object obj, Errors err){
    			setErrors(err);
    			LoginFormObject lfo = (LoginFormObject)obj;
    			
    			if ("".equals(lfo.getUsername()))
    				err.rejectValue("username", "err.invalid.username", "Username not supplied");
    		 
    			if ("".equals(lfo.getPassword()))
    				err.rejectValue("password", "err.invalid.password", "Password not supplied");
    			
    			if("".equals(lfo.getDigits()))
    				err.rejectValue("digits", "security.digits.empty");
    			if(lfo.getDigits().length()!=3) 
    				err.rejectValue("digits", "security.digits.length.too_short");
    			if (!((Integer)lfo.getFirstSecurityDigit() instanceof Integer))
    					err.rejectValue("first_security_digit", "err.invalid.first_security_digit", "First security digit not supplied");
    			
    			if (!(((Integer)lfo.getSecondSecurityDigit()) instanceof Integer))
    				err.rejectValue("second_security_digit", "err.invalid.second_security_digit", "Second security digit not supplied");
    			if ((!((String)lfo.getInvalidDetailsSupplied()).equals(""))&&(lfo.getInvalidDetailsSupplied().equalsIgnoreCase("invalid.username.password")))
    			err.rejectValue("invalidDetailsSupplied","invalid.username.password", "Invalid username, password or security digits supplied.\nPlease check these details and try again");
    			if ((!((String)lfo.getInvalidDetailsSupplied()).equals(""))&&(lfo.getInvalidDetailsSupplied().equalsIgnoreCase("user.not.loggedIn")))
    				err.rejectValue("invalidDetailsSupplied","user.not.loggedIn", "You've been brought to this page because you have not logged in or you session has expired.\nPlease login to continue");
    			
    			if (!(((Integer)lfo.getThirdSecurityDigit()) instanceof Integer))
    				err.rejectValue("third_security_digit", "err.invalid.third_security_digit", "Second security digit not supplied");
    			
    		}
    LoginFormObject.java

    Code:
    private String username; 
    
    public synchronized String getUsername() {
    		return username;
    	}
    
    public synchronized void setUsername(String username) {
    		this.username = username;
    	}
    Last edited by quophyie; Dec 9th, 2009, 08:48 AM.

  • #2
    Hi I have found the answer to part 1 of my question i.e. the Exception. All I had to do was change the supports method to

    Code:
    	@SuppressWarnings("unchecked")
    	public boolean supports(Class aClass){
    		return LoginFormObject.class.isAssignableFrom( aClass);
    	}

    I am not getting the validation errors anymore however, I still dunno why the setter methods dont work. Please help!!

    Comment

    Working...
    X