I've solved the serialization problems by Base64 encoding the
serialized task before calling payload() and decoding it in the
deserialize(HttpServletRequest) method. I'm guessing something in the
task queue chain (either task queue payload storage or the servlet
call when task is run) has problems transmitting the binary data, as
the exception I was getting at one point was a
java.io.StreamCorruptedException.

I'll send another patch to Vince. My solution works, but I'm not
completely satisfied that I've diagnosed the problem correctly. I used
Apache commons-codec for Base64. Is it safe to use com.sun.misc
instead? I see it in appengine.repackaged chain, as well, but don't
see it as part of an official Google API.

Somewhat related, I've wired up the Deferred servlet through the
GuiceFilter so I can pass a Guice injector to Deferrable tasks. Since
the task objects are not created through Guice, but rather by
deserializing, I modified doTask() to accept an additional Injector
argument. We probably don't want that in the official version of
Deferrable, though.

Is there a better way for my Deferrable classes to get access to a
Guice "context"? I'm trying to avoid Guice.createInjector(), as it
results in a duplicate PersistenceManagerFactory being created since
other servlets are also being served through Guice.

Thank you,
/dmc

On Nov 27, 5:42 pm, David Chandler <[email protected]> wrote:
> Jeff,
>
> I'm seeing problems with deserialization, too, when deployed on
> AppEngine. In dev, I can deserialize(serialize(task)) and it works
> just fine, but not so in AppEngine. I get the same error whether the
> task payload is the serialized Deferrable task itself or just the Key
> with the task in the db, but I haven't yet figured out which is the
> cause of the problem.
>
> The error I'm getting on AppEngine is invalid type code: 00 in
> Deferred.deserialize method. I've tried Base64 encoding after
> serialization in case it's related to special binary escape sequences
> that happen to be in the serialized object stream but still no
> success.
>
> I'm pretty sure AppEngine has written some custom code to do
> serialization because I previously got an AppEngine acess control
> exception when calling enableResolveObject(true) in a subclass of
> ObjectInputStream, and I'm wondering if that's in play somehow...
>
> /dmc
>
> On Nov 26, 5:31 am, Jeff Schnitzer <[email protected]> wrote:
>
> > I should have said this before, but thanks for providing this code!
>
> > For reasons that are still not clear to me, my task was not
> > deserializing properly (very odd complaints about HashMap).  Not
> > having a stack trace made it even more confusing than usual.
> > Ultimately I fixed the problem by making my class Externalizable and
> > serializing my object graph as JSON.
>
> > I would definitely want to see deserialization exceptions in the logs.
> >  Even if the container is behaving perfectly rationally, developers
> > can easily hork up the process with Externalizable.  What is to be
> > gained by hiding the stack trace?
>
> > Thanks,
> > JeffOn Wed, Nov 25, 2009 at 11:03 AM, Vince Bonfanti <[email protected]> 
> > wrote:
> > > Hi Jeff,
> > > Thanks for the suggestions and the code. David Chandler sent me a patch to
> > > support user-specified queue names (almost exactly the same as your
> > > changes), and I've committed that patch to SVN. Regarding your other
> > > changes:
> > >   - I've probably make the <url-pattern> init parameter optional and have 
> > > it
> > > default to "/_ah/<queue_name>" rather than throw an exception from the 
> > > init
> > > method if it's missing.
> > >   - While we're at it, the default queue name could be optionally 
> > > specified
> > > by an init parameter also.
> > >   - I'm not sure a stacktrace from the doPost method is really going to 
> > > give
> > > you much more information, but would be open to that  change.
> > > It looks like the Deferred class is going to be added to the official 
> > > GAE/J
> > > SDK, though I'm not sure when. Rather than make any more changes to the 
> > > code
> > > right now, I'd rather wait to see what shows up the SDK and then work
> > > through normal Google channels to get any further modifications made. In 
> > > the
> > > mean time, I'm glad it's working for you.
> > > Vince
> > > On Tue, Nov 24, 2009 at 8:09 PM, Jeff Schnitzer <[email protected]> 
> > > wrote:
>
> > >> Attached is a modified version of that class that lets you define any
> > >> path you want for the servlet and lets you specify which queue to use
> > >> like this: Deferred.defer(task, "queueName");
>
> > >> (I needed this for my own purposes)
>
> > >> Do with it as you wish :-)
>
> > >> The only other major change I would make is to stop masking all the
> > >> exceptions during the task processing.  Or at least, if you're going
> > >> to log the exception and stop propagation, log the whole thing so we
> > >> get a stacktrace in the logs.
>
> > >> Jeff
>
> > >> On Fri, Nov 20, 2009 at 1:03 PM, David Chandler <[email protected]>
> > >> wrote:
> > >> > Vince, this is great! I hadn't been watching my own issue, so didn't
> > >> > see this until now. Thanks so much!
>
> > >> > Only enhancement I would suggest is to enable multiple deferred
> > >> > queues. For example. I would like to defer tasks in an email throttle
> > >> > queue separately from a general background queue. Perhaps the
> > >> > Deferrable interface could have a getQueueName() method, or
> > >> > Deferred.defer could have an additional signature defer(Deferrable
> > >> > task, String queueName).
>
> > >> > Thanks again,
> > >> > /dmc
>
> > >> --
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > > "Google App Engine for Java" group.
> > > To post to this group, send email to 
> > > [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to