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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations