protected ChannelFuture sendError(ChannelHandlerContext channelContext, String message) { return sendFrame(channelContext, StompFrames.newErrorFrame(message, null)); }
public void send(StompMessage message) { StompFrame frame = StompFrames.newSendFrame( message ); sendFrame( frame ); }
public void abort(String transactionId) throws StompException { StompControlFrame frame = StompFrames.newAbortFrame( transactionId ); ReceiptFuture future = sendFrame( frame ); try { future.await(); } catch (InterruptedException e) { throw new StompException( e ); } catch (ExecutionException e) { throw new StompException( e ); } }
@Test public void testErrorFrame() { StompMessage message = StompMessages.createStompMessage(); message.getHeaders().put( Header.RECEIPT, "some-frame" ); StompFrame inReplyTo = StompFrames.newSendFrame( message ); StompFrame frame = StompFrames.newErrorFrame( "It broke", inReplyTo ); boolean result = this.encoder.offer( frame ); assertTrue( result ); List<String> lines = getFrameLines(); assertEquals( "ERROR", lines.get(0) ); assertContainsLine( "receipt-id:some-frame", lines ); assertContainsContent( "It broke", lines ); }
@Override public void ack(String transactionId) throws Exception { DefaultHeaders ackHeaders = new DefaultHeaders(); ackHeaders.put( Header.MESSAGE_ID, this.headers.get( Header.MESSAGE_ID ) ); ackHeaders.put( Header.SUBSCRIPTION, this.headers.get( Header.SUBSCRIPTION ) ); if (transactionId == null) { transactionId = this.headers.get( Header.TRANSACTION ); } if (transactionId != null) { ackHeaders.put( Header.TRANSACTION, transactionId ); } client.sendFrame( StompFrames.newAckFrame( ackHeaders ) ); }
public void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { this.closeRequest = e; StompFrame closeFrame = StompFrames.newDisconnectFrame(); this.receiptId = closeFrame.getHeader( Header.RECEIPT ); Channels.write( ctx.getChannel(), closeFrame ); }
public void commit(String transactionId) throws StompException { StompControlFrame frame = StompFrames.newCommitFrame( transactionId ); ReceiptFuture future = sendFrame( frame ); try { future.await(); } catch (InterruptedException e) { throw new StompException( e ); } catch (ExecutionException e) { throw new StompException( e ); } }
public ClientTransaction begin() throws StompException { String transactionId = getNextTransactionId(); StompControlFrame frame = StompFrames.newBeginFrame( transactionId ); ReceiptFuture future = sendFrame( frame ); try { future.await(); if (future.isError()) { return null; } else { ClientTransaction transaction = new ClientTransaction( this, transactionId ); this.transactions.put( transaction.getId(), transaction ); return transaction; } } catch (InterruptedException e) { throw new StompException( e ); } catch (ExecutionException e) { throw new StompException( e ); } }
@Override public void nack(String transactionId) throws Exception { if (version.isBefore( Version.VERSION_1_1 )) { throw new StompException("Cannot nack prior to STOMP version 1.1."); } DefaultHeaders nackHeaders = new DefaultHeaders(); nackHeaders.put( Header.MESSAGE_ID, this.headers.get( Header.MESSAGE_ID ) ); nackHeaders.put( Header.SUBSCRIPTION, this.headers.get( Header.SUBSCRIPTION ) ); if (transactionId == null) { transactionId = this.headers.get( Header.TRANSACTION ); } if (transactionId != null) { nackHeaders.put( Header.TRANSACTION, transactionId ); } client.sendFrame( StompFrames.newNackFrame( nackHeaders ) ); }
@Test public void testConnectedFrame() { StompFrame frame = StompFrames.newConnectedFrame( "session-42", Version.VERSION_1_1 ); boolean result = this.encoder.offer( frame ); assertTrue( result ); List<String> lines = getFrameLines(); assertEquals( "CONNECTED", lines.get(0) ); assertContainsLine( "session:session-42", lines ); assertContainsLine( "version:1.1", lines ); }
@Test public void testControlFrame() throws Exception { StompFrame frame = StompFrames.newAckFrame( new DefaultHeaders() ); boolean result = this.decoder.offer( frame ); Object output = this.decoder.poll(); assertSame( frame, output ); //assertFalse( result ); }
@Test public void testAckFrame() { StompFrame frame = StompFrames.newAckFrame( new DefaultHeaders() ); frame.setHeader( Header.SUBSCRIPTION, "subscription-42" ); frame.setHeader( Header.MESSAGE_ID, "message-84" ); boolean result = this.encoder.offer( frame ); assertTrue( result ); List<String> lines = getFrameLines(); assertEquals( "ACK", lines.get(0) ); assertContainsLine( "subscription:subscription-42", lines ); assertContainsLine( "message-id:message-84", lines ); }
@Test public void testContentFrame() throws Exception { StompMessage message = StompMessages.createStompMessage( "/queues/one", "wtf is a taco?" ); StompFrame frame = StompFrames.newSendFrame( message ); boolean result = this.decoder.offer( frame ); assertTrue( result ); StompMessage outputMessage = this.decoder.poll(); assertNotNull( outputMessage ); assertNotSame( message, outputMessage ); assertEquals( "/queues/one", outputMessage.getDestination() ); assertEquals( "wtf is a taco?", outputMessage.getContentAsString() ); }