private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse((JsonNode)Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }
/** * Return the protocol for a Java interface. * <p>The correct name of the method parameters needs the <code>-parameters</code> * java compiler argument. More info at https://openjdk.java.net/jeps/118 */ @Override public Protocol getProtocol(Class iface) { Protocol protocol = new Protocol(iface.getSimpleName(), iface.getPackage()==null?"":iface.getPackage().getName()); Map<String,Schema> names = new LinkedHashMap<>(); Map<String,Message> messages = protocol.getMessages(); for (Method method : iface.getMethods()) if ((method.getModifiers() & Modifier.STATIC) == 0) { String name = method.getName(); if (messages.containsKey(name)) throw new AvroTypeException("Two methods with same name: "+name); messages.put(name, getMessage(method, protocol, names)); } // reverse types, since they were defined in reference order List<Schema> types = new ArrayList<>(); types.addAll(names.values()); Collections.reverse(types); protocol.setTypes(types); return protocol; }
/** Return the protocol for a Java interface. * <p>Note that this requires that <a * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled * interface declarations, since Java 6 reflection does not provide access to * method parameter names. See Avro's build.xml for an example. */ @Override public Protocol getProtocol(Class iface) { Protocol protocol = new Protocol(iface.getSimpleName(), iface.getPackage()==null?"":iface.getPackage().getName()); Map<String,Schema> names = new LinkedHashMap<String,Schema>(); Map<String,Message> messages = protocol.getMessages(); for (Method method : iface.getMethods()) if ((method.getModifiers() & Modifier.STATIC) == 0) { String name = method.getName(); if (messages.containsKey(name)) throw new AvroTypeException("Two methods with same name: "+name); messages.put(name, getMessage(method, protocol, names)); } // reverse types, since they were defined in reference order List<Schema> types = new ArrayList<Schema>(); types.addAll(names.values()); Collections.reverse(types); protocol.setTypes(types); return protocol; }
private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse(Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }
final public Protocol ProtocolDeclaration() throws ParseException { String name; Protocol p; Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>(); label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: ; break; default: jj_la1[4] = jj_gen; break label_2; } SchemaProperty(props); } if (props.containsKey("namespace")) namespace = getTextProp("namespace", props, token); jj_consume_token(PROTOCOL); name = Identifier(); p = new Protocol(name, getDoc(), namespace); for (String key : props.keySet()) if ("namespace".equals(key)) { // already handled: ignore } else { // add all other props Accessor.addProp(p, key, props.get(key)); } ProtocolBody(p); {if (true) return p;} throw new Error("Missing return statement in function"); }
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; }
Protocol result = new Protocol(protocol.getName(), protocol.getDoc(), protocol.getNamespace()); final Collection<Schema> types = protocol.getTypes();
@Test public void testSplitProtocolBuild() { Protocol p = new Protocol("P", null, "foo"); p.addProp("property", "some value"); String protocolString = p.toString(); final int mid = protocolString.length() / 2; String[] parts = { protocolString.substring(0, mid), protocolString.substring(mid), }; Protocol parsedStringProtocol = org.apache.avro.Protocol.parse(protocolString); Protocol parsedArrayOfStringProtocol = org.apache.avro.Protocol.parse(protocolString.substring(0, mid), protocolString.substring(mid)); assertNotNull(parsedStringProtocol); assertNotNull(parsedArrayOfStringProtocol); assertEquals(parsedStringProtocol.toString(), parsedArrayOfStringProtocol.toString()); } }
/** 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())); }
@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(); } }
@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(); } }
record.setFields(fields); Protocol protocol = new Protocol("Simple", "org.apache.avro.test"); List<Field> params = new ArrayList<>(); params.add(new Field("record", record, null, null));
/** Return the protocol for a Java interface. * <p>Note that this requires that <a * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled * interface declarations, since Java 6 reflection does not provide access to * method parameter names. See Avro's build.xml for an example. */ @Override public Protocol getProtocol(Class iface) { Protocol protocol = new Protocol(iface.getSimpleName(), iface.getPackage()==null?"":iface.getPackage().getName()); Map<String,Schema> names = new LinkedHashMap<String,Schema>(); Map<String,Message> messages = protocol.getMessages(); for (Method method : iface.getMethods()) if ((method.getModifiers() & Modifier.STATIC) == 0) { String name = method.getName(); if (messages.containsKey(name)) throw new AvroTypeException("Two methods with same name: "+name); messages.put(name, getMessage(method, protocol, names)); } // reverse types, since they were defined in reference order List<Schema> types = new ArrayList<Schema>(); types.addAll(names.values()); Collections.reverse(types); protocol.setTypes(types); return protocol; }
/** Return the protocol for a Java interface. * <p>Note that this requires that <a * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled * interface declarations, since Java 6 reflection does not provide access to * method parameter names. See Avro's build.xml for an example. */ @Override public Protocol getProtocol(Class iface) { Protocol protocol = new Protocol(iface.getSimpleName(), iface.getPackage()==null?"":iface.getPackage().getName()); Map<String,Schema> names = new LinkedHashMap<String,Schema>(); Map<String,Message> messages = protocol.getMessages(); for (Method method : iface.getMethods()) if ((method.getModifiers() & Modifier.STATIC) == 0) { String name = method.getName(); if (messages.containsKey(name)) throw new AvroTypeException("Two methods with same name: "+name); messages.put(name, getMessage(method, protocol, names)); } // reverse types, since they were defined in reference order List<Schema> types = new ArrayList<Schema>(); types.addAll(names.values()); Collections.reverse(types); protocol.setTypes(types); return protocol; }
/** Return the protocol for a Java interface. * <p>Note that this requires that <a * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled * interface declarations, since Java 6 reflection does not provide access to * method parameter names. See Avro's build.xml for an example. */ @Override public Protocol getProtocol(Class iface) { Protocol protocol = new Protocol(iface.getSimpleName(), iface.getPackage().getName()); Map<String,Schema> names = new LinkedHashMap<String,Schema>(); Map<String,Message> messages = protocol.getMessages(); for (Method method : iface.getMethods()) if ((method.getModifiers() & Modifier.STATIC) == 0) { String name = method.getName(); if (messages.containsKey(name)) throw new AvroTypeException("Two methods with same name: "+name); messages.put(name, getMessage(method, protocol, names)); } // reverse types, since they were defined in reference order List<Schema> types = new ArrayList<Schema>(); types.addAll(names.values()); Collections.reverse(types); protocol.setTypes(types); return protocol; }
private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse(Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }
private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse(Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }
private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse(Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }
private static Protocol parse(JsonParser parser) { try { Protocol protocol = new Protocol(); protocol.parse(Schema.MAPPER.readTree(parser)); return protocol; } catch (IOException e) { throw new SchemaParseException(e); } }