|
14 | 14 |
|
15 | 15 | package com.google.api.services.samples.calendar.appengine.server;
|
16 | 16 |
|
17 |
| -import com.google.api.client.extensions.auth.helpers.ThreeLeggedFlow; |
18 |
| -import com.google.api.client.extensions.servlet.auth.AbstractFlowUserServlet; |
19 |
| -import com.google.api.client.googleapis.extensions.auth.helpers.oauth2.draft10.GoogleOAuth2ThreeLeggedFlow; |
20 |
| -import com.google.api.client.http.HttpTransport; |
21 |
| -import com.google.api.client.json.JsonFactory; |
22 |
| -import com.google.api.services.calendar.CalendarUrl; |
23 |
| -import com.google.api.services.samples.shared.appengine.AppEngineUtils; |
24 |
| -import com.google.api.services.samples.shared.appengine.OAuth2ClientCredentials; |
| 17 | +import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; |
| 18 | +import com.google.api.client.extensions.appengine.auth.oauth2.AbstractAppEngineAuthorizationCodeServlet; |
25 | 19 | import com.google.appengine.api.users.UserService;
|
26 | 20 | import com.google.appengine.api.users.UserServiceFactory;
|
27 | 21 |
|
28 | 22 | import java.io.IOException;
|
29 | 23 | import java.io.PrintWriter;
|
30 | 24 |
|
31 |
| -import javax.jdo.PersistenceManagerFactory; |
32 | 25 | import javax.servlet.ServletException;
|
33 | 26 | import javax.servlet.http.HttpServletRequest;
|
34 | 27 | import javax.servlet.http.HttpServletResponse;
|
|
38 | 31 | *
|
39 | 32 | * @author Yaniv Inbar
|
40 | 33 | */
|
41 |
| -public class CalendarAppEngineSample extends AbstractFlowUserServlet { |
| 34 | +public class CalendarAppEngineSample extends AbstractAppEngineAuthorizationCodeServlet { |
| 35 | + |
42 | 36 | static final String APP_NAME = "Google Calendar Data API Sample Web Client";
|
43 | 37 |
|
44 | 38 | static final String GWT_MODULE_NAME = "calendar";
|
45 | 39 |
|
46 | 40 | private static final long serialVersionUID = 1L;
|
47 | 41 |
|
48 | 42 | @Override
|
49 |
| - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { |
| 43 | + protected void doGet(HttpServletRequest request, HttpServletResponse response) |
| 44 | + throws IOException { |
50 | 45 | response.setContentType("text/html");
|
51 | 46 | response.setCharacterEncoding("UTF-8");
|
52 | 47 | PrintWriter writer = response.getWriter();
|
53 | 48 | writer.println("<!doctype html><html><head>");
|
54 | 49 | writer.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
|
55 | 50 | writer.println("<title>" + APP_NAME + "</title>");
|
56 |
| - writer.println("<link type=\"text/css\" rel=\"stylesheet\" href=\"" + GWT_MODULE_NAME |
57 |
| - + ".css\">"); |
| 51 | + writer.println( |
| 52 | + "<link type=\"text/css\" rel=\"stylesheet\" href=\"" + GWT_MODULE_NAME + ".css\">"); |
58 | 53 | writer.println("<script type=\"text/javascript\" language=\"javascript\" " + "src=\""
|
59 | 54 | + GWT_MODULE_NAME + "/" + GWT_MODULE_NAME + ".nocache.js\"></script>");
|
60 | 55 | writer.println("</head><body>");
|
61 | 56 | UserService userService = UserServiceFactory.getUserService();
|
62 | 57 | writer.println("<div class=\"header\"><b>" + request.getUserPrincipal().getName() + "</b> | "
|
63 |
| - + "<a href=\"" + userService.createLogoutURL(Utils.getFullURL(request)) |
| 58 | + + "<a href=\"" + userService.createLogoutURL(request.getRequestURL().toString()) |
64 | 59 | + "\">Log out</a> | "
|
65 |
| - + "<a href=\"http://code.google.com/p/google-api-java-client/source/browse?repo=" |
66 |
| - + "samples#hg/calendar-appengine-sample\">See source code for " + "this sample</a></div>"); |
| 60 | + + "<a href=\"http://code.google.com/p/google-api-java-client/source/browse" |
| 61 | + + "/calendar-appengine-sample?repo=samples\">See source code for " |
| 62 | + + "this sample</a></div>"); |
67 | 63 | writer.println("<div id=\"main\"/>");
|
68 | 64 | writer.println("</body></html>");
|
69 | 65 | }
|
70 | 66 |
|
71 | 67 | @Override
|
72 |
| - protected PersistenceManagerFactory getPersistenceManagerFactory() { |
73 |
| - return AppEngineUtils.getPersistenceManagerFactory(); |
74 |
| - } |
75 |
| - |
76 |
| - @Override |
77 |
| - protected ThreeLeggedFlow newFlow(String userId) throws IOException { |
78 |
| - return new GoogleOAuth2ThreeLeggedFlow(userId, OAuth2ClientCredentials.getClientId(), |
79 |
| - OAuth2ClientCredentials.getClientSecret(), CalendarUrl.ROOT_URL, Utils.getCallbackUrl()); |
80 |
| - } |
81 |
| - |
82 |
| - @Override |
83 |
| - protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, |
84 |
| - ServletException { |
85 |
| - Utils.setCallbackUrl(req); |
86 |
| - super.service(req, resp); |
87 |
| - } |
88 |
| - |
89 |
| - @Override |
90 |
| - protected String getUserId() { |
91 |
| - return Utils.getUserId(); |
92 |
| - } |
93 |
| - |
94 |
| - @Override |
95 |
| - protected HttpTransport newHttpTransportInstance() { |
96 |
| - return AppEngineUtils.getHttpTransport(); |
| 68 | + protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException { |
| 69 | + return Utils.getRedirectUri(req); |
97 | 70 | }
|
98 | 71 |
|
99 | 72 | @Override
|
100 |
| - protected JsonFactory newJsonFactoryInstance() { |
101 |
| - return AppEngineUtils.getJsonFactory(); |
| 73 | + protected AuthorizationCodeFlow initializeFlow() throws IOException { |
| 74 | + return Utils.newFlow(); |
102 | 75 | }
|
103 | 76 | }
|
0 commit comments