org.apache.qpid.proton.amqp.Symbol Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.Symbol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpSession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a sender instance using the given Target
 *
 * @param target the caller created and configured Target used to create the sender link.
 * @param senderId the sender ID to assign to the newly created Sender.
 * @param desiredCapabilities the capabilities that the caller wants the remote to support.
 * @param offeredCapabilities the capabilities that the caller wants the advertise support for.
 * @param properties the properties to send as part of the sender open.
 * @return a newly created sender that is ready for use.
 * @throws Exception if an error occurs while creating the receiver.
 */
public AmqpSender createSender(Target target, String senderId, Symbol[] desiredCapabilities, Symbol[] offeredCapabilities, Map<Symbol, Object> properties) throws Exception {
   checkClosed();

   final AmqpSender sender = new AmqpSender(AmqpSession.this, target, senderId);
   sender.setDesiredCapabilities(desiredCapabilities);
   sender.setOfferedCapabilities(offeredCapabilities);
   sender.setProperties(properties);
   final ClientFuture request = new ClientFuture();

   connection.getScheduler().execute(new Runnable() {

      @Override
      public void run() {
         checkClosed();
         sender.setStateInspector(getStateInspector());
         sender.open(request);
         pumpToProtonTransport(request);
      }
   });

   request.sync();

   return sender;
}
 
Example #2
Source File: DataImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeDecodeSymbolArrayUsingPutObject()
{
    Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
    Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
    Symbol[] input = new Symbol[]{symbol1, symbol2};

    Data data1 = new DataImpl();
    data1.putObject(input);

    Binary encoded = data1.encode();
    encoded.asByteBuffer();

    Data data2 = new DataImpl();
    data2.decode(encoded.asByteBuffer());

    assertEquals("unexpected array length", 2, data2.getArray());
    assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());

    Object[] array = data2.getJavaArray();
    assertArrayEquals("Array not as expected", input, array);
}
 
Example #3
Source File: SymbolTypeTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void doTestEncodeSymbolTypeReservation(int size) throws IOException {
    Random random = new Random(System.currentTimeMillis());
    StringBuilder builder = new StringBuilder(size);
    for (int i = 0; i < size; ++i) {
        builder.append((byte) random.nextInt(127));
    }

    Symbol symbol = Symbol.valueOf(builder.toString());

    WritableBuffer writable = new WritableBuffer.ByteBufferWrapper(ByteBuffer.allocate(2048));
    WritableBuffer spy = Mockito.spy(writable);

    encoder.setByteBuffer(spy);
    encoder.writeSymbol(symbol);

    // Check that the SymbolType tries to reserve space, actual encoding size not computed here.
    Mockito.verify(spy).ensureRemaining(Mockito.anyInt());
}
 
Example #4
Source File: ErrorConditionTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testConditionAndDescriptionEquality()
{
    String symbolValue = "symbol";
    String descriptionValue = "description";

    ErrorCondition same1 = new ErrorCondition();
    same1.setCondition(Symbol.getSymbol(new String(symbolValue)));
    same1.setDescription(new String(descriptionValue));

    ErrorCondition same2 = new ErrorCondition();
    same2.setCondition(Symbol.getSymbol(new String(symbolValue)));
    same2.setDescription(new String(descriptionValue));

    assertErrorConditionsEqual(same1, same2);

    ErrorCondition different = new ErrorCondition();
    different.setCondition(Symbol.getSymbol(symbolValue));
    different.setDescription("other");

    assertErrorConditionsNotEqual(same1, different);
}
 
Example #5
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSendBufferAddsDeliveryCountOnlyToSendMessageAndTrimsDeliveryAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf("testGetSendBufferRemoveDeliveryAnnotations"), "X");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   ReadableBuffer buffer = message.getSendBuffer(7);
   assertNotNull(buffer);
   message.reencode(); // Ensures Header is current if accidentally updated

   AMQPStandardMessage copy = new AMQPStandardMessage(0, buffer, null, null);

   MessageImpl originalsProtonMessage = message.getProtonMessage();
   MessageImpl copyProtonMessage = copy.getProtonMessage();
   assertProtonMessageNotEquals(originalsProtonMessage, copyProtonMessage);

   assertNull(originalsProtonMessage.getHeader().getDeliveryCount());
   assertEquals(6, copyProtonMessage.getHeader().getDeliveryCount().intValue());
   assertNull(copyProtonMessage.getDeliveryAnnotations());
}
 
Example #6
Source File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetMessageAnnotationsOnNewMessage() {
    Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName");
    Symbol symbolKeyName2 = Symbol.valueOf("myTestSymbolName2");
    String value = "myTestValue";

    AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();

    // check setting first annotation
    amqpMessageFacade.setMessageAnnotation(symbolKeyName, value);

    MessageAnnotations underlyingAnnotations = amqpMessageFacade.getMessageAnnotations();
    assertNotNull(underlyingAnnotations);

    assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName));
    assertEquals(value, underlyingAnnotations.getValue().get(symbolKeyName));

    // set another
    amqpMessageFacade.setMessageAnnotation(symbolKeyName2, value);

    assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName));
    assertTrue(underlyingAnnotations.getValue().containsKey(symbolKeyName2));
}
 
Example #7
Source File: SaslIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doMechanismSelectedExternalTestImpl(boolean requireClientCert, Symbol clientSelectedMech, Symbol[] serverMechs) throws Exception {
    TransportOptions sslOptions = new TransportOptions();
    sslOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
    sslOptions.setKeyStorePassword(PASSWORD);
    sslOptions.setVerifyHost(false);
    if (requireClientCert) {
        sslOptions.setTrustStoreLocation(BROKER_JKS_TRUSTSTORE);
        sslOptions.setTrustStorePassword(PASSWORD);
    }

    SSLContext context = TransportSupport.createJdkSslContext(sslOptions);

    try (TestAmqpPeer testPeer = new TestAmqpPeer(context, requireClientCert);) {
        String connOptions = "?transport.trustStoreLocation=" + CLIENT_JKS_TRUSTSTORE + "&" +
                             "transport.trustStorePassword=" + PASSWORD + "&" +
                             "jms.clientID=myclientid";
        if (requireClientCert) {
            connOptions += "&transport.keyStoreLocation=" + CLIENT_JKS_KEYSTORE + "&" +
                           "transport.keyStorePassword=" + PASSWORD;
        }

        testPeer.expectSaslFailingAuthentication(serverMechs, clientSelectedMech);

        JmsConnectionFactory factory = new JmsConnectionFactory("amqps://localhost:" + testPeer.getServerPort() + connOptions);
        try {
            factory.createConnection();
            fail("Expected exception to be thrown");
        } catch (JMSException jmse) {
            // Expected
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #8
Source File: FrameWithPayloadMatchingHandler.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
protected FrameWithPayloadMatchingHandler(FrameType frameType,
                                            int channel,
                                            int frameSize,
                                            UnsignedLong numericDescriptor,
                                            Symbol symbolicDescriptor)
{
    super(frameType, channel, frameSize, numericDescriptor, symbolicDescriptor);
}
 
Example #9
Source File: OpenTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopy() {
    Map<Symbol, Object> properties = new HashMap<>();
    properties.put(Symbol.valueOf("x-opt"), "value");

    Open open = new Open();

    open.setContainerId("test");
    open.setHostname("host");
    open.setMaxFrameSize(UnsignedInteger.valueOf(42));
    open.setChannelMax(UnsignedShort.MAX_VALUE);
    open.setIdleTimeOut(UnsignedInteger.valueOf(111));
    open.setOfferedCapabilities(new Symbol[] { Symbol.valueOf("anonymous-relay") });
    open.setDesiredCapabilities(new Symbol[0]);
    open.setProperties(properties);

    Open copyOf = open.copy();

    assertEquals(open.getContainerId(), copyOf.getContainerId());
    assertEquals(open.getHostname(), copyOf.getHostname());
    assertEquals(open.getMaxFrameSize(), copyOf.getMaxFrameSize());
    assertEquals(open.getChannelMax(), copyOf.getChannelMax());
    assertEquals(open.getIdleTimeOut(), copyOf.getIdleTimeOut());
    assertArrayEquals(open.getDesiredCapabilities(), copyOf.getDesiredCapabilities());
    assertArrayEquals(open.getOfferedCapabilities(), copyOf.getOfferedCapabilities());
    assertEquals(open.getProperties(), copyOf.getProperties());
}
 
Example #10
Source File: AbstractFrameFieldAndPayloadMatchingHandler.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
protected AbstractFrameFieldAndPayloadMatchingHandler(FrameType frameType,
                                            int channel,
                                            int frameSize,
                                            UnsignedLong numericDescriptor,
                                            Symbol symbolicDescriptor)
{
    super(numericDescriptor, symbolicDescriptor);
    _frameType = frameType;
    _expectedChannel = channel;
    _expectedFrameSize = frameSize;
}
 
Example #11
Source File: AmqpRedirect.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public AmqpRedirect(Map<Symbol, Object> redirect, AmqpProvider provider) {
    this.redirect = redirect;
    this.provider = provider;

    if (provider == null) {
        throw new IllegalArgumentException("A provider instance is required");
    }

    URI remoteURI = provider.getRemoteURI();
    if (remoteURI == null || remoteURI.getScheme() == null || remoteURI.getScheme().isEmpty()) {
        throw new IllegalArgumentException("The provider instance must provide a valid scheme");
    }
}
 
Example #12
Source File: TestAmqpPeer.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public void expectSaslFailingExchange(Symbol[] serverMechs, Symbol clientSelectedMech, UnsignedByte saslFailureAuthCode)
{
    SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(serverMechs);
    addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
                                        new FrameSender(
                                                this, FrameType.SASL, 0,
                                                saslMechanismsFrame, null)));

    if(saslFailureAuthCode.compareTo(SASL_FAIL_AUTH) < 0 || saslFailureAuthCode.compareTo(SASL_SYS_TEMP) > 0) {
        throw new IllegalArgumentException("A valid failing SASL code must be supplied");
    }

    SaslInitMatcher saslInitMatcher = new SaslInitMatcher().withMechanism(equalTo(clientSelectedMech));
    saslInitMatcher.onCompletion(new AmqpPeerRunnable()
    {
        @Override
        public void run()
        {
            TestAmqpPeer.this.sendFrame(
                    FrameType.SASL, 0,
                    new SaslOutcomeFrame().setCode(saslFailureAuthCode),
                    null,
                    false, 0);
            _driverRunnable.expectHeader();
        }
    });
    addHandler(saslInitMatcher);
}
 
Example #13
Source File: EncoderImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void writeSymbol(final Symbol s)
{
    if(s == null)
    {
        writeNull();
    }
    else
    {
        _symbolType.fastWrite(this, s);
    }
}
 
Example #14
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testSendFailsWhenDelayedDeliveryIsNotSupported() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {

        // DO NOT add capability to indicate server support for DELAYED-DELIVERY

        Connection connection = testFixture.establishConnecton(testPeer);

        connection.start();

        testPeer.expectBegin();

        Matcher<Symbol[]> desiredCapabilitiesMatcher = arrayContaining(new Symbol[] { DELAYED_DELIVERY });
        Symbol[] offeredCapabilities = null;
        testPeer.expectSenderAttach(notNullValue(), notNullValue(), false, false, false, false, 0, 1, null, null, desiredCapabilitiesMatcher, offeredCapabilities);

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);

        MessageProducer producer = session.createProducer(dest);
        producer.setDeliveryDelay(5000);

        // Producer should fail to send when message has delivery delay since remote
        // did not report that it supports that option.
        Message message = session.createMessage();
        try {
            producer.send(message);
            fail("Send should fail");
        } catch (JMSException jmsEx) {
            LOG.debug("Caught expected error from failed send.");
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #15
Source File: AmqpReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
   server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   connection.setContainerId("testClient");
   connection.connect();

   try {
      AmqpSession session = connection.createSession();

      Source source = new Source();
      source.setDurable(TerminusDurability.UNSETTLED_STATE);
      source.setCapabilities(Symbol.getSymbol("topic"));
      source.setAddress("mytopic");
      session.createReceiver(source, "testSub");

      SimpleString fo = new SimpleString("testClient.testSub:mytopic");
      assertNotNull(server.locateQueue(fo));

   } catch (Exception e) {
      e.printStackTrace();
   } finally {
      connection.close();
   }
}
 
Example #16
Source File: FrameWithPayloadMatchingHandler.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
protected FrameWithPayloadMatchingHandler(FrameType frameType,
                                            int channel,
                                            UnsignedLong numericDescriptor,
                                            Symbol symbolicDescriptor)
{
    super(frameType, channel, 0, numericDescriptor, symbolicDescriptor);
}
 
Example #17
Source File: SaslIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testRestrictSaslMechanismsWithSingleMech() throws Exception {
    // Check PLAIN gets picked when we don't specify a restriction
    doMechanismSelectionRestrictedTestImpl("username", "password", PLAIN, new Symbol[] { PLAIN, ANONYMOUS}, null);

    // Check ANONYMOUS gets picked when we do specify a restriction
    doMechanismSelectionRestrictedTestImpl("username", "password", ANONYMOUS, new Symbol[] { PLAIN, ANONYMOUS}, "ANONYMOUS");
}
 
Example #18
Source File: SaslInitMatcher.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public SaslInitMatcher()
{
    super(FrameType.SASL,
          ANY_CHANNEL,
          UnsignedLong.valueOf(0x0000000000000041L),
          Symbol.valueOf("amqp:sasl-init:list"));
}
 
Example #19
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMessageAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   MessageAnnotations decoded = message.getMessageAnnotations();
   assertNotSame(decoded, protonMessage.getMessageAnnotations());
   assertMessageAnnotationsEquals(protonMessage.getMessageAnnotations(), decoded);

   // Update the values
   decoded.getValue().put(Symbol.valueOf(UUID.randomUUID().toString()), "test");

   // Check that the message is unaffected.
   assertMessageAnnotationsNotEquals(protonMessage.getMessageAnnotations(), decoded);
}
 
Example #20
Source File: MessageImpl.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void setContentEncoding(String contentEncoding)
{
    if(_properties == null)
    {
        if(contentEncoding == null)
        {
            return;
        }
        _properties = new Properties();
    }
    _properties.setContentEncoding(Symbol.valueOf(contentEncoding));
}
 
Example #21
Source File: SubscriptionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doSharedSubscriptionLinkCapabilitySupportedTestImpl(boolean durable) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        // DONT include server connection capability to indicate support for shared-subs.
        // This will cause the link capability to be desired, and we verify success if offered.
        Symbol[] serverCapabilities = new Symbol[]{};

        Connection connection = testFixture.establishConnecton(testPeer, serverCapabilities);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);
        String subscriptionName = "mySubscription";

        // Expect a shared receiver to attach, and succeed due to the server offering
        // the shared subs capability, i.e sharing is supported.
        if (durable) {
            Matcher<?> durableLinkNameMatcher = equalTo(subscriptionName);
            testPeer.expectSharedSubscriberAttach(topicName, subscriptionName, durableLinkNameMatcher, true, false, true, true, true);
            testPeer.expectLinkFlow();

            session.createSharedDurableConsumer(dest, subscriptionName);
        } else {
            Matcher<?> volatileLinkNameMatcher = equalTo(subscriptionName + SUB_NAME_DELIMITER + "volatile1");
            testPeer.expectSharedSubscriberAttach(topicName, subscriptionName, volatileLinkNameMatcher, false, false, true, true, true);
            testPeer.expectLinkFlow();

            session.createSharedConsumer(dest, subscriptionName);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #22
Source File: AmqpCoreConverter.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static byte parseQueueAnnotation(MessageAnnotations annotations, Symbol symbol) {
   Object value = (annotations != null && annotations.getValue() != null ? annotations.getValue().get(symbol) : AMQPMessageSupport.QUEUE_TYPE);

   byte queueType;
   if (value == null || !(value instanceof Number)) {
      queueType = AMQPMessageSupport.QUEUE_TYPE;
   } else {
      queueType = ((Number)value).byteValue();
   }
   return queueType;
}
 
Example #23
Source File: AmqpConnectionSession.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected Receiver createEndpoint(JmsSessionInfo resourceInfo) {
    Receiver receiver = getParent().getEndpoint().receiver(linkName);
    receiver.setTarget(new Target());
    receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    if (!hasClientID) {
      // We are trying to unsubscribe a 'global' shared subs using a 'null source lookup', add link
      // desired capabilities as hints to the peer to consider this when trying to attach the link.
      receiver.setDesiredCapabilities(new Symbol[] { AmqpSupport.SHARED, AmqpSupport.GLOBAL });
    }

    return receiver;
}
 
Example #24
Source File: SymbolType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public Symbol readValue()
{
    DecoderImpl decoder = getDecoder();
    int size = ((int)decoder.readRawByte()) & 0xff;
    return decoder.readRaw(_symbolCreator, size);
}
 
Example #25
Source File: NettySimpleAmqpServer.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private Map<Symbol, Object> getConnetionProperties() {
    Map<Symbol, Object> properties = new HashMap<Symbol, Object>();

    properties.put(PRODUCT, "Qpid-JMS-NettyServer");
    properties.put(VERSION, "1.0");
    properties.put(PLATFORM, "java");

    return properties;
}
 
Example #26
Source File: TestAmqpPeer.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public void expectAndRefuseTempTopicCreationAttach(Symbol errorType, String errorMessage, boolean deferAttachResponseWrite)
{
    expectTempNodeCreationAttach(null, AmqpDestinationHelper.TEMP_TOPIC_CAPABILITY, true, deferAttachResponseWrite, errorType, errorMessage);
}
 
Example #27
Source File: SymbolType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
protected int getEncodedValueSize(final Symbol val)
{
    return val.length();
}
 
Example #28
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testErrorConditionAfterTransportClosed() {
    Symbol condition = Symbol.getSymbol("some-error");
    String description = "some-error-description";
    ErrorCondition origErrorCondition = new ErrorCondition();
    origErrorCondition.setCondition(condition);
    origErrorCondition.setDescription(description);
    assertNotNull("Expected a Condition", origErrorCondition.getCondition());

    // Set an error condition, then call 'closed' specifying an error.
    // Expect the original condition which was set to remain.
    TransportImpl transport = new TransportImpl();

    transport.setCondition(origErrorCondition);
    transport.closed(new TransportException("my-ignored-exception"));

    assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
    assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition());

    // ---------------------------------------------------------------- //

    // Set an error condition, then call 'closed' without an error.
    // Expect the original condition which was set to remain.
    transport = new TransportImpl();

    transport.setCondition(origErrorCondition);
    transport.closed(null);

    assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
    assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition());

    // ---------------------------------------------------------------- //

    // Without having set an error condition, call 'closed' specifying an error.
    // Expect a condition to be set.
    transport = new TransportImpl();
    transport.closed(new TransportException(description));

    assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
    assertEquals("Unexpected condition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition());
    assertEquals("Unexpected description returned", "org.apache.qpid.proton.engine.TransportException: " + description, transport.getCondition().getDescription());

    // ---------------------------------------------------------------- //

    // Without having set an error condition, call 'closed' without an error.
    // Expect a condition to be set.
    transport = new TransportImpl();

    transport.closed(null);

    assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
    assertEquals("Unexpected ErrorCondition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition());
    assertEquals("Unexpected description returned", "connection aborted", transport.getCondition().getDescription());
}
 
Example #29
Source File: Declare.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
public Symbol getDescriptor()
{
    return DESCRIPTOR_SYMBOL;
}
 
Example #30
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testConvertMessageWithMapInFooter() throws Exception {
   Map<String, Object> mapprop = createPropertiesMap();
   ApplicationProperties properties = new ApplicationProperties(mapprop);
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setApplicationProperties(properties);

   final String footerName = "test-footer";
   final Symbol footerNameSymbol = Symbol.valueOf(footerName);

   Map<String, String> embeddedMap = new LinkedHashMap<>();
   embeddedMap.put("key1", "value1");
   embeddedMap.put("key2", "value2");
   embeddedMap.put("key3", "value3");
   Map<Symbol, Object> footerMap = new LinkedHashMap<>();
   footerMap.put(footerNameSymbol, embeddedMap);
   Footer messageFooter = new Footer(footerMap);
   byte[] encodedEmbeddedMap = encodeObject(embeddedMap);

   Map<String, Object> mapValues = new HashMap<>();
   mapValues.put("somestr", "value");
   mapValues.put("someint", Integer.valueOf(1));

   message.setFooter(messageFooter);
   message.setBody(new AmqpValue(mapValues));

   AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message);

   ICoreMessage serverMessage = encodedMessage.toCore();
   serverMessage.getReadOnlyBodyBuffer();

   ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
   mapMessage.decode();

   verifyProperties(mapMessage);

   assertEquals(1, mapMessage.getInt("someint"));
   assertEquals("value", mapMessage.getString("somestr"));
   assertTrue(mapMessage.propertyExists(JMS_AMQP_ENCODED_FOOTER_PREFIX + footerName));
   assertArrayEquals(encodedEmbeddedMap, (byte[]) mapMessage.getObjectProperty(JMS_AMQP_ENCODED_FOOTER_PREFIX + footerName));

   AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null);
   assertNotNull(newAMQP.getBody());
   assertNotNull(newAMQP.getFooter());
   assertNotNull(newAMQP.getFooter().getValue());
   assertTrue(newAMQP.getFooter().getValue().containsKey(footerNameSymbol));
   Object result = newAMQP.getFooter().getValue().get(footerNameSymbol);
   assertTrue(result instanceof Map);
   assertEquals(embeddedMap, (Map<String, String>) result);
}