calling web service from cascading

24 views
Skip to first unread message

una...@gmail.com

unread,
Feb 10, 2017, 4:34:10 PM2/10/17
to cascading-user
Hello everyone, I could use some assistance from the experts here.

What's the best way of calling a web service from a Cascading operation?
Am querying an internal API and parsing the output to populate TupleEntry values.
My code ends up with an exception. Obviously it's not able to serialize the object. 

My broader question is: what's the best practice around doing something like this?
If this is the way to go (or not) what can I do to solve this problem or avoid this anti-pattern?

Thanks in advance -

Caused by: java.io.NotSerializableException: org.jboss.resteasy.client.jaxrs.ResteasyClient
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at java.util.HashMap.writeObject(HashMap.java:1129)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at cascading.flow.hadoop.util.JavaObjectSerializer.serialize(JavaObjectSerializer.java:57)
at cascading.flow.hadoop.util.HadoopUtil.serializeBase64(HadoopUtil.java:282)
at cascading.flow.hadoop.HadoopFlowStep.pack(HadoopFlowStep.java:193) 

 

Ken Krugler

unread,
Feb 10, 2017, 4:40:32 PM2/10/17
to cascadi...@googlegroups.com
Often the classes used to query web services aren’t serializable.

So what you want to save with your function is the set of values required to instantiate the client. Typically those are serializable (e.g. rest endpoint, username, various other settings)

The actual client field in the function class is flagged as transient, so that it isn’t serialized.

Then in your function’s open() method, you use these settings to create the client.

And in the close() method you close it, of course.

— Ken


-- 
You received this message because you are subscribed to the Google Groups "cascading-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cascading-use...@googlegroups.com.
To post to this group, send email to cascadi...@googlegroups.com.
Visit this group at https://groups.google.com/group/cascading-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/cascading-user/23b207c0-067d-46b7-bdea-497226d35b27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--------------------------
Ken Krugler
custom big data solutions & training
Hadoop, Cascading, Cassandra & Solr



una...@gmail.com

unread,
Feb 10, 2017, 6:20:09 PM2/10/17
to cascading-user
Great thanks for the spot-on advice! this works as expected now. 
The more I use Cascading the more I fall in love with it :)

Chris K Wensel

unread,
Feb 10, 2017, 6:51:13 PM2/10/17
to cascadi...@googlegroups.com
fwiw, the ‘context’ object in a Function allows you to initialize resources that are not thread safe

see the bottom of this section


ckw

una...@gmail.com

unread,
Feb 13, 2017, 12:53:50 PM2/13/17
to cascading-user
Cool, thanks for tip Chris. Using the 'context' seems like the way to go, to avoid creating unnecessary objects & reusing when possible. 
Reply all
Reply to author
Forward
0 new messages