5 Replies Latest reply on Feb 14, 2007 2:36 PM by Gavin King


    Monkey Den Master

      I'm looking for the Seam equivalent of ServletRequest.getRemoteAddr(). The api docs don't tell me much. Thanks.


        • 1. Re: ServletRequest.getRemoteAddr()
          Norman Richards Master

          This might be instructive: http://jboss.org/index.html?module=bb&op=viewtopic&p=3998480

          Obviously, if you want it in Java, just translate the EL to the equivalent calls.

          • 2. Re: ServletRequest.getRemoteAddr()
            Monkey Den Master

            Thanks Norm. That's essentially the same reason I'd like to log the IP. The only difference is, I'd like to do it within an interceptor (like the @LoggedIn example given in the docs). I don't know if it's not working because you cant do this in an Interceptor or because components.xml is wrong.

            public class LoggedInInterceptor {
             private Log log;
             @In("#{remoteAddr}") private String ipAddress;
             public Object checkLoggedIn(InvocationContext invocation) throws Exception {
             User user = (User)Contexts.getSessionContext().get("user");
             boolean isLoggedIn = user != null;
             try {
             if (isLoggedIn) {
             return invocation.proceed();
             } else {
             throw new SecurityException();
             } catch (SecurityException se) {
             log.info("IP #0 is trying to access a secure location without having logged in.", ipAddress);
             return "/login.seam";

            Given my ignorance of advanced XML, I assume I can use the default namespace, which gives me "http://jboss.com/products/seam/components"

            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
             "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.1.xsd
             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.1.xsd
             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.1.xsd">
             <core:init debug="true" jndi-pattern="nemoves-pws/#{ejbName}/local"/>
             <core:ejb installed="false"/>
             <factory name="remoteAddr" value="#{facesContext.externalContext.request.remoteAddr}"/>

            • 3. Re: ServletRequest.getRemoteAddr()
              Monkey Den Master

              Also, this code produces a RequestFacade but it's remoteAddr field is null:

              String ip = FacesContext.getCurrentInstance().getExternalContext().getRequest().getRemoteAddr();

              • 4. Re: ServletRequest.getRemoteAddr()
                Gavin King Master

                An interceptor is not a Seam component. You can't use @In and friends. Use Component.getInstance(), etc.

                • 5. Re: ServletRequest.getRemoteAddr()
                  Gavin King Master

                  Or BuiltInComponent.instance(), or whatever.

                  And interceptors should not have @Names.