use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.
the class ConnectionDispatcher method visit.
public void visit(POOpen po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
openPO = po;
try {
OpenFrame openFrame = new OpenFrame(0);
openFrame.setContainerId(new AMQPString(po.getContainerId()));
openFrame.setChannelMax(new AMQPUnsignedShort(po.getMaxChannel()));
if (myConnection.getOpenHostname() == null)
openFrame.setHostname(new AMQPString(remoteHostname));
else
openFrame.setHostname(new AMQPString(myConnection.getOpenHostname()));
maxLocalFrameSize = po.getMaxFrameSize() > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) po.getMaxFrameSize();
openFrame.setMaxFrameSize(new AMQPUnsignedInt(maxLocalFrameSize));
myIdleTimeout = po.getIdleTimeout();
if (myIdleTimeout > 0) {
openFrame.setIdleTimeOut(new Milliseconds(myIdleTimeout));
idleTimeoutDelay = po.getIdleTimeout() / 2;
idleTimeoutChecker = new TimerListener() {
public void performTimeAction(TimerEvent evt) {
dispatch(new POCheckIdleTimeout(null));
}
};
TimerRegistry.Singleton().addTimerListener(idleTimeoutDelay, idleTimeoutChecker);
}
outboundHandler.send(openFrame);
} catch (Exception e) {
e.printStackTrace();
}
checkBothSidesOpen();
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transformApplicationProperties.
protected void transformApplicationProperties(ApplicationProperties applicationProperties, MessageImpl jmsMessage) throws Exception {
Map map = applicationProperties.getValue();
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
AMQPType key = (AMQPType) entry.getKey();
AMQPDescribedConstructor constructor = key.getConstructor();
int code = constructor != null ? constructor.getFormatCode() : key.getCode();
String propName = null;
if (AMQPTypeDecoder.isString(code))
propName = nameTranslator.translate(((AMQPString) key).getValue());
else if (AMQPTypeDecoder.isSymbol(code))
propName = nameTranslator.translate(((AMQPSymbol) key).getValue());
if (propName != null) {
if (jmsTypeProp != null && propName.equals(jmsTypeProp)) {
AMQPType t = (AMQPType) entry.getValue();
if (AMQPTypeDecoder.isString(t.getCode()))
jmsMessage.setJMSType(((AMQPString) entry.getValue()).getValue());
else
jmsMessage.setStringProperty("JMS_TYPE_ERROR", jmsTypeProp + " must be of String value");
} else {
try {
jmsMessage.setObjectProperty(propName, Util.convertAMQPtoJMS((AMQPType) entry.getValue()));
} catch (Exception e) {
jmsMessage.setStringProperty(propName + "_ERROR", e.getMessage());
}
}
}
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transformMap.
protected void transformMap(Map map, MessageImpl jmsMessage, String prefix) throws Exception {
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
boolean isJMSType = false;
Map.Entry entry = (Map.Entry) iter.next();
AMQPType key = (AMQPType) entry.getKey();
AMQPDescribedConstructor constructor = key.getConstructor();
int code = constructor != null ? constructor.getFormatCode() : key.getCode();
String propName = null;
if (AMQPTypeDecoder.isULong(code))
propName = prefix + String.valueOf(((AMQPUnsignedLong) key).getValue());
else if (AMQPTypeDecoder.isSymbol(code)) {
if (prefix.equals(prefixMA) && ((AMQPSymbol) key).getValue().equals("x-opt-jms-type"))
isJMSType = true;
propName = prefix + nameTranslator.translate(((AMQPSymbol) key).getValue());
}
if (isJMSType) {
AMQPType t = (AMQPType) entry.getValue();
if (AMQPTypeDecoder.isString(t.getCode()))
jmsMessage.setJMSType(((AMQPString) entry.getValue()).getValue());
else
jmsMessage.setStringProperty("JMS_TYPE_ERROR", "x-opt-jms-type must be of String value");
} else if (propName != null) {
try {
jmsMessage.setObjectProperty(propName, Util.convertAMQPtoJMS((AMQPType) entry.getValue()));
} catch (Exception e) {
jmsMessage.setStringProperty(propName + "_ERROR", e.getMessage());
}
}
}
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transformProperties.
protected void transformProperties(Properties properties, final MessageImpl jmsMessage, final DestinationFactory destinationFactory) throws Exception {
if (overwriteMessageId) {
jmsMessage.setJMSMessageID(nextMsgId());
} else {
MessageIdIF messageIdIF = properties.getMessageId();
if (messageIdIF != null)
messageIdIF.accept(new MessageIdVisitor() {
public void visit(MessageIdUlong messageIdUlong) {
try {
jmsMessage.setJMSMessageID(String.valueOf(messageIdUlong.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdUuid messageIdUuid) {
try {
jmsMessage.setJMSMessageID(String.valueOf(messageIdUuid.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdBinary messageIdBinary) {
try {
jmsMessage.setJMSMessageID(new String(messageIdBinary.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdString messageIdString) {
try {
jmsMessage.setJMSMessageID(messageIdString.getValue());
} catch (JMSException e) {
}
}
});
}
AMQPBinary userId = properties.getUserId();
if (userId != null)
jmsMessage.setStringProperty(MessageImpl.PROP_USER_ID, new String(userId.getValue(), "ISO-8859-1"));
AddressIF to = properties.getTo();
if (to != null) {
jmsMessage.setJMSDestination(destinationFactory.create(to));
to.accept(new AddressVisitor() {
public void visit(AddressString addressString) {
try {
jmsMessage.setStringProperty(Util.PROP_AMQP_TO_ADDRESS, addressString.getValue());
} catch (JMSException e) {
}
}
});
}
AMQPString subject = properties.getSubject();
if (subject != null)
jmsMessage.setStringProperty(prefixVendor + "Subject", subject.getValue());
AddressIF replyTo = properties.getReplyTo();
if (replyTo != null)
jmsMessage.setJMSReplyTo(destinationFactory.create(replyTo));
MessageIdIF correlationIdIF = properties.getCorrelationId();
if (correlationIdIF != null)
correlationIdIF.accept(new MessageIdVisitor() {
public void visit(MessageIdUlong messageIdUlong) {
try {
jmsMessage.setJMSCorrelationID(String.valueOf(messageIdUlong.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdUuid messageIdUuid) {
try {
jmsMessage.setJMSCorrelationID(String.valueOf(messageIdUuid.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdBinary messageIdBinary) {
try {
jmsMessage.setJMSCorrelationID(new String(messageIdBinary.getValue()));
} catch (JMSException e) {
}
}
public void visit(MessageIdString messageIdString) {
try {
jmsMessage.setJMSCorrelationID(messageIdString.getValue());
} catch (JMSException e) {
}
}
});
AMQPSymbol contentType = properties.getContentType();
if (contentType != null)
jmsMessage.setStringProperty(prefixVendor + "ContentType", contentType.getValue());
AMQPSymbol contentEncoding = properties.getContentEncoding();
if (contentEncoding != null)
jmsMessage.setStringProperty(prefixVendor + "ContentEncoding", contentEncoding.getValue());
AMQPTimestamp ts = properties.getAbsoluteExpiryTime();
if (ts != null)
jmsMessage.setJMSExpiration(ts.getValue());
AMQPTimestamp ct = properties.getCreationTime();
if (ct != null)
jmsMessage.setJMSTimestamp(ct.getValue());
AMQPString groupId = properties.getGroupId();
if (groupId != null)
jmsMessage.setStringProperty(Util.PROP_GROUP_ID, groupId.getValue());
SequenceNo groupSeq = properties.getGroupSequence();
if (groupSeq != null)
jmsMessage.setLongProperty(Util.PROP_GROUP_SEQ, groupSeq.getValue());
AMQPString replyToGroupId = properties.getReplyToGroupId();
if (replyToGroupId != null)
jmsMessage.setStringProperty(prefixVendor + "ReplyToGroupID", replyToGroupId.getValue());
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.
the class MessageTypeBodyFactory method createBody.
public void createBody(MessageImpl jmsMessage, AMQPMessage amqpMessage) throws JMSException, AMQPException {
jmsMessage.reset();
if (jmsMessage instanceof TextMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPString(((TextMessageImpl) jmsMessage).getText())));
} else if (jmsMessage instanceof MapMessageImpl) {
MapMessageImpl msg = (MapMessageImpl) jmsMessage;
Map map = new HashMap();
for (Enumeration _enum = msg.getMapNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
map.put(new AMQPString(name), Util.convertJMStoAMQP(msg.getObject(name)));
}
try {
amqpMessage.setAmqpValue(new AmqpValue(new AMQPMap(map)));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
} else if (jmsMessage instanceof BytesMessageImpl) {
BytesMessageImpl msg = (BytesMessageImpl) jmsMessage;
byte[] b = new byte[(int) msg.getBodyLength()];
msg.readBytes(b);
amqpMessage.addData(new Data(b));
} else if (jmsMessage instanceof ObjectMessageImpl) {
amqpMessage.setAmqpValue(new AmqpValue(Util.convertJMStoAMQP(((ObjectMessageImpl) jmsMessage).getObject())));
} else if (jmsMessage instanceof StreamMessageImpl) {
List list = new ArrayList();
StreamMessageImpl msg = (StreamMessageImpl) jmsMessage;
try {
for (; ; ) {
list.add(Util.convertJMStoAMQP(msg.readObject()));
}
} catch (MessageEOFException e) {
}
try {
amqpMessage.addAmqpSequence(new AmqpSequence(list));
} catch (IOException e) {
throw new AMQPException(e.toString());
}
}
}
Aggregations