avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tuan Nguyen <tua...@gmail.com>
Subject Avro Quickstart updated for 1.2.0
Date Fri, 30 Oct 2009 12:37:32 GMT
Hi,

I've tried the quickstart tutorial and run into a small problem. When I
tried to modified the mail.apvr to allow null parameter and null value in
Message object,

{
 "namespace": "example.proto",
 "protocol": "Mail",

 "types": [
     {"name": "Message", "type": "record",
      "fields": [
          {"name": "to",   "type": "string"},
          {"name": "from", "type": "string"},
          {"name": "body", "type": ["string", "null"]}
      ]
     }
 ],

 "messages": {
     "send": {
         "request": [{"name": "message", "type": ["Message", "null"]}],
         "response": "string"
     },

     "receive": {
         "request": [{"name": "query", "type": ["string", "null"]}],
         "response": ["null", "Message"]
     }
 }
}

public class Main {

  public static class MailImpl implements Mail {

    // in this simple example just return details of the message

    public Utf8 send(Message message) {

      return new Utf8("Sent message to " + message.to.toString() + "
from "+ message.
from.toString() + " with body " + message.body);

    }


    public Message receive(Utf8 query) throws AvroRemoteException {

      Message message = new Message();

      message.to = new Utf8("user");

      message.from = new Utf8("user");

      //message.body = new Utf8("Hello Tuan");

      return message;

    }

  }


  public static void main(String[] args) throws Exception {

    SocketServer server =

      new SocketServer(new SpecificResponder(Mail.class, new MailImpl()),
new InetSocketAddress(0));

    // client code - attach to the server and send a message

    SocketTransceiver client = new
SocketTransceiver(newInetSocketAddress(server.getPort()));

    SpecificRequestor requestor = new SpecificRequestor(Mail.class, client);

    Mail proxy = (Mail) SpecificRequestor.getClient(Mail.class, requestor);


    // fill in the Message record and send it

    Message message = new Message();

    message.to = new Utf8("tuan");

    message.from = new Utf8("tuan");

    message.body = new Utf8("Hello Tuan");

    System.out.println("Send Result: " + proxy.send(null));


    System.out.println("Receive Result: " + proxy.receive(new Utf8("query"
)));

    // cleanup

    client.close();

    server.close();

    System.out.println("Exist!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

  }

}

I got the following exceptions when I tried to passed the null parrameter to
the receive method and return a message with the null body.

Exception in thread "Connection to /192.168.1.200:64182"
java.lang.NullPointerException
        at
org.apache.avro.specific.SpecificDatumWriter.getField(SpecificDatumWriter.java:36)
        at
org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:90)
        at
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:62)
        at
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:55)
        at
org.apache.avro.reflect.ReflectResponder.writeResponse(ReflectResponder.java:69)
        at org.apache.avro.ipc.Responder.respond(Responder.java:135)
        at
org.apache.avro.ipc.SocketServer$Connection.run(SocketServer.java:91)
        at java.lang.Thread.run(Thread.java:637)


java.lang.NullPointerException
        at
org.apache.avro.io.BinaryEncoder.writeString(BinaryEncoder.java:131)
        at
org.apache.avro.generic.GenericDatumWriter.writeString(GenericDatumWriter.java:171)
        at
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
        at
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:55)
        at
org.apache.avro.reflect.ReflectRequestor.writeRequest(ReflectRequestor.java:78)
        at org.apache.avro.ipc.Requestor.request(Requestor.java:107)
        at
org.apache.avro.reflect.ReflectRequestor.invoke(ReflectRequestor.java:62)
        at $Proxy5.querySingle(Unknown Source)

I also try to to serialize/deserialize the Message object with the
SecificDatumWriter and there is no exception. Do I miss any thing here?

Thank for your help.
Tuan Nguyen!

Mime
View raw message