/** * simple read test from buffer * put couple of messages in buffer and try to read them */ public function testConnectionRad() { $connection = new Connection(new Stomp\ConnectionFactory\NullFactory()); $this->assertFalse($connection->_bufferContainsMessage(), 'Do not expect any messages in connection'); $frame1 = new Stomp\Message\Bytes("lorem ipsum \n\n dolore sitamet", array('foo' => 'meta')); $connection->_appendToBuffer("\n\n"); $connection->_appendToBuffer($frame1->__toString()); $connection->_appendToBuffer("\n\n\n"); $frame2 = new Stomp\Message\Bytes("lorem forem \n\n, none ", array('beta' => 'treu', 'mod' => false)); $connection->_appendToBuffer($frame2->__toString()); $this->assertTrue($connection->_bufferContainsMessage(), 'Expect to have frame to read.'); $result = $connection->readFrame(); $this->assertInstanceOf('CentralDesktop\\Stomp\\Frame', $result); $this->assertEquals($frame1->body, $result->body); $this->assertTrue($connection->_bufferContainsMessage(), "We should have some message in buffer"); $connection->readFrame(); $this->assertFalse($connection->_bufferContainsMessage(), 'Now buffer should be empty'); }
public function testProtoHandling() { $iters = 5; $bytes = [10, 4, 49, 48, 50, 52, 24, 50]; // $bytes = [\004, 1, 0, 2, 4, \030, 2]; $body = implode(array_map("chr", $bytes)); $headers = ['ack' => 'ID\\ctest-35459-1423180748247-4597\\c1', 'message-id' => 'ID\\cCD-test-59238-1423527427959-7\\c1\\c2\\c1\\c1', 'destination' => '/queue/test', 'timestamp' => '1423527680019', 'expires' => '1423527700019', 'subsc ription' => '0', 'persistent' => 'true', 'content-length' => '8', 'priority' => '4', 'reply-to' => '/remote-temp-queue/ID\\cCD-test-59238-1423527427959-7\\c1\\c1', 'correlation-id' => 'Camel-ID -CD-test-cdlocal-59236-1423527427164-0-7']; $frame = new Stomp\Message\Bytes($body, $headers); $s_frame = $frame->__toString(); $stomp = $this->stomp; foreach (range(0, $iters) as $i) { $stomp->_appendToBuffer($s_frame); } foreach (range(0, $iters) as $i) { $frame = $stomp->readFrame(); $body = $frame->body; $this->assertEquals(count($bytes), mb_strlen($body, '8bit'), "byte count doesn't match on iter {$i}"); $this->assertEquals($body, $frame->body, "body doesn't match on iter {$i}"); } }
/** * Constructor * * @param Frame|string $msg * @param array $headers */ function __construct($msg, $headers = null) { if ($msg instanceof Stomp\Frame) { $this->_init($msg->command, $msg->headers, $msg->body); if ($msg->headers['transformation'] == 'jms-map-xml') { $this->map = self::decode_xml($msg->body); } elseif ($msg->headers['transformation'] == 'jms-map-json') { $this->map = self::decode_json($msg->body); } if (count($this->map) == 0) { error_log("Json error: " . json_last_error() . " on: " . $msg->body); error_log("Body length is: " . strlen($msg->body)); } } else { if (!is_array($headers)) { $headers = array(); } $headers = array_merge($headers, array('transformation' => 'jms-map-json')); parent::__construct(json_encode($msg), $headers); } }