I just managed to call the Google Drive API to enable push notifications for the file.
The code that configures push notifications is as follows:
public class SampleServlet extends AbstractAppEngineAuthorizationCodeServlet { private final static Logger logger = Logger.getLogger(SampleServlet.class.getName()); private static final long serialVersionUID = 1L;
After calling the doGet servlets from my browser and logging in, I get this as an answer:
{ "expiration": "1484565747000", "id": SAME_ID_AS_DEFINED_IN_SERVLET, "kind": "api#channel", "resourceId": A_NEW_ID, "resourceUri": "https:\/\/www.googleapis.com\/drive\/v3\/files\/FILE_ID?acknowledgeAbuse=false&alt=json" }
The next step is to determine my controller, which receives notifications when the file changes. Looks like that:
@RestController @RequestMapping("/drive") public class ConcreteFileWatchController implements FileWatchController { private final static Logger logger = Logger.getLogger(ConcreteFileWatchController.class.getName()); @RequestMapping(method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { logger.info("Received watch call"); } }
Finally, I try to modify the file after the application is deployed (it is deployed to the Google App Engine), and after viewing the logs in GAE, I see that there was a call. However, my receiving method does not work. I see only 302 in the log with large json attached to it. It is impossible to see any error, except that I do not notice that my method is called. The path even looks correct in the log. What can i do wrong?
Error Details:
When I go to the log page in Google Cloud, I see this message 302:
11:34:35.957 POST 302 0 B 22 ms APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html) /drive 10.72.94.97 - - [16/Jan/2017:11:34:35 +0100] "POST /drive HTTP/1.1" 302 - - "APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)" "mydomain.appspot.com" ms=22 cpu_ms=0 cpm_usd=0 loading_request=0 instance=- app_engine_release=1.9.48 trace_id=d0e888dd3989e353344e40e41758fdf4
There is also json looking like this:
{ protoPayload: { @ type: "type.googleapis.com/google.appengine.logging.v1.RequestLog" appId: "p~blabla" versionId: "201t113050" requestId: "587ca1bb00ff05706f727465726261636b656e640001323031373031313674313133303530000100" ip: "10.76.94.97" startTime: "2017-01-16T10:34:35.957904Z" endTime: "2017-01-16T10:34:35.980366Z" latency: "0.022462s" method: "POST" resource: "/drive" httpVersion: "HTTP/1.1" status: 302 userAgent: "APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)" host: "blabla.appspot.com" instanceIndex: -1 finished: true appEngineRelease: "1.9.48" traceId: "d0e888dd390f41758fdf4" first: true } insertId: "587cf6df9ded23f7" httpRequest: { status: 302 } resource: { type: "gae_app" labels: {…} } timestamp: "2017-01-16T10:34:35.957904Z" labels: { appengine.googleapis.com/version_id: "2017013050" clone_id: "" appengine.googleapis.com/clone_id: "" appengine.googleapis.com/module_id: "default" version_id: "20170116t113050" request_id: "587ca1bb00ff0e9dd0f39f31350001707e6561737974696d657265706f721373031313674313133303530000100" appengine.googleapis.com/request_id: "587ca1bb00ff0e9dd0f39f31350001707e6561737974696d6572653674313133303530000100" module_id: "default" } logName: "projects/blabla/logs/appengine.googleapis.com%2Frequest_log" operation: { id: "587ca1bb00ff0e9dde640001323031373031313674313133303530000100" producer: "appengine.googleapis.com/request_id" first: true last: true } }
web.xml:
<web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </context-param> <filter> <filter-name>CORS</filter-name> <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class> </filter> <filter-mapping> <filter-name>CORS</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>PlusBasicServlet</servlet-name> <servlet-class>packagename.PlusBasicServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PlusBasicServlet</servlet-name> <url-pattern>/plusbasicservlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>PlusSampleServlet</servlet-name> <servlet-class>packagename.PlusSampleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PlusSampleServlet</servlet-name> <url-pattern>/plussampleservlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>FileWatchTestServlet</servlet-name> <servlet-class>packagename.ConcreteFileWatchController</servlet-class> </servlet> <servlet-mapping> <servlet-name>FileWatchTestServlet</servlet-name> <url-pattern>/drive</url-pattern> </servlet-mapping> <servlet> <servlet-name>PlusSampleAuthCallbackServlet</servlet-name> <servlet-class>packagename.PlusSampleAuthCallbackServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PlusSampleAuthCallbackServlet</servlet-name> <url-pattern>/oauth2callback</url-pattern> </servlet-mapping> <security-constraint> <web-resource-collection> <web-resource-name>any</web-resource-name> <url-pattern>/plussampleservlet</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> </security-constraint> </web-app>
Screenshot from the log:
