• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic