Passing parameters across 2 servers
mat Jul 13, 2007 5:33 AMHi,
We have created two minimal seam projects based on seam-gen, each on a separate server, with the following environment:
JBoss-seam 2.0 BETA1, with facelets;
JBoss-4.2.0.GA;
We need to pass authentication parameters from one server to another:
Users must authenticate in server1, by entering username and password. Upon successful login; browser should redirect to other servers such as serverMain, with the username and password passed as parameters.
I have implemented the following which redirects to serverMain home page correctly:
String url = "http:// serverMain:8080/MyMainApp/home.seam"; FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getExternalContext().redirect(url);
However, I need to pass the authentication parameters, username and password, from server1 to serverMain.
In server1, I have tried:
String url = "http:// serverMain:8080/MyMainApp/home.seam"; FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getExternalContext().redirect(url); //passing parameter HttpServletRequest req = (HttpServletRequest) facesContext.getExternalContext().getRequest(); HttpServletResponse res = (HttpServletResponse) facesContext.getExternalContext().getResponse(); req.setAttribute("username", value); //test 1 //req.getRequestDispatcher(url).forward(req, res); //test 2 req.getSession().getServletContext().getRequestDispatcher(url).forward(req, res);
To receive the passed parameters, on the serverMain, I have tried:
@Name("userSession") @Scope(ScopeType.SESSION) public class UserSession { public void init() { System.out.println("*** userSession ****** init called."); try { FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletRequest req = (HttpServletRequest) facesContext.getExternalContext().getRequest(); String username = (String) req.getAttribute("username"); System.out.println("req.getAttribute received == " +username); } catch (Exception ex) { ex.printStackTrace(); } } }
But, when the init() method gets called, I get null for the username. I would be grateful for any help ? much appreciated.
Many thanks.