/** Create a one-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request) { return createMessage(name, doc, new LinkedHashMap<String,String>(),request); } /** Create a one-way message. */
/** Create a two-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request, Schema response, Schema errors) { return createMessage(name, doc, new LinkedHashMap<String,String>(), request, response, errors); } /** Create a two-way message. */
errs.add(getSchema(err, names)); Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);
private Protocol addStringType(Protocol p) { if (stringType != StringType.String) return p; Protocol newP = new Protocol(p.getName(), p.getDoc(), p.getNamespace()); Map<Schema,Schema> types = new LinkedHashMap<>(); for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) { newP.addProp(a.getKey(), a.getValue()); } // annotate types Collection<Schema> namedTypes = new LinkedHashSet<>(); for (Schema s : p.getTypes()) namedTypes.add(addStringType(s, types)); newP.setTypes(namedTypes); // annotate messages Map<String,Message> newM = newP.getMessages(); for (Message m : p.getMessages().values()) newM.put(m.getName(), m.isOneWay() ? newP.createMessage(m, addStringType(m.getRequest(), types)) : newP.createMessage(m, addStringType(m.getRequest(), types), addStringType(m.getResponse(), types), addStringType(m.getErrors(), types))); return newP; }
errs.add(getSchema(err, names)); Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);
if (value.isOneWay()) { Schema replacement = resolve(replacements, value.getRequest(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, replacement); } else { Schema response = resolve(replacements, value.getResponse(), protocol); Schema errors = resolve(replacements, value.getErrors(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, request, response, errors);
{if (true) throw error("One-way message'"+name+"' must return void", token);} {if (true) return oneWay ? p.createMessage(name, msgDoc, props, request) : p.createMessage(name, msgDoc, props, request, response, errors);} throw new Error("Missing return statement in function");
/** Test that Responder ignores one-way with stateless transport. */ @Test public void testStatelessOneway() throws Exception { // a version of the Simple protocol that doesn't declare "ack" one-way Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); Protocol.Message message = protocol.createMessage("ack", null, Schema.createRecord(new ArrayList<>()), Schema.create(Schema.Type.NULL), Schema.createUnion(new ArrayList<>())); protocol.getMessages().put("ack", message); // call a server over a stateless protocol that has a one-way "ack" GenericRequestor requestor = new GenericRequestor(protocol, createTransceiver()); requestor.request("ack", new GenericData.Record(message.getRequest())); // make the request again, to better test handshakes w/ differing protocols requestor.request("ack", new GenericData.Record(message.getRequest())); }
protocol.createMessage("echo", null, Schema.createRecord(params), record, Schema.createUnion(new ArrayList<>()));
@Test /** Construct and use a different protocol whose "hello" method has an extra argument to check that schema is sent to parse request. */ public void testHandshake() throws IOException { Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); List<Field> fields = new ArrayList<>(); fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN), null, null)); fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING), null, null)); Protocol.Message message = protocol.createMessage("hello", null /* doc */, Schema.createRecord(fields), Schema.create(Schema.Type.STRING), Schema.createUnion(new ArrayList<>())); protocol.getMessages().put("hello", message); Transceiver t = new SocketTransceiver(new InetSocketAddress(server.getPort())); try { GenericRequestor r = new GenericRequestor(protocol, t); GenericRecord params = new GenericData.Record(message.getRequest()); params.put("extra", Boolean.TRUE); params.put("greeting", new Utf8("bob")); Utf8 response = (Utf8)r.request("hello", params); assertEquals(new Utf8("goodbye"), response); } finally { t.close(); } }
@Test /** Construct and use a protocol whose "hello" method has an extra argument to check that schema is sent to parse request. */ public void testParamVariation() throws Exception { Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); List<Schema.Field> fields = new ArrayList<>(); fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN), null, null)); fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING), null, null)); Protocol.Message message = protocol.createMessage("hello", null /* doc */, Schema.createRecord(fields), Schema.create(Schema.Type.STRING), Schema.createUnion(new ArrayList<>())); protocol.getMessages().put("hello", message); Transceiver t = createTransceiver(); try { GenericRequestor r = new GenericRequestor(protocol, t); addRpcPlugins(r); GenericRecord params = new GenericData.Record(message.getRequest()); params.put("extra", Boolean.TRUE); params.put("greeting", "bob"); String response = r.request("hello", params).toString(); assertEquals("goodbye", response); } finally { t.close(); } }
/** Create a two-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request, Schema response, Schema errors) { return createMessage(name, doc, new LinkedHashMap<String,String>(), request, response, errors); } /** Create a two-way message. */
/** Create a one-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request) { return createMessage(name, doc, new LinkedHashMap<String,String>(),request); } /** Create a one-way message. */
/** Create a two-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request, Schema response, Schema errors) { return createMessage(name, doc, new LinkedHashMap<String,String>(), request, response, errors); } /** Create a two-way message. */
/** Create a one-way message. */ @Deprecated public Message createMessage(String name, String doc, Schema request) { return createMessage(name, doc, new LinkedHashMap<String,String>(),request); } /** Create a one-way message. */
Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);
errs.add(getSchema(err, names)); Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);
Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);
errs.add(getSchema(err, names)); Schema errors = Schema.createUnion(errs); return protocol.createMessage(method.getName(), null /* doc */, request, response, errors);