1

I am running into the problems addressed in How to test Mirror API Subscriptions.

"The second and most helpful way I have found to do development locally is to capture a subscription callback request (say from a server that is publicly accessible) into a log and then use curl to reproduce that request on your local/dev machine"

Could someone provide an explanation of how to do this?

Community
  • 1
  • 1
Daniel Kaplan
  • 222
  • 1
  • 8

2 Answers2

1

The specific way you do this depends on your language and platform, but the gist of it is that you log the notification request body.

The Java quick start is actually already doing it in [NotifyServlet.java][2]. It does some quick checks on the request body and logs it to info.

public class NotifyServlet extends HttpServlet {
  private static final Logger LOG = Logger.getLogger(MainServlet.class.getSimpleName());
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // Respond with OK and status 200 in a timely fashion to prevent redelivery
    response.setContentType("text/html");
    Writer writer = response.getWriter();
    writer.append("OK");
    writer.close();

    // Get the notification object from the request body (into a string so we
    // can log it)
    BufferedReader notificationReader =
        new BufferedReader(new InputStreamReader(request.getInputStream()));
    String notificationString = "";

    // Count the lines as a very basic way to prevent Denial of Service attacks
    int lines = 0;
    while (notificationReader.ready()) {
      notificationString += notificationReader.readLine();
      lines++;

      // No notification would ever be this long. Something is very wrong.
      if(lines > 1000) {
        throw new IOException("Attempted to parse notification payload that was unexpectedly long.");
      }
    }

    LOG.info("got raw notification " + notificationString);
    JsonFactory jsonFactory = new JacksonFactory();
  ...

Once this code runs, visit your log, copy the JSON and use it with curl to post it back to your local server.

mimming
  • 13,974
  • 3
  • 45
  • 74
  • I was wondering where those LOG strings were being sent. I just hadn't found the Logs in the admin console (https://developers.google.com/appengine/articles/logging). Thanks! – Daniel Kaplan Jun 06 '13 at 22:00
1

One possible way to do this is using a tool such as nc, which will let you listen on a particular port for all traffic to that port and display the results (or redirect it to a file). (You'll need to use the https/http proxy, unless you're good at manually negotiating SSL.)

In this scenario, the server will send you the callback info which will be displayed, and you can copy the JSON and use it locally.

Prisoner
  • 49,922
  • 7
  • 53
  • 105