GUICE endpoint servlet and cron

75 views
Skip to first unread message

Trez Ertzzer

unread,
Oct 20, 2017, 9:45:57 AM10/20/17
to Google App Engine
Hello. 
at this URL:
I found in the web.xml:
 
    <!--
      URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
      the route /_ah/api/ and using /* will erronously use the legacy v1
      servlet instead of routing to your API.
    -->
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </filter-mapping>


I do not understand why if I put /* instead of /_ah/api/* then it does not work...



In fact I managed to make my endpoint work with guice: everything is working fine concerning the endpoint.
But now I want to add a cron task wich means I need to create a servelt and add it to my web.xml

the issue that I have it that in the servlet I want to use GUICE, but the DI does not work:
when I use this code, the "updater" that is supposed to have been injected is null...

public class UpdateCurrenciesServlet extends HttpServlet {
  Logger logger = Logger.getLogger(this.getClass().getName());

  @Inject
  CurrencyRateUpdater updater;

  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    try {
      updater.doOnGae();
    }
    catch (InterruptedException | ExecutionException | TimeoutException e) {
      logger.log(Level.SEVERE, e.toString(), e);
    }

    resp.setStatus(HttpStatusCodes.STATUS_CODE_OK);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    super.doPost(req, resp);
  }
}

what am I missing?
thank you for the help





Jordan (Cloud Platform Support)

unread,
Oct 20, 2017, 3:38:32 PM10/20/17
to Google App Engine
You seem to be missing a '.' char in your '/*' regular expression. The correct '/.*' matches any characters, zero or more times. Concerning your injection issue, you may want to check out past questions on Stack Overflow that cover this topic. 

- Note that Google Groups is meant for general product discussions and not for technical support. If you require further technical support it is recommended to post your full question to Stack Overflow using the supported Cloud tags. 

Trez Ertzzer

unread,
Oct 27, 2017, 4:45:52 AM10/27/17
to Google App Engine
Hello.
I did not write this code... 


Can you explain the  comment from this code... 

    <!--
      URL Pattern /_ah/api/* instead of /* because a legacy v1 servlet uses
      the route /_ah/api/ and using /* will erronously use the legacy v1
      servlet instead of routing to your API.
    -->
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </filter-mapping>


 (I used the legacy endpoint, I moved to endpoint framework, now I am trying to use GUICE)

Yannick (Cloud Platform Support)

unread,
Oct 27, 2017, 1:54:40 PM10/27/17
to Google App Engine
Hello Trez, I find it difficult to explain that comment further. It is itself an explanation of the value used in the "url-pattern" parameter for the filter. What about it is confusing?
Reply all
Reply to author
Forward
0 new messages