How to override Content-Type header when submitting task to task queue?

66 views
Skip to first unread message

AndyD

unread,
Jan 9, 2012, 11:29:02 AM1/9/12
to google-a...@googlegroups.com
First off, I'm new to App Engine task queues, and so I may just be going against the grain here.  Feel free to redirect me if that's the case.

What I'd like to do is queue a task and supply a JSON payload in the HTTP request to the handler

Here's what I'm trying...

    TaskOptions task = TaskOptions.Builder
        .withUrl("/mytaskhandler")
        .header("Content-Type", "application/json")
        .payload(jsonBody);
    QueueFactory.getDefaultQueue().add(task);

What I'm seeing is that this results in a request that has **both** of the following headers:
Content-Type:application/json 
and 
Content-Type:text/plain

That seems bogus, and it's confusing the REST library (Restlet) that I'm using to handle the request content negotiation.  Bug?

-AndyD

Nicholas Verne

unread,
Jan 9, 2012, 3:21:36 PM1/9/12
to google-a...@googlegroups.com
Try using TaskOptions.payload(byte[] payload, java.Lang.String contentType)

TaskOptions task = TaskOptions.Builder
.withUrl("/mytaskhandler")

.payload(jsonBody.getBytes(), "application/json");
QueueFactory.getDefaultQueue().add(task);

Nick Verne

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/fEC1iFfb2T0J.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.

AndyD

unread,
Jan 10, 2012, 12:40:03 PM1/10/12
to google-a...@googlegroups.com
That did the trick, thanks!
Reply all
Reply to author
Forward
0 new messages