public static function parse($json) { if (is_null($json)) { throw new AvroProtocolParseException("Protocol can't be null"); } $protocol = new AvroProtocol(); $protocol->real_parse(json_decode($json, true)); return $protocol; }
public function testParsing() { $cnt = count($this->prot_parseable); for ($i = 0; $i < $cnt; $i++) { try { //print($i . " " . ($this->prot_parseable[$i]?"true":"false") . " \n"); $prot = AvroProtocol::parse($this->prot_data[$i]); } catch (AvroSchemaParseException $x) { // exception ok if we expected this protocol spec to be unparseable $this->assertEquals(false, $this->prot_parseable[$i]); } } }
public function write($input_filename, $output_folder, $namespace_prefix, $java_string) { $protocol_json = file_get_contents($input_filename); $protocol = \AvroProtocol::parse($protocol_json); $working_tpl = $this->protocol_tpl; $filename = $this->getFilename($protocol); $subdirectory = $this->getSubdirectory($protocol); $working_tpl = $this->generate($protocol, $protocol_json, $namespace_prefix, $working_tpl, $java_string); if (!file_exists($output_folder . $subdirectory)) { mkdir($output_folder . $subdirectory, 0755, true); } file_put_contents($output_folder . $subdirectory . "/" . $filename, $working_tpl); }
{ echo $local_message->name . ":" . json_encode($request) . "\n"; switch ($local_message->name) { case "testSimpleRequestResponse": if ($request["message"]["subject"] == "ping") { return array("response" => "pong"); } else { if ($request["message"]["subject"] == "pong") { return array("response" => "ping"); } } break; case "testSimpleRequestWithoutParameters": return array("response" => "no incoming parameters"); break; case "testNotification": break; case "testRequestResponseException": if ($request["exception"]["cause"] == "callback") { throw new AvroRemoteException(array("exception" => "raised on callback cause")); } else { throw new AvroRemoteException("System exception"); } break; default: throw new AvroRemoteException("Method unknown"); } } } $server = new SocketServer('127.0.0.1', 1411, new TestProtocolResponder(AvroProtocol::parse($protocol)), true); $server->start();
public function testRequestResponseException() { $server = new TestServer(new TestProtocolResponder(AvroProtocol::parse($this->protocol))); $client = TestTransceiver::getTestClient($server); $requestor = new Requestor(AvroProtocol::parse($this->protocol), $client); $exception_raised = false; try { $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "callback"))); } catch (AvroRemoteException $e) { $exception_raised = true; $exception_datum = $e->getDatum(); $this->assertEquals("raised on callback cause", $exception_datum["exception"]); } $this->assertTrue($exception_raised); $exception_raised = false; try { $response = $requestor->request('testRequestResponseException', array("exception" => array("cause" => "system"))); } catch (AvroRemoteException $e) { $exception_raised = true; $exception_datum = $e->getDatum(); $this->assertEquals("System exception", $exception_datum); } $this->assertTrue($exception_raised); }
public function __construct(AvroProtocol $local_protocol) { $this->local_protocol = $local_protocol; $this->local_hash = $local_protocol->md5(); $this->protocol_cache[$this->local_hash] = $this->local_protocol; $this->handshake_responder_writer = new AvroIODatumWriter(AvroSchema::parse(HANDSHAKE_RESPONSE_SCHEMA_JSON)); $this->handshake_responder_reader = new AvroIODatumReader(AvroSchema::parse(HANDSHAKE_REQUEST_SCHEMA_JSON)); $this->meta_writer = new AvroIODatumWriter(AvroSchema::parse('{"type": "map", "values": "bytes"}')); $this->meta_reader = new AvroIODatumReader(AvroSchema::parse('{"type": "map", "values": "bytes"}')); $this->system_error_schema = AvroSchema::parse('["string"]'); }
"testNotification": { "doc" : "Notification : one-way message", "request": [{"name": "notification", "type": "Notification"}], "one-way": true }, "testRequestResponseException": { "doc" : "Request Response with Exception", "request": [{"name": "exception", "type": "RaiseException"}], "response" : "NeverSend", "errors" : ["AlwaysRaised"] } } } PROTO; $client = NettyFramedSocketTransceiver::create('127.0.0.1', 1411); $requestor = new Requestor(AvroProtocol::parse($protocol), $client); try { $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "pong"))); echo "Response received: " . json_encode($response) . "\n"; $response = $requestor->request('testSimpleRequestResponse', array("message" => array("subject" => "ping"))); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; } try { $response = $requestor->request('testSimpleRequestWithoutParameters', array()); echo "Response received: " . json_encode($response) . "\n"; } catch (AvroRemoteException $e) { echo "Exception received: " . json_encode($e->getDatum()) . "\n"; } try {
public function __construct($host, $port) { $client = \NettyFramedSocketTransceiver::create($host, $port); parent::__construct(\AvroProtocol::parse(self::$json_protocol), $client); }