Search in sources :

Example 11 with Symbol

use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.

the class MessageConverter_from_1_0 method getAmqp0xTypeHint.

private static ContentHint getAmqp0xTypeHint(final Message_1_0 serverMsg) {
    Symbol contentType = getContentType(serverMsg);
    JmsMessageTypeAnnotation jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(serverMsg);
    String mimeTypeHint = null;
    Class<?> classHint = getContentTypeClassHint(jmsMessageTypeAnnotation);
    if (contentType != null) {
        Class<?> contentTypeClassHint = null;
        String type = contentType.toString();
        String supportedContentType = null;
        if (ConversionUtils.TEXT_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = String.class;
            // the AMQP 0-x client does not accept arbitrary "text/*" mimeTypes so use "text/plain"
            supportedContentType = "text/plain";
        } else if (ConversionUtils.MAP_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = Map.class;
            supportedContentType = contentType.toString();
        } else if (ConversionUtils.LIST_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = List.class;
            supportedContentType = contentType.toString();
        } else if (ConversionUtils.OBJECT_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = Serializable.class;
            // the AMQP 0-x client does not accept the "application/x-java-serialized-object" mimeTypes so use fall back
            supportedContentType = "application/java-object-stream";
        } else if (ConversionUtils.BYTES_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = byte[].class;
            supportedContentType = "application/octet-stream";
        }
        if (classHint == null || classHint == contentTypeClassHint) {
            classHint = contentTypeClassHint;
            mimeTypeHint = supportedContentType;
        }
    }
    return new ContentHint(classHint, mimeTypeHint);
}
Also used : Serializable(java.io.Serializable) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with Symbol

use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.

the class MessageConverter_from_1_0 method getContentType.

public static Symbol getContentType(final Message_1_0 serverMsg) {
    final PropertiesSection propertiesSection = serverMsg.getPropertiesSection();
    if (propertiesSection != null) {
        final Properties properties = propertiesSection.getValue();
        propertiesSection.dispose();
        if (properties != null) {
            return properties.getContentType();
        }
    }
    return null;
}
Also used : PropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.PropertiesSection) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 13 with Symbol

use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.

the class MessageConverter_from_1_0 method getJmsMessageTypeAnnotation.

static JmsMessageTypeAnnotation getJmsMessageTypeAnnotation(final Message_1_0 serverMsg) {
    JmsMessageTypeAnnotation jmsMessageTypeAnnotation = null;
    MessageAnnotationsSection section = serverMsg.getMessageAnnotationsSection();
    if (section != null) {
        Map<Symbol, Object> annotations = section.getValue();
        section.dispose();
        if (annotations != null && annotations.containsKey(JmsMessageTypeAnnotation.ANNOTATION_KEY)) {
            Object object = annotations.get(JmsMessageTypeAnnotation.ANNOTATION_KEY);
            if (object instanceof Byte) {
                try {
                    jmsMessageTypeAnnotation = JmsMessageTypeAnnotation.valueOf(((Byte) object));
                } catch (IllegalArgumentException e) {
                // ignore
                }
            }
        }
    }
    return jmsMessageTypeAnnotation;
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) UnsignedByte(org.apache.qpid.server.protocol.v1_0.type.UnsignedByte) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection)

Example 14 with Symbol

use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.

the class MessageConverter_to_1_0 method createMessageAnnotation.

public static MessageAnnotations createMessageAnnotation(final EncodingRetainingSection<?> bodySection, final String contentMimeType) {
    MessageAnnotations messageAnnotations = null;
    final Symbol key = Symbol.valueOf("x-opt-jms-msg-type");
    if (contentMimeType != null) {
        if (TEXT_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, TEXT_MESSAGE.getType()));
        } else if (BYTES_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, BYTES_MESSAGE.getType()));
        } else if (MAP_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            if (isSectionValidForJmsMap(bodySection)) {
                messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MAP_MESSAGE.getType()));
            }
        } else if (LIST_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            if (isSectionValidForJmsList(bodySection)) {
                messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, STREAM_MESSAGE.getType()));
            }
        } else if (OBJECT_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, OBJECT_MESSAGE.getType()));
        }
    } else if (bodySection instanceof AmqpValueSection && bodySection.getValue() == null) {
        messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MESSAGE.getType()));
    }
    return messageAnnotations;
}
Also used : MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 15 with Symbol

use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.

the class MessageConverter_v1_0_to_Internal method getInternalTypeHint.

private static MessageConverter_from_1_0.ContentHint getInternalTypeHint(final Message_1_0 serverMsg) {
    Symbol contentType = MessageConverter_from_1_0.getContentType(serverMsg);
    JmsMessageTypeAnnotation jmsMessageTypeAnnotation = MessageConverter_from_1_0.getJmsMessageTypeAnnotation(serverMsg);
    Class<?> classHint = MessageConverter_from_1_0.getContentTypeClassHint(jmsMessageTypeAnnotation);
    String mimeTypeHint = null;
    if (contentType != null) {
        Class<?> contentTypeClassHint = null;
        String type = contentType.toString();
        if (ConversionUtils.TEXT_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = String.class;
        } else if (ConversionUtils.MAP_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = Map.class;
        } else if (ConversionUtils.LIST_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = List.class;
        } else if (ConversionUtils.OBJECT_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = Serializable.class;
        } else if (ConversionUtils.BYTES_MESSAGE_CONTENT_TYPES.matcher(type).matches()) {
            contentTypeClassHint = byte[].class;
        }
        if (classHint == null || classHint == contentTypeClassHint) {
            classHint = contentTypeClassHint;
        }
        mimeTypeHint = contentType.toString();
    }
    return new MessageConverter_from_1_0.ContentHint(classHint, mimeTypeHint);
}
Also used : Serializable(java.io.Serializable) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) Map(java.util.Map)

Aggregations

Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)27 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)11 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 Map (java.util.Map)6 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)6 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3