Search in sources :

Example 61 with BasicContentHeaderProperties

use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.

the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationFails.

public void testPublishContentHeaderWhenMessageAuthorizationFails() throws Exception {
    final String impostorId = "impostor";
    doThrow(new AccessControlException("fail")).when(_amqConnection).checkAuthorizedMessagePrincipal(eq(impostorId));
    when(_virtualHost.getDefaultDestination()).thenReturn(mock(MessageDestination.class));
    when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {

        @Override
        public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
            MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
            return messageHandle;
        }
    });
    int channelId = 1;
    AMQChannel channel = new AMQChannel(_amqConnection, channelId, _virtualHost.getMessageStore());
    BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
    properties.setUserId(impostorId);
    channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, AMQShortString.EMPTY_STRING, false, false);
    channel.receiveMessageHeader(properties, 0);
    verify(_amqConnection).sendConnectionClose(eq(ErrorCodes.ACCESS_REFUSED), anyString(), eq(channelId));
    verifyZeroInteractions(_messageDestination);
}
Also used : MessageHandle(org.apache.qpid.server.store.MessageHandle) MessageDestination(org.apache.qpid.server.message.MessageDestination) AccessControlException(java.security.AccessControlException) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Matchers.anyString(org.mockito.Matchers.anyString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 62 with BasicContentHeaderProperties

use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.

the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationSucceeds.

public void testPublishContentHeaderWhenMessageAuthorizationSucceeds() throws Exception {
    when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
    when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {

        @Override
        public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
            MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
            return messageHandle;
        }
    });
    final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            ServerMessage message = messageCaptor.getValue();
            return new RoutingResult(message);
        }
    }).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
    AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
    BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
    properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
    channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
    channel.receiveMessageHeader(properties, 0);
    verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) RoutingResult(org.apache.qpid.server.message.RoutingResult) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MessageHandle(org.apache.qpid.server.store.MessageHandle) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 63 with BasicContentHeaderProperties

use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.

the class MessageMetaDataFactoryTest method createTestMessageMetaData.

private MessageMetaData createTestMessageMetaData() {
    final MessagePublishInfo publishBody = new MessagePublishInfo(_exchange, false, false, _routingKey);
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setContentType(CONTENT_TYPE);
    final ContentHeaderBody contentHeaderBody = new ContentHeaderBody(props);
    return new MessageMetaData(publishBody, contentHeaderBody, _arrivalTime);
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 64 with BasicContentHeaderProperties

use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.

the class PropertyConverter_v0_8_to_InternalTest method testContentEncodingConversion.

public void testContentEncodingConversion() {
    String contentEncoding = "my-test-encoding";
    BasicContentHeaderProperties header = new BasicContentHeaderProperties();
    header.setEncoding(contentEncoding);
    final AMQMessage originalMessage = createTestMessage(header);
    InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected content encoding", contentEncoding, convertedMessage.getMessageHeader().getEncoding());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 65 with BasicContentHeaderProperties

use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.

the class PropertyConverter_v0_8_to_InternalTest method testHeadersConversion.

public void testHeadersConversion() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("testProperty1", "testProperty1Value");
    properties.put("intProperty", 1);
    BasicContentHeaderProperties header = new BasicContentHeaderProperties();
    header.setHeaders(FieldTable.convertToFieldTable(properties));
    final AMQMessage originalMessage = createTestMessage(header);
    final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    final Map<String, Object> headers = convertedMessage.getMessageHeader().getHeaderMap();
    assertEquals("Unexpected headers", properties, new HashMap<>(headers));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) HashMap(java.util.HashMap) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Aggregations

BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)151 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)115 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)74 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)59 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)52 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)48 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)39 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)31 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)21 Matchers.anyString (org.mockito.Matchers.anyString)20 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)18 HashMap (java.util.HashMap)16 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)16 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)12 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)9 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)7 Date (java.util.Date)6 UUID (java.util.UUID)6 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)6