use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_8 method getReplyTo.
private String getReplyTo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
String replyTo = serverMsg.getMessageHeader().getReplyTo();
if (replyTo != null) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
final String replyToBindingUrl;
if (messageDestination instanceof Exchange) {
Exchange<?> exchange = (Exchange<?>) messageDestination;
final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
} else if (messageDestination instanceof Queue) {
replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
} else {
replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
}
return replyToBindingUrl;
}
return null;
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class MessageConverter_0_10_to_0_8 method convertContentHeaderProperties.
public static BasicContentHeaderProperties convertContentHeaderProperties(MessageTransferMessage messageTransferMessage, NamedAddressSpace addressSpace) {
BasicContentHeaderProperties props = new BasicContentHeaderProperties();
Header header = messageTransferMessage.getHeader();
DeliveryProperties deliveryProps = header.getDeliveryProperties();
MessageProperties messageProps = header.getMessageProperties();
if (deliveryProps != null) {
if (deliveryProps.hasDeliveryMode()) {
props.setDeliveryMode((deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
}
if (deliveryProps.hasTtl()) {
props.setExpiration(messageTransferMessage.getArrivalTime() + deliveryProps.getTtl());
} else if (deliveryProps.hasExpiration()) {
props.setExpiration(deliveryProps.getExpiration());
}
if (deliveryProps.hasPriority()) {
props.setPriority((byte) deliveryProps.getPriority().getValue());
}
if (deliveryProps.hasTimestamp()) {
props.setTimestamp(deliveryProps.getTimestamp());
} else {
props.setTimestamp(messageTransferMessage.getArrivalTime());
}
}
if (messageProps != null) {
if (messageProps.hasAppId()) {
try {
props.setAppId(AMQShortString.createAMQShortString(messageProps.getAppId()));
} catch (IllegalArgumentException e) {
// pass
}
}
if (messageProps.hasContentType()) {
props.setContentType(messageProps.getContentType());
}
if (messageProps.hasCorrelationId()) {
try {
props.setCorrelationId(AMQShortString.createAMQShortString(messageProps.getCorrelationId()));
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'correlationId' failed.", e);
}
}
if (messageProps.hasContentEncoding()) {
props.setEncoding(messageProps.getContentEncoding());
}
if (messageProps.hasMessageId()) {
// Add prefix 'ID:' to workaround broken 0-8..0-9-1 Qpid JMS client
props.setMessageId("ID:" + messageProps.getMessageId().toString());
}
if (messageProps.hasReplyTo()) {
ReplyTo replyTo = messageProps.getReplyTo();
String exchangeName = replyTo.getExchange();
String routingKey = replyTo.getRoutingKey();
if (exchangeName == null) {
exchangeName = "";
}
if (!"".equals(exchangeName) || (routingKey != null && !"".equals(routingKey))) {
MessageDestination destination = addressSpace.getAttainedMessageDestination(exchangeName, false);
Exchange<?> exchange = destination instanceof Exchange ? (Exchange<?>) destination : null;
String exchangeClass = exchange == null ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS : exchange.getType();
String routingKeyOption = routingKey == null ? "" : "?routingkey='" + routingKey + "'";
final String replyToBindingUrl = String.format("%s://%s//%s", exchangeClass, exchangeName, routingKeyOption);
try {
props.setReplyTo(replyToBindingUrl);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'reply-to' failed.", e);
}
}
}
if (messageProps.hasUserId()) {
try {
props.setUserId(AMQShortString.createAMQShortString(messageProps.getUserId()));
} catch (IllegalArgumentException e) {
// ignore
}
}
if (messageProps.hasApplicationHeaders()) {
Map<String, Object> appHeaders = new HashMap<String, Object>(messageProps.getApplicationHeaders());
if (messageProps.getApplicationHeaders().containsKey("x-jms-type")) {
String jmsType = String.valueOf(appHeaders.remove("x-jms-type"));
try {
props.setType(jmsType);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because x-jms-type conversion failed.", e);
}
}
FieldTable ft;
try {
ft = FieldTableFactory.createFieldTable(appHeaders);
} catch (IllegalArgumentException | AMQPInvalidClassException e) {
throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of application headers failed.", e);
}
props.setHeaders(ft);
}
}
return props;
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class Session_1_0Test method findBinding.
private Binding findBinding(final String exchangeName, final String bindingName) {
Exchange exchange = _virtualHost.findConfiguredObject(Exchange.class, exchangeName);
Collection<Binding> bindings = exchange.getBindings();
Binding binding = null;
for (Binding b : bindings) {
if (bindingName.equals(b.getName())) {
binding = b;
break;
}
}
return binding;
}
Aggregations