-
1. Re: ServletRequest.getRemoteAddr()
norman.richards Feb 14, 2007 11:30 AM (in response to monkeyden)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()
monkeyden Feb 14, 2007 1:14 PM (in response to monkeyden)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.
@Name("loggedInInterceptor") public class LoggedInInterceptor { @Logger private Log log; @In("#{remoteAddr}") private String ipAddress; @AroundInvoke 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" xmlns:core="http://jboss.com/products/seam/core" xmlns:security="http://jboss.com/products/seam/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "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}"/> </components>
-
3. Re: ServletRequest.getRemoteAddr()
monkeyden Feb 14, 2007 1:57 PM (in response to monkeyden)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 Feb 14, 2007 2:35 PM (in response to monkeyden)An interceptor is not a Seam component. You can't use @In and friends. Use Component.getInstance(), etc.
-
5. Re: ServletRequest.getRemoteAddr()
gavin.king Feb 14, 2007 2:36 PM (in response to monkeyden)Or BuiltInComponent.instance(), or whatever.
And interceptors should not have @Names.