[jboss-user] [JBoss Web Services] New message: "Re: Accesing Http Request object from a WS"

Juan Pablo Sabadini do-not-reply at jboss.com
Mon Feb 15 14:02:35 EST 2010


User development,

A new message was posted in the thread "Accesing Http Request object from a WS":

http://community.jboss.org/message/526451#526451

Author  : Juan Pablo Sabadini
Profile : http://community.jboss.org/people/jpsabadini

Message:
--------------------------------------------------------------
I found the way to access to the HttpServletRequest object. I post the anwser because maybe helps somebody. Here is the code (i'm posting a code of mine, it's a login):
 
...

//imports here

...

@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT) 
public class VmobileWS {
    
     //The WebServiceContext has the HttpServletRequest in it.

     @Resource 
     WebServiceContext wsCtx;
    
    @WebMethod()
    public UserDTO login(@WebParam(name="username") String username, @WebParam(name="password")  String password) {
        UserServiceEJBLocal userService = null;
        try {
            userService = UserServiceEJBUtil.getLocalHome().create();
        
            String md5Hash;
            md5Hash = MD5.createMD5(password);
            
            UserDTO userData = new UserDTO();
            userData.setLogonId(username);
            userData.setPassword(md5Hash);
            userData.setUsrMultiLogin(null);
 
            userData = userService.authenticateUser(userData);
 
            if(userData.getVmobileLogin()) {
                SOAPMessageContext jaxwsContext = (SOAPMessageContext)wsCtx.getMessageContext();
               //Here I extract the HttpServletRequest from the WebServiceContext.

*HttpServletRequest request =                (HttpServletRequest)jaxwsContext.get(SOAPMessageContext.SERVLET_REQUEST);*
                String remoteAddr = request.getRemoteAddr();
                HttpSession session = request.getSession();
                session.setAttribute(Constants.WEB_SESSION_USER_DTO_KEY, userData);
                return userData;
            }
        }
        catch (NamingException e) {
            return null;
        }
        catch (Exception e) {
            return null;
        }
        return null;
    }
}
 
Regards,
JP

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/526451#526451




More information about the jboss-user mailing list