You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Funk <ma...@googlemail.com> on 2010/03/26 14:32:24 UTC

Re: Wicket on GAE with Facebook Connect - doesnt work after deploying / HTTP 500 error

you are aware of this?
http://www.danwalmsley.com/2009/04/08/apache-wicket-on-google-app-engine-for-java/

2010/3/26 christoph glass <ma...@googlemail.com>

> Hi everyone,
>
> I'm trying to run a simple Wicket Application with Facebook Connect on
> Google App Engine.
>
> So far it runs local, but when I deploy to Google Facebook Connect wont
> work.
>
> I cant find any examples for using wicket with gae and facebook on the
> web. Is anyone here who successfully made it?
>
> Here is the output from ajax debug window:
>
> ---
> INFO: Using XMLHttpRequest transport
> INFO:
> INFO:
> Initiating Ajax GET request on
> ?wicket:interface=wicket-9:36:fbconnectpanel::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true&random=0.6834228196057528
> INFO: Invoking pre-call handler(s)...
> ERROR: Received Ajax response with code: 500
> ERROR: 500 error had text:
> <html><head>
> <meta http-equiv="content-type" content="text/html;charset=utf-8">
> <title>500 Server Error</title>
> </head>
> <body text=#000000 bgcolor=#ffffff>
> <h1>Error: Server Error</h1>
> <h2>The server encountered an error and could not complete your
> request.<p>If the problem persists, please <A HREF="
> http://code.google.com/appengine/community.html">report</A> your problem
> and mention this error message and the query that caused it.</h2>
> <h2></h2>
> </body></html>
>
> INFO: Invoking post-call handler(s)...
> INFO: Invoking failure handler(s)...
> ---
>
> FacebookConnectPanel.java -> took the most from
> http://cwiki.apache.org/WICKET/adding-facebook-connect.html
>
> ---
> package polizeiwache.sites.auth.facebookconnect;
>
> import java.io.IOException;
>
>
> import java.util.ArrayList;
> import java.util.HashSet;
> import java.util.List;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> import org.apache.wicket.Page;
> import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.behavior.SimpleAttributeModifier;
> import org.apache.wicket.markup.html.WebMarkupContainer;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.panel.Panel;
> import org.apache.wicket.protocol.http.WebResponse;
> import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
> import org.json.JSONArray;
> import org.json.JSONException;
> import org.json.JSONObject;
> import
>
> org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
> import org.springframework.security.core.GrantedAuthority;
> import org.springframework.security.core.authority.GrantedAuthorityImpl;
> import org.springframework.security.core.context.SecurityContext;
> import org.springframework.security.core.context.SecurityContextHolder;
> import org.springframework.security.core.context.SecurityContextImpl;
>
> import pojos.FacebookUser;
>
> //import com.facebook.api.FacebookException;
> //import com.facebook.api.FacebookJsonRestClient;
> //import com.facebook.api.FacebookWebappHelper;
> //import com.facebook.api.ProfileField;
>
> import com.google.code.facebookapi.FacebookException;
> import com.google.code.facebookapi.FacebookJsonRestClient;
> import com.google.code.facebookapi.FacebookWebappHelper;
> import com.google.code.facebookapi.ProfileField;
>
>
> //import
>
> com.google.appengine.repackaged.org.apache.commons.logging.impl.LogFactoryImpl;
>
> /**
>  * @see http://cwiki.apache.org/WICKET/adding-facebook-connect.html
>  * @author christoph
>  *
>  */
>
> @SuppressWarnings("deprecation")
> public class FacebookConnectPanel extends Panel
> {
>
>        /**
>         *
>         */
>        private static final long serialVersionUID = -5912681574741410118L;
>
>        //private static final
> com.google.appengine.repackaged.org.apache.commons.logging.Log log =
> LogFactoryImpl.getLog(FacebookConnectPanel.class);
>    private WebMarkupContainer fbloginDiv;
>    private Label fblogin;
>
>        /**
>         *
>         * @param id
>         */
>
>        public FacebookConnectPanel(String id) {
>                super(id);
>        }
>
>        /**
>     * This method will the panel
>     */
>
>    public void createPanel() {
>        fbloginDiv = new WebMarkupContainer("fbloginDiv");
>        fbloginDiv.setOutputMarkupId(true).setMarkupId("fbloginDiv");
>        fblogin = new Label("fblogin", "<fb:login-button
> onlogin='callWicket();'></fb:login-button>");
>        fblogin.setEscapeModelStrings(false);
>        fblogin.setOutputMarkupId(true);
>        if (isAuthenticated())
>        {
>            fbloginDiv.add(new SimpleAttributeModifier("style",
> "display:none;"));
>        }
>        fbloginDiv.add(fblogin);
>        addOrReplace(fbloginDiv);
>
>        /**
>         * This will only be called after they're logged in via facebook
>         */
>
>        final AbstractDefaultAjaxBehavior behave = new
> AbstractDefaultAjaxBehavior()
>        {
>            /**
>                         *
>                         */
>                        private static final long serialVersionUID =
> -486358491644699655L;
>
>                        protected void respond(final AjaxRequestTarget
> target)
>            {
>                // deal with facebook
>                try {
>
>  handleFacebookCallback(target.getPage());
>                                } catch (IOException e) {
>                                        e.printStackTrace();
>                                }
>                fbloginDiv.add(new SimpleAttributeModifier("style",
> "display:none;"));
>                target.addComponent(fbloginDiv);
>            }
>        };
>        add(behave);
>        CharSequence url = behave.getCallbackUrl();
>        StringBuffer sb = new StringBuffer();
>        sb.append("function callWicket() { \n");
>        sb.append("     var wcall = wicketAjaxGet('");
>        sb.append(url);
>        sb.append("', function() { }, function() { });");
>        sb.append("    }");
>        Label fbcallback = new Label("fbcallback", sb.toString());
>        fbcallback.setOutputMarkupId(true);
>        fbcallback.setEscapeModelStrings(false);
>        add(fbcallback);
>
>    }
>
>    /**
>     * All that we do to log you in from facebook. I put my fbook.key
> and fbook.secret in the
>     * properties file.
>     * @param thePage
>     * @throws IOException
>     */
>
>    public void handleFacebookCallback(Page thePage) throws IOException
> {
>
>        HttpServletRequest req = ((ServletWebRequest)
> thePage.getRequest()).getHttpServletRequest();
>        HttpServletResponse res = ((WebResponse)
> thePage.getResponse()).getHttpServletResponse();
>        String api = getLocalizer().getString("fbook.key", this);
>        String secret = getLocalizer().getString("fbook.secret",
> this);
>        FacebookWebappHelper<Object> helper =
> FacebookWebappHelper.newInstanceJson(req, res, api, secret);
>
>        // make sure the login worked
>        if (helper.isLogin()) {
>            FacebookJsonRestClient facebookClient =
> (FacebookJsonRestClient) helper.getFacebookRestClient();
>            long id;
>            try {
>                // grab the logged in user's id
>                id = facebookClient.users_getLoggedInUser();
>
>                // you can bundle ajax calls...
>                facebookClient.beginBatch();
>
>                // i'm going to call the users.getInfo fb api call, just
> to make sure it works
>                ArrayList<Long> ids = new ArrayList<Long>();
>                ids.add(new Long(id));
>
>                // put together a set of fields for fb to return
>                HashSet<ProfileField> fields = new
> HashSet<ProfileField>();
>                fields.add(ProfileField.FIRST_NAME);
>                fields.add(ProfileField.LAST_NAME);
>
>                // get the user data
>                facebookClient.users_getInfo(ids, fields);
>
>                // execute the batch (which also terminates batch mode
> until beginBatch is called again)
>                List<? extends Object> batchResponse =
> facebookClient.executeBatch(false);
>                JSONArray userInfo = (JSONArray) batchResponse.get(0);
>                JSONObject user = userInfo.getJSONObject(0);
>
>                // a pojo user object
> //                User theUser = new User();
>                FacebookUser theUser = new FacebookUser();
>                String username = user.getString("facebookVorname");
>                theUser.setVorname(username);
>
>                // fb emails are proxy, my app needs some kind of holder
>                theUser.setEmail("noreply@facebook.com");
>                theUser.setUserId(new Integer(0));
>                theUser.setFacebook(true);
>                theUser.setFacebookId(id);
>
>                // we use spring, so here we give basic access to the
> facebook user.
>                List<GrantedAuthority> gaList = new
> ArrayList<GrantedAuthority>();
>                gaList.add(new GrantedAuthorityImpl("STANDARD"));
>                theUser.setAuthorities(gaList.toArray(new
> GrantedAuthority[] {}));
>                GrantedAuthority[] ga = theUser.getAuthorities();
>                UsernamePasswordAuthenticationToken authentication = new
> UsernamePasswordAuthenticationToken(theUser, theUser, ga);
>                SecurityContext context = new SecurityContextImpl();
>                context.setAuthentication(authentication);
>                SecurityContextHolder.setContext(context);
>
>            } catch (FacebookException e) {
>                //log.error("facebook issues: " + e);
>            } catch (JSONException e) {
>                //log.error("facebook json issues: " + e);
>            }
>        }
>    }
>
>    /**
>     * Do your own kind of auth check
>     * @return
>     */
>
>    public boolean isAuthenticated() {
>        return SecurityContextHolder.getContext().getAuthentication() !=
> null;
>    }
>
>
> }
> ---
>
> FacebookConnectPanel.html
>
> ---
> <html xmlns:wicket>
> <body>
>  <wicket:panel>
>    <!-- facebook api as of 8/11/09 -->
>        <script
> src="
> http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
> type="text/javascript"></script>
>
>    <!-- function for facebook to execute on login-->
>        <script type="text/javascript" wicket:id="fbcallback">
>    function callWicket() {
>     var wcall = wicketAjaxGet('$url$' + '$args$', function() { },
> function() { });
>    }
>    </script>
>
>        <div id="loginform">
>                <div wicket:id="fbloginDiv" style="display:block;">
>                    <span wicket:id="fblogin">
>
>            <!-- facebool login button -->
>            <fb:login-button onlogin='callWicket();'></fb:login-button>
>            </span>
>
>            <!-- facebook api -->
>                <script type="text/javascript">
>                FB.init(fbook.key "/xd_receiver.htm");
>                </script>
>            </div>
>        </div>
>
>  </wicket:panel>
> </body>
> </html>
>
> ---
>
> Any help would be most welcome.
>
> Thanks and  best regards
> Christoph
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket on GAE with Facebook Connect - doesnt work after deploying / HTTP 500 error

Posted by christoph glass <ma...@googlemail.com>.
You solved it :)

I configured my project some days ago with the instructions from your
link. Now I checked everything carefully again, and noticed that I
forgott the following line in WicketApplication.java

---
super.init();
---

Now it seems to work.

Thank you very much!

Best regards
Christoph



On Fri, 2010-03-26 at 14:32 +0100, Martin Funk wrote:
> you are aware of this?
> http://www.danwalmsley.com/2009/04/08/apache-wicket-on-google-app-engine-for-java/
> 
> 2010/3/26 christoph glass <ma...@googlemail.com>
> 
> > Hi everyone,
> >
> > I'm trying to run a simple Wicket Application with Facebook Connect on
> > Google App Engine.
> >
> > So far it runs local, but when I deploy to Google Facebook Connect wont
> > work.
> >
> > I cant find any examples for using wicket with gae and facebook on the
> > web. Is anyone here who successfully made it?
> >
> > Here is the output from ajax debug window:
> >
> > ---
> > INFO: Using XMLHttpRequest transport
> > INFO:
> > INFO:
> > Initiating Ajax GET request on
> > ?wicket:interface=wicket-9:36:fbconnectpanel::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true&random=0.6834228196057528
> > INFO: Invoking pre-call handler(s)...
> > ERROR: Received Ajax response with code: 500
> > ERROR: 500 error had text:
> > <html><head>
> > <meta http-equiv="content-type" content="text/html;charset=utf-8">
> > <title>500 Server Error</title>
> > </head>
> > <body text=#000000 bgcolor=#ffffff>
> > <h1>Error: Server Error</h1>
> > <h2>The server encountered an error and could not complete your
> > request.<p>If the problem persists, please <A HREF="
> > http://code.google.com/appengine/community.html">report</A> your problem
> > and mention this error message and the query that caused it.</h2>
> > <h2></h2>
> > </body></html>
> >
> > INFO: Invoking post-call handler(s)...
> > INFO: Invoking failure handler(s)...
> > ---
> >
> > FacebookConnectPanel.java -> took the most from
> > http://cwiki.apache.org/WICKET/adding-facebook-connect.html
> >
> > ---
> > package polizeiwache.sites.auth.facebookconnect;
> >
> > import java.io.IOException;
> >
> >
> > import java.util.ArrayList;
> > import java.util.HashSet;
> > import java.util.List;
> >
> > import javax.servlet.http.HttpServletRequest;
> > import javax.servlet.http.HttpServletResponse;
> >
> > import org.apache.wicket.Page;
> > import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
> > import org.apache.wicket.ajax.AjaxRequestTarget;
> > import org.apache.wicket.behavior.SimpleAttributeModifier;
> > import org.apache.wicket.markup.html.WebMarkupContainer;
> > import org.apache.wicket.markup.html.basic.Label;
> > import org.apache.wicket.markup.html.panel.Panel;
> > import org.apache.wicket.protocol.http.WebResponse;
> > import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
> > import org.json.JSONArray;
> > import org.json.JSONException;
> > import org.json.JSONObject;
> > import
> >
> > org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
> > import org.springframework.security.core.GrantedAuthority;
> > import org.springframework.security.core.authority.GrantedAuthorityImpl;
> > import org.springframework.security.core.context.SecurityContext;
> > import org.springframework.security.core.context.SecurityContextHolder;
> > import org.springframework.security.core.context.SecurityContextImpl;
> >
> > import pojos.FacebookUser;
> >
> > //import com.facebook.api.FacebookException;
> > //import com.facebook.api.FacebookJsonRestClient;
> > //import com.facebook.api.FacebookWebappHelper;
> > //import com.facebook.api.ProfileField;
> >
> > import com.google.code.facebookapi.FacebookException;
> > import com.google.code.facebookapi.FacebookJsonRestClient;
> > import com.google.code.facebookapi.FacebookWebappHelper;
> > import com.google.code.facebookapi.ProfileField;
> >
> >
> > //import
> >
> > com.google.appengine.repackaged.org.apache.commons.logging.impl.LogFactoryImpl;
> >
> > /**
> >  * @see http://cwiki.apache.org/WICKET/adding-facebook-connect.html
> >  * @author christoph
> >  *
> >  */
> >
> > @SuppressWarnings("deprecation")
> > public class FacebookConnectPanel extends Panel
> > {
> >
> >        /**
> >         *
> >         */
> >        private static final long serialVersionUID = -5912681574741410118L;
> >
> >        //private static final
> > com.google.appengine.repackaged.org.apache.commons.logging.Log log =
> > LogFactoryImpl.getLog(FacebookConnectPanel.class);
> >    private WebMarkupContainer fbloginDiv;
> >    private Label fblogin;
> >
> >        /**
> >         *
> >         * @param id
> >         */
> >
> >        public FacebookConnectPanel(String id) {
> >                super(id);
> >        }
> >
> >        /**
> >     * This method will the panel
> >     */
> >
> >    public void createPanel() {
> >        fbloginDiv = new WebMarkupContainer("fbloginDiv");
> >        fbloginDiv.setOutputMarkupId(true).setMarkupId("fbloginDiv");
> >        fblogin = new Label("fblogin", "<fb:login-button
> > onlogin='callWicket();'></fb:login-button>");
> >        fblogin.setEscapeModelStrings(false);
> >        fblogin.setOutputMarkupId(true);
> >        if (isAuthenticated())
> >        {
> >            fbloginDiv.add(new SimpleAttributeModifier("style",
> > "display:none;"));
> >        }
> >        fbloginDiv.add(fblogin);
> >        addOrReplace(fbloginDiv);
> >
> >        /**
> >         * This will only be called after they're logged in via facebook
> >         */
> >
> >        final AbstractDefaultAjaxBehavior behave = new
> > AbstractDefaultAjaxBehavior()
> >        {
> >            /**
> >                         *
> >                         */
> >                        private static final long serialVersionUID =
> > -486358491644699655L;
> >
> >                        protected void respond(final AjaxRequestTarget
> > target)
> >            {
> >                // deal with facebook
> >                try {
> >
> >  handleFacebookCallback(target.getPage());
> >                                } catch (IOException e) {
> >                                        e.printStackTrace();
> >                                }
> >                fbloginDiv.add(new SimpleAttributeModifier("style",
> > "display:none;"));
> >                target.addComponent(fbloginDiv);
> >            }
> >        };
> >        add(behave);
> >        CharSequence url = behave.getCallbackUrl();
> >        StringBuffer sb = new StringBuffer();
> >        sb.append("function callWicket() { \n");
> >        sb.append("     var wcall = wicketAjaxGet('");
> >        sb.append(url);
> >        sb.append("', function() { }, function() { });");
> >        sb.append("    }");
> >        Label fbcallback = new Label("fbcallback", sb.toString());
> >        fbcallback.setOutputMarkupId(true);
> >        fbcallback.setEscapeModelStrings(false);
> >        add(fbcallback);
> >
> >    }
> >
> >    /**
> >     * All that we do to log you in from facebook. I put my fbook.key
> > and fbook.secret in the
> >     * properties file.
> >     * @param thePage
> >     * @throws IOException
> >     */
> >
> >    public void handleFacebookCallback(Page thePage) throws IOException
> > {
> >
> >        HttpServletRequest req = ((ServletWebRequest)
> > thePage.getRequest()).getHttpServletRequest();
> >        HttpServletResponse res = ((WebResponse)
> > thePage.getResponse()).getHttpServletResponse();
> >        String api = getLocalizer().getString("fbook.key", this);
> >        String secret = getLocalizer().getString("fbook.secret",
> > this);
> >        FacebookWebappHelper<Object> helper =
> > FacebookWebappHelper.newInstanceJson(req, res, api, secret);
> >
> >        // make sure the login worked
> >        if (helper.isLogin()) {
> >            FacebookJsonRestClient facebookClient =
> > (FacebookJsonRestClient) helper.getFacebookRestClient();
> >            long id;
> >            try {
> >                // grab the logged in user's id
> >                id = facebookClient.users_getLoggedInUser();
> >
> >                // you can bundle ajax calls...
> >                facebookClient.beginBatch();
> >
> >                // i'm going to call the users.getInfo fb api call, just
> > to make sure it works
> >                ArrayList<Long> ids = new ArrayList<Long>();
> >                ids.add(new Long(id));
> >
> >                // put together a set of fields for fb to return
> >                HashSet<ProfileField> fields = new
> > HashSet<ProfileField>();
> >                fields.add(ProfileField.FIRST_NAME);
> >                fields.add(ProfileField.LAST_NAME);
> >
> >                // get the user data
> >                facebookClient.users_getInfo(ids, fields);
> >
> >                // execute the batch (which also terminates batch mode
> > until beginBatch is called again)
> >                List<? extends Object> batchResponse =
> > facebookClient.executeBatch(false);
> >                JSONArray userInfo = (JSONArray) batchResponse.get(0);
> >                JSONObject user = userInfo.getJSONObject(0);
> >
> >                // a pojo user object
> > //                User theUser = new User();
> >                FacebookUser theUser = new FacebookUser();
> >                String username = user.getString("facebookVorname");
> >                theUser.setVorname(username);
> >
> >                // fb emails are proxy, my app needs some kind of holder
> >                theUser.setEmail("noreply@facebook.com");
> >                theUser.setUserId(new Integer(0));
> >                theUser.setFacebook(true);
> >                theUser.setFacebookId(id);
> >
> >                // we use spring, so here we give basic access to the
> > facebook user.
> >                List<GrantedAuthority> gaList = new
> > ArrayList<GrantedAuthority>();
> >                gaList.add(new GrantedAuthorityImpl("STANDARD"));
> >                theUser.setAuthorities(gaList.toArray(new
> > GrantedAuthority[] {}));
> >                GrantedAuthority[] ga = theUser.getAuthorities();
> >                UsernamePasswordAuthenticationToken authentication = new
> > UsernamePasswordAuthenticationToken(theUser, theUser, ga);
> >                SecurityContext context = new SecurityContextImpl();
> >                context.setAuthentication(authentication);
> >                SecurityContextHolder.setContext(context);
> >
> >            } catch (FacebookException e) {
> >                //log.error("facebook issues: " + e);
> >            } catch (JSONException e) {
> >                //log.error("facebook json issues: " + e);
> >            }
> >        }
> >    }
> >
> >    /**
> >     * Do your own kind of auth check
> >     * @return
> >     */
> >
> >    public boolean isAuthenticated() {
> >        return SecurityContextHolder.getContext().getAuthentication() !=
> > null;
> >    }
> >
> >
> > }
> > ---
> >
> > FacebookConnectPanel.html
> >
> > ---
> > <html xmlns:wicket>
> > <body>
> >  <wicket:panel>
> >    <!-- facebook api as of 8/11/09 -->
> >        <script
> > src="
> > http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
> > type="text/javascript"></script>
> >
> >    <!-- function for facebook to execute on login-->
> >        <script type="text/javascript" wicket:id="fbcallback">
> >    function callWicket() {
> >     var wcall = wicketAjaxGet('$url$' + '$args$', function() { },
> > function() { });
> >    }
> >    </script>
> >
> >        <div id="loginform">
> >                <div wicket:id="fbloginDiv" style="display:block;">
> >                    <span wicket:id="fblogin">
> >
> >            <!-- facebool login button -->
> >            <fb:login-button onlogin='callWicket();'></fb:login-button>
> >            </span>
> >
> >            <!-- facebook api -->
> >                <script type="text/javascript">
> >                FB.init(fbook.key "/xd_receiver.htm");
> >                </script>
> >            </div>
> >        </div>
> >
> >  </wicket:panel>
> > </body>
> > </html>
> >
> > ---
> >
> > Any help would be most welcome.
> >
> > Thanks and  best regards
> > Christoph
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org