1 Reply Latest reply on Feb 15, 2010 2:02 PM by jpsabadini

    Accesing Http Request object from a WS

    jpsabadini

      Hi everybody,

                  I really need the community help on this one. I have a web app running on Jboss 4.2.2GA with jbossws-native-2.0.1.SP2 (build=200710210837). I need to find the IP host of where the user is accesing the WS... If I had the htto request object I could access with the following code:

       

        ....

        HttpServletRequest request = ... do the object intanciation here...

        String remoteHost = request.getRemoteAddr();

        ....

       

       

           So I need or access to the http request object or get a similar object in WS...

       

           Thanks for any help!

       

           JP

        • 1. Re: Accesing Http Request object from a WS
          jpsabadini

          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