I am new to this site and this is my first question.
I need to make a website, I use java and Struts2, but I'm new to Struts2.
On my site, I have to make requests on Facebook and receive authentication using OAuth.
I perform the whole process (authenticate and request secure resources) in the method of executing the action page, this process is very complex and has many redirects between Facebook and my network.
The other day I read this: "Do not create actions with several methods:" execute ", and the operation you want to perform (for example," createUser ") should be sufficient" (from http://freeopenidea.blogspot.com.es/ 2010/04 / struts2-best-practices.html ).
Most of the code can be called from another part of my site at another moment, because I do this process when I connect for the first time, but I could do it (or something like that) to update the contact list.
1 - Should I create a separate class (and not an action) for the methods that I need and call them from the "execute" method?
2 - Should I store the code on the action page, but in methods other than "execute"? And call this page every time I need to perform some tasks.
I donβt know where to put the code (and I know I have to store accessToken. I just paste the code to show complexity, but I donβt look at the fix).
public String execute() throws Exception{ if (code!=null){ Verifier verifier = new Verifier(code); //get the accessToken to do requests Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); OAuthRequest requestList = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, requestList); Response responseList = requestList.send(); if (responseList.getCode() == 200){ //I get the Friends List JsonParse parser = new JsonParse(); JSONObject json = (JSONObject) JSONSerializer.toJSON(responseList.getBody()); JSONArray datos = json.getJSONArray("data"); for (Object o : datos) {//for every friend of the list I do this JSONObject elem = (JSONObject) o; String id = elem.getString("id"); OAuthRequest requestFriend = new OAuthRequest(Verb.GET,"https://graph.facebook.com/"+id); service.signRequest(accessToken, requestFriend); Response responseFriend = requestFriend.send(); if (responseFriend.getCode() == 200){ JsonParse parserAux = new JsonParse(); PerfilContacto pcBean = parserAux.parseFacebookElement(responseFriend.getBody()); pcDAO.insertarContacto(pcBean); } } } return SUCCESS; } else return ERROR; }