Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input values like name="bean.property" can not be populated to interceptors

 
Ramesh kangamuthu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my Strut2 application I have to pass uservo.userId and uservo.password to AuthenticationInterceptor's intercept method.

UserVO is a model object that has userId and password properties.

index.jsp:-


<s:textfield theme="simple" name="uservo.userId" cssClass="LoginTextBox" size="20" />

<s:password theme="simple" name="uservo.password" cssClass="LoginTextBox" size="20" />

when the page is submitted, AuthenticationInterceptor will be invoked to do authentication for checking userId and password entered by the user.

AuthenticationInterceptor.java


public class AuthenticationInterceptor extends AbstractInterceptor implements SessionAware,RequestAware{

private UserVO uservo;
private String userId;

private String password


UserServices userServices=new UserServicesImpl();
Map<String,Object> session;
Map<String,Object> request;

public void setSession(Map session) {
this.session = session;
}
public void setRequest(Map request) {
this.request = request;
}

@SuppressWarnings("unchecked")
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Inside AuthenticationInterceptor");
log.debug(" Inside AuthenticationInterceptor ");
ActionContext ctx = invocation.getInvocationContext();

session = ActionContext.getContext().getSession();

log.debug(" ActionContext ctx :"+ctx);
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
log.debug(" HttpServletRequest request :"+request);

String userIPAddress = request.getRemoteAddr();
String loginID = "anonymous";

//assertCanCreateSession(request);


if (authenticateCoinUser(request))
{
loginID = (String)session.get("userId");
if(loginID == null || loginID.trim().equals("")){
loginID = "anonymous";
}
log.debug("loginId and IP :"+loginID+" : "+userIPAddress);
if(userServices.enlistUserProfile(loginID, userIPAddress)){
return invocation.invoke();
}
}else{
throw new AuthenticationException("You are not authorised");
}
return null;
}

public boolean authenticateCoinUser(HttpServletRequest request){

System.out.println(" uservo >>"+uservo);
String userId=getUserId();
String password=getPassword();
System.out.println(" userId >>"+userId);
System.out.println(" password >>"+password);

return false;
}

public UserVO getUservo() {
return uservo;
}

public void setUservo(UserVO uservo) {
this.uservo = uservo;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}
}

I could not get the uservo.userId and uservo.password input values from index.jsp to the interceptor even i implement RequestAware.

uservo object throws NullPointerException.

Could anybody tell the answer?



 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Interceptors are not actions, and are not treated as such: request parameters are not set on interceptors, and doing so would be a potential nightmare. Ideally, interceptors are completely ignorant of other interceptors in the interceptor stacks.

2) This is an inappropriate use of an interceptor: interceptors are designed to handle cross-cutting application concerns, not logging someone on. Logging someone on should be handled by an action. *Checking* if someone is logged on would be handled by an interceptor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic