google app engine - NotSerializableException FacebookConnectionFactory -


i'm using jsf 2.0, spring social facebook , google app engine. getting error when execute code:

web.xml:

    <welcome-file-list>         <welcome-file>login.jsf</welcome-file>    </welcome-file-list> 

login.jsf:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:prime="http://primefaces.org/ui">        <h:outputtext value="#{user.text}" />  </html> 

usersessionmbean:

@managedbean(name = "user") @sessionscoped public final class usersessionmbean implements serializable {  oauth2operations oauthoperations = null; facebookconnectionfactory connectionfactory = null; private facebook fbusersession = null;  private string text = "loging...";  public usersessionmbean() {     connectionfactory = new facebookconnectionfactory("my_key",             "my_secret");     oauthoperations = connectionfactory.getoauthoperations(); }   public void facebooklogin() {      try {          externalcontext ec = facescontext.getcurrentinstance()                 .getexternalcontext();          httpservletrequest httpservletrequest = null;         object request = ec.getrequest();          if (request instanceof httpservletrequest) {             httpservletrequest = (httpservletrequest) request;         }          string code = httpservletrequest.getparameter("code");          if (stringutil.isnotblankstr(code)) {              // upon receiving callback provider:             accessgrant accessgrant = oauthoperations.exchangeforaccess(                     code, "http://localhost:8888/", null);              connection<facebook> connection = connectionfactory                     .createconnection(accessgrant);              setfbusersession(connection != null ? connection.getapi()                     : new facebooktemplate());              ec.getsessionmap().put("fbusersession", fbusersession);              ec.redirect("init.jsf");          } else {              oauth2parameters params = new oauth2parameters();             params.setredirecturi("http://localhost:8888/");              params.setscope("publish_stream");             params.setscope("email");             params.setscope("offline_access");              string authorizeurl = oauthoperations.buildauthorizeurl(                     granttype.authorization_code, params);             ec.redirect(authorizeurl);             return;         }     } catch (ioexception e) {         e.printstacktrace();     } }   public string gettext() {     facebooklogin();     return text; } 

error occurs in:

ec.getsessionmap().put("fbusersession", fbusersession); 

error:

23/08/2013 21:36:36 com.google.apphosting.utils.jetty.jettylogger warn aviso: / java.lang.runtimeexception: java.io.notserializableexception:     org.springframework.social.facebook.connect.facebookconnectionfactory        @ com.google.appengine.tools.development.serializableobjectsonlyhashsessionmanager$serializableobjectsonlyhttpsession.checkcanserialize(serializableobjectsonlyhashsessionmanager.java:66)       @ com.google.appengine.tools.development.serializableobjectsonlyhashsessionmanager$serializableobjectsonlyhttpsession.setattribute(serializableobjectsonlyhashsessionmanager.java:43)       @ com.sun.faces.context.sessionmap.put(sessionmap.java:141)       @ com.sun.faces.context.sessionmap.put(sessionmap.java:61)       @ com.sun.faces.mgbean.beanmanager$scopemanager$sessionscopehandler.handle(beanmanager.java:576)       @ com.sun.faces.mgbean.beanmanager$scopemanager.pushtoscope(beanmanager.java:458)       @ com.sun.faces.mgbean.beanmanager.createandpush(beanmanager.java:410)       @ com.sun.faces.mgbean.beanmanager.create(beanmanager.java:269)       @ com.sun.faces.el.managedbeanelresolver.resolvebean(managedbeanelresolver.java:244)       @ com.sun.faces.el.managedbeanelresolver.getvalue(managedbeanelresolver.java:116)       @ com.sun.faces.el.demuxcompositeelresolver._getvalue(demuxcompositeelresolver.java:176)       @ com.sun.faces.el.demuxcompositeelresolver.getvalue(demuxcompositeelresolver.java:203)       @ org.apache.el.parser.astidentifier.getvalue(astidentifier.java:68)       @ org.apache.el.parser.astvalue.getvalue(astvalue.java:112)       @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:186)       @ com.sun.faces.facelets.el.tagvalueexpression.getvalue(tagvalueexpression.java:109)       @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:194)       @ javax.faces.component.componentstatehelper.eval(componentstatehelper.java:182)       @ javax.faces.component.uioutput.getvalue(uioutput.java:169)       @ com.sun.faces.renderkit.html_basic.htmlbasicinputrenderer.getvalue(htmlbasicinputrenderer.java:205)       @ com.sun.faces.renderkit.html_basic.htmlbasicrenderer.getcurrentvalue(htmlbasicrenderer.java:355)       @ com.sun.faces.renderkit.html_basic.htmlbasicrenderer.encodeend(htmlbasicrenderer.java:164)       @ javax.faces.component.uicomponentbase.encodeend(uicomponentbase.java:875)       @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1786)       @ javax.faces.component.uicomponent.encodeall(uicomponent.java:1782)       @ com.sun.faces.application.view.faceletviewhandlingstrategy.renderview(faceletviewhandlingstrategy.java:424)       @ com.sun.faces.application.view.multiviewhandler.renderview(multiviewhandler.java:124)       @ com.sun.faces.lifecycle.renderresponsephase.execute(renderresponsephase.java:121)       @ com.sun.faces.lifecycle.phase.dophase(phase.java:101)       @ com.sun.faces.lifecycle.lifecycleimpl.render(lifecycleimpl.java:139)       @ javax.faces.webapp.facesservlet.service(facesservlet.java:594)       @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1166)       @ com.google.appengine.tools.development.devappservermodulesfilter.dodirectrequest(devappservermodulesfilter.java:368)       @ com.google.appengine.tools.development.devappservermodulesfilter.dodirectmodulerequest(devappservermodulesfilter.java:351)       @ com.google.appengine.tools.development.devappservermodulesfilter.dofilter(devappservermodulesfilter.java:116)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:388)       @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.java:216)       @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:182)       @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:765)       @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)       @ com.google.appengine.tools.development.devappenginewebappcontext.handle(devappenginewebappcontext.java:97)       @ org.mortbay.jetty.servlet.dispatcher.forward(dispatcher.java:327)       @ org.mortbay.jetty.servlet.dispatcher.forward(dispatcher.java:126)       @ com.google.appengine.tools.development.staticfileutils.servewelcomefileasforward(staticfileutils.java:82)       @ com.google.appengine.tools.development.localresourcefileservlet.maybeservewelcomefile(localresourcefileservlet.java:247)       @ com.google.appengine.tools.development.localresourcefileservlet.doget(localresourcefileservlet.java:120)       @ javax.servlet.http.httpservlet.service(httpservlet.java:617)       @ javax.servlet.http.httpservlet.service(httpservlet.java:717)       @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1166)       @ br.com.caronagem.config.httpifmodifiedsincefix.dofilter(httpifmodifiedsincefix.java:54)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.googlecode.objectify.cache.asynccachefilter.dofilter(asynccachefilter.java:59)       @ com.googlecode.objectify.objectifyfilter.dofilter(objectifyfilter.java:49)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.api.socket.dev.devsocketfilter.dofilter(devsocketfilter.java:74)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.tools.development.responserewriterfilter.dofilter(responserewriterfilter.java:123)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.tools.development.headerverificationfilter.dofilter(headerverificationfilter.java:34)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.api.blobstore.dev.serveblobfilter.dofilter(serveblobfilter.java:63)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.apphosting.utils.servlet.transactioncleanupfilter.dofilter(transactioncleanupfilter.java:43)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.tools.development.staticfilefilter.dofilter(staticfilefilter.java:125)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ com.google.appengine.tools.development.devappservermodulesfilter.dodirectrequest(devappservermodulesfilter.java:368)       @ com.google.appengine.tools.development.devappservermodulesfilter.dodirectmodulerequest(devappservermodulesfilter.java:351)       @ com.google.appengine.tools.development.devappservermodulesfilter.dofilter(devappservermodulesfilter.java:116)       @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)       @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:388)       @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.java:216)       @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:182)       @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:765)       @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)       @ com.google.appengine.tools.development.devappenginewebappcontext.handle(devappenginewebappcontext.java:97)       @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)       @ com.google.appengine.tools.development.jettycontainerservice$apiproxyhandler.handle(jettycontainerservice.java:485)       @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)       @ org.mortbay.jetty.server.handle(server.java:326)       @ org.mortbay.jetty.httpconnection.handlerequest(httpconnection.java:542)       @ org.mortbay.jetty.httpconnection$requesthandler.headercomplete(httpconnection.java:923)       @ org.mortbay.jetty.httpparser.parsenext(httpparser.java:547)       @ org.mortbay.jetty.httpparser.parseavailable(httpparser.java:212)       @ org.mortbay.jetty.httpconnection.handle(httpconnection.java:404)       @ org.mortbay.io.nio.selectchannelendpoint.run(selectchannelendpoint.java:409)       @ org.mortbay.thread.queuedthreadpool$poolthread.run(queuedthreadpool.java:582) caused by: java.io.notserializableexception: org.springframework.social.facebook.connect.facebookconnectionfactory       @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1164)       @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1518)       @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1483)       @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1400)       @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1158)       @ java.io.objectoutputstream.writeobject(objectoutputstream.java:330)       @ com.google.appengine.tools.development.serializableobjectsonlyhashsessionmanager$serializableobjectsonlyhttpsession.checkcanserialize(serializableobjectsonlyhashsessionmanager.java:64) ... 89 more 

the solution simple: not declare non-serializable instances property of serializable class. session scoped beans needs serialize because can stored on harddisk (e.g. on server low memory profile) and/or transferred on network (e.g. on server cluster). however, object represents "connection" can't serialized such thing can't passivated.

you need rewrite session scoped bean such things created , destroyed in method local scope, i.e. entirely inside method block. should never leave method, @ least not public scope (private static helper methods okay).

so, move 3 declarations of oauthoperations, connectionfactory , fbusersession inside facebooklogin() method , not ever pass them outside.

public void facebooklogin() {     oauth2operations oauthoperations = connectionfactory.getoauthoperations();     facebookconnectionfactory connectionfactory = new facebookconnectionfactory("my_key", "my_secret");     facebook fbusersession = null;     // ... 

another cause manually placed fbusersession in http session unclear reason. should not that. fbusersession represents session wherein you can let code interact fb. can't kept open after method finishes. has closed , reopened upon new http request. not represent http session orso. should instead extract desired information fb session , store information (usually, in flavor of string, integer, etc, if necessary wrapped in bean) in session instead. or assign that property of current session scoped bean.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -