예제 #1
0
 /**
  * @expectedException \Stomp\Exception\StompException
  */
 public function testWaitForReceiptWillThrowExceptionOnIdMissmatch()
 {
     $receiptFrame = new Frame('RECEIPT');
     $receiptFrame->setHeader('receipt-id', 'not-matching-id');
     $stomp = $this->getStompWithInjectedMockedConnectionReadResult($receiptFrame);
     $waitForReceipt = new ReflectionMethod($stomp, 'waitForReceipt');
     $waitForReceipt->setAccessible(true);
     // expect a receipt for another id
     $waitForReceipt->invoke($stomp, 'your-id');
 }
예제 #2
0
파일: Client.php 프로젝트: grimkirill/stomp
 protected function _throwStompException(Frame $frame)
 {
     $headers = $frame->getHeaders();
     if (isset($headers['message'])) {
         $message = $headers['message'];
     } else {
         $message = $frame->getCommand();
         foreach ($headers->getHeaders() as $key => $value) {
             $message .= ' ' . $key . ' ' . $value . ';';
         }
     }
     if ($frame->getBody()) {
         $message .= ' ' . $frame->getBody();
     }
     throw new StompException($message);
 }
예제 #3
0
 /**
  * Constructor
  *
  * @param Frame|string $msg
  * @param array $headers
  */
 public function __construct($msg, array $headers = array())
 {
     if ($msg instanceof Frame) {
         parent::__construct($msg->command, $msg->headers, $msg->body);
         $this->map = json_decode($msg->body, true);
     } else {
         parent::__construct('SEND', $headers, $msg);
         $this->headers['transformation'] = 'jms-map-json';
         $this->body = json_encode($msg);
     }
 }
예제 #4
0
파일: Stomp.php 프로젝트: phpwutz/stomp-php
 /**
  * Acknowledge consumption of a message from a subscription
  * Note: This operation is always asynchronous
  *
  * @param string|Frame $message ID to ack
  * @param string $transactionId
  * @return boolean
  * @throws StompException
  */
 public function ack($message, $transactionId = null)
 {
     if ($message instanceof Frame) {
         return $this->sendFrame($this->protocol->getAckFrame($message->getMessageId(), $transactionId), false);
     } else {
         return $this->sendFrame($this->protocol->getAckFrame($message, $transactionId), false);
     }
 }
예제 #5
0
 /**
  * Read frame
  * @return bool|Frame
  */
 public function read($timeout = 0)
 {
     $this->setTimeout($timeout);
     $this->isConnected();
     // as per protocol COMMAND is 1st \n terminated then headers also \n terminated
     // COMMAND and header block are seperated by a blank line.
     $headers_rows = array();
     // read command and headers
     while (($line = @fgets($this->_socket)) !== false) {
         $headers_rows[] = $line;
         if (rtrim($line) === '') {
             break;
         }
     }
     if (count($headers_rows) > 0) {
         $command = trim($headers_rows[0]);
         unset($headers_rows[0]);
         $headers = Frame::extractHeaders($headers_rows);
         $response = '';
         if (!isset($headers[Frame::CONTENT_LENGTH])) {
             // read till we hit the end of frame marker
             do {
                 $chunk = @fgets($this->_socket);
                 if ($chunk === false || strlen($chunk) === 0) {
                     $this->_checkSocketReadTimeout();
                     break;
                 }
                 if (substr($chunk, -2) === Frame::END_OF_FRAME) {
                     // add the chunk above to the result before returning
                     $response .= $chunk;
                     break;
                 }
                 $response .= $chunk;
             } while (feof($this->_socket) === false);
         } else {
             // we have a content-length header set
             $contentLength = $headers[Frame::CONTENT_LENGTH] + 2;
             $current_pos = ftell($this->_socket);
             $chunk = '';
             for ($read_to = $current_pos + $contentLength; $read_to > $current_pos; $current_pos = ftell($this->_socket)) {
                 $chunk = fread($this->_socket, $read_to - $current_pos);
                 if ($chunk === false || strlen($chunk) === 0) {
                     $this->_checkSocketReadTimeout();
                     break;
                 }
                 $response .= $chunk;
                 // Break if the connection ended prematurely
                 if (feof($this->_socket)) {
                     break;
                 }
             }
         }
         return new Frame($command, substr($response, 0, -2), $headers);
     } else {
         return false;
     }
 }
예제 #6
0
 /**
  * Write frame to server.
  *
  * @param Frame $stompFrame
  * @return boolean
  * @throws ConnectionException
  */
 public function writeFrame(Frame $stompFrame)
 {
     if (!$this->isConnected()) {
         throw new ConnectionException('Not connected to any server.', $this->activeHost);
     }
     $data = $stompFrame->__toString();
     if (!@fwrite($this->connection, $data, strlen($data))) {
         throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
     }
     return true;
 }
예제 #7
0
 /** @test */
 public function shouldConvertFrameWithoutBodyToString()
 {
     $frame = new Frame('SEND', array('destination' => '/queue/a'));
     $result = $frame->__toString();
     $this->assertEquals("SEND\ndestination:/queue/a\n\n", $result);
 }
예제 #8
0
 public function testParseHeaders()
 {
     $this->assertEquals(array('version' => '1.0'), \Stomp\Frame::extractHeaders(array('version:1.0')));
     $this->assertEquals(array('server' => 'apache-apollo/1.5'), \Stomp\Frame::extractHeaders(array('server:apache-apollo/1.5')));
     $this->assertEquals(array('destination' => '/queue/a', 'content-type' => 'text/plain'), \Stomp\Frame::extractHeaders(array('destination:/queue/a', 'content-type:text/plain')));
 }