Facebook Connect with seam
bbasdeo Jun 23, 2010 2:34 AMHello everyone!
I am working on a Seam project (Seam 2.1.2) into which I need to integrate Facebook connect and by-pass the current registration process when uses are logged in through facebook connect.
I don't want to use the javascript api provided by Facebook, but would like to send and get response through the HTTP object and thus handle the request through Java nstead of javascript.
I am currently using the facebook-java-api-3.0.1.jar
I wrote the following :
package com.testntrust.actions.registration; import java.io.IOException; import javax.faces.context.FacesContext; import javax.interceptor.Interceptors; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.ejb.SeamInterceptor; import com.google.code.facebookapi.FacebookParam; import com.google.code.facebookapi.FacebookXmlRestClient; @Scope(ScopeType.EVENT) @Interceptors(SeamInterceptor.class) @Name("facebookUserFilter") public class FacebookUserFilter { private final String secret = "e03ae7ac59932b91d7663dc9bf9aa9e7"; private final String apiKey ="d02ce85f646e19d83a63b2af0fa190a6"; private static Logger log; @In private FacesContext facesContext; private HttpServletRequest request; @Create public void setup() { request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); } public String loadUserJAAS() { HttpSession session = request.getSession(); FacebookXmlRestClient client = (FacebookXmlRestClient) session .getAttribute("facebookClient"); if (client == null) { String sessionKey = request .getParameter(FacebookParam.SESSION_KEY.toString()); String authToken = request.getParameter("auth_token"); if (sessionKey == null && authToken == null) { //response.sendRedirect(loginPage); return "ok"; } else { try { if (sessionKey != null) { client = new FacebookXmlRestClient(apiKey, secret, sessionKey); } else { client = new FacebookXmlRestClient(apiKey, secret); client.auth_getSession(authToken); } // client.setIsDesktop(false); session.setAttribute("facebookClient", client); } catch (Exception fe) { log.error("Unable to log into facebook", fe); } } } return "ok2"; } }
accessed the method thus:
<h:outputText value="#{facebookUserFilter.loadUserJAAS()}" />
but am getting classloaders exception:
Caused by: javax.el.ELException: /connexion.xhtml @107,67 value="#{facebookUserFilter.loadUserJAAS()}": java.lang.reflect.InvocationTargetException at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76) at javax.faces.component.UIOutput.getValue(UIOutput.java:173) ... 68 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at com.testntrust.actions.registration.FacebookUserFilter_$$_javassist_seam_15.loadUserJAAS(FacebookUserFilter_$$_javassist_seam_15.java) at sun.reflect.NativeMet 10:01:25,041 ERROR [STDERR] hodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280) at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59) at org.jboss.el.parser.AstValue.getValue(AstValue.java:67) at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71) ... 69 more Caused by: java.lang.NoClassDefFoundError: com/google/code/facebookapi/FacebookParam at com.testntrust.actions.registration.FacebookUserFilter.loadUserJAAS(FacebookUserFilter.java:106) ... 98 more Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: com.google.code.facebookapi.FacebookParam at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:306) at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521) at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 99 more
I would like to know which api should I use for this purpose in seam. Are there any example which I can follow for the integration of seam and facebook connect.
Any help would be highly appreciated
Rgds
Neerou