use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class EndpointImpl method poll.
public void poll() {
try {
AMQPMessage msg = consumer.receiveNoWait(this);
if (msg != null) {
Data data = msg.getData().get(0);
dis.reset();
dis.setBuffer(data.getValue());
Dumpable d = Dumpalizer.construct(dis, factory);
if (d instanceof Reply)
requestRegistry.setReply((Reply) d);
else
dispatch((Request) d);
pollerService.execute(poller);
}
} catch (Exception e) {
e.printStackTrace();
close();
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-client by iitsoftware.
the class EndpointImpl method performRequest.
public synchronized void performRequest(Request request) {
try {
dos.rewind();
Dumpalizer.dump(dos, request);
AMQPMessage msg = new AMQPMessage();
byte[] bytes = new byte[dos.getCount()];
System.arraycopy(dos.getBuffer(), 0, bytes, 0, bytes.length);
msg.addData(new Data(bytes));
Properties prop = new Properties();
if (connection.getUserName() == null)
prop.setUserId(new AMQPBinary("anonymous".getBytes()));
else
prop.setUserId(new AMQPBinary(connection.getUserName().getBytes()));
prop.setReplyTo(replyAddress);
msg.setProperties(prop);
producer.send(msg);
} catch (Exception e) {
close();
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class TargetLink method handleTransactionRequest.
private void handleTransactionRequest(TransferFrame frame) throws EndWithErrorException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, frame=" + frame);
AMQPMessage msg = null;
try {
msg = new AMQPMessage(frame.getPayload());
} catch (Exception e) {
e.printStackTrace();
new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Exception during decode of a message: " + e));
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, msg=" + msg);
if (msg.getAmqpValue() == null)
throw new SessionEndException(AmqpError.NOT_FOUND, new AMQPString("Missing amqp-value message body in transaction request!"));
AMQPType bare = msg.getAmqpValue().getValue();
AMQPDescribedConstructor constructor = bare.getConstructor();
if (constructor == null)
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Missing constructor: " + bare));
if (!AMQPTypeDecoder.isList(constructor.getFormatCode()))
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Message body is not of a list type, code=0x" + Integer.toHexString(bare.getCode()) + ", bare=" + bare));
AMQPType descriptor = constructor.getDescriptor();
int code = descriptor.getCode();
try {
if (AMQPTypeDecoder.isULong(code)) {
long type = ((AMQPUnsignedLong) descriptor).getValue();
if (type == Declare.DESCRIPTOR_CODE)
handleDeclare(new Declare(((AMQPList) bare).getValue()));
else if (type == Discharge.DESCRIPTOR_CODE)
handleDischarge(new Discharge(((AMQPList) bare).getValue()));
else
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
} else if (AMQPTypeDecoder.isSymbol(code)) {
String type = ((AMQPSymbol) descriptor).getValue();
if (type.equals(Declare.DESCRIPTOR_NAME))
handleDeclare(new Declare(((AMQPList) bare).getValue()));
else if (type.equals(Discharge.DESCRIPTOR_NAME))
handleDischarge(new Discharge(((AMQPList) bare).getValue()));
else
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
} else
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare));
} catch (Exception e) {
e.printStackTrace();
throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString(e.toString()));
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class JMSMappingOutboundTransformer method transform.
public void transform(Delivery delivery) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl message = delivery.getMessage();
if (message.propertyExists(amqpNative) && message.getBooleanProperty(amqpNative))
throw new JMSException("Message is an AMQP native transformation");
try {
AMQPMessage amqpMessage = new AMQPMessage();
Header header = new Header();
int deliveryMode = message.getJMSDeliveryMode();
header.setDurable(new AMQPBoolean(deliveryMode == DeliveryMode.PERSISTENT));
header.setPriority(new AMQPUnsignedByte(message.getJMSPriority()));
header.setDeliveryCount(new AMQPUnsignedInt(delivery.getMessageIndex().getDeliveryCount() - 1));
long ttl = message.getJMSExpiration();
if (ttl > 0) {
if (message.propertyExists(Util.PROP_EXPIRATION_CURRENT_TIME_ADD))
header.setTtl(new Milliseconds(ttl - message.getLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD)));
}
Properties properties = new Properties();
String messageId = message.getJMSMessageID();
if (messageId != null)
properties.setMessageId(new MessageIdString(message.getJMSMessageID()));
if (message.propertyExists(Util.PROP_AMQP_TO_ADDRESS))
properties.setTo(new AddressString(message.getStringProperty(Util.PROP_AMQP_TO_ADDRESS)));
else
properties.setTo(new AddressString(message.getJMSDestination().toString()));
Destination replyTo = message.getJMSReplyTo();
if (replyTo != null)
properties.setReplyTo(new AddressString(replyTo.toString()));
String correlationId = message.getJMSCorrelationID();
if (correlationId != null)
properties.setCorrelationId(new MessageIdString(correlationId));
if (ttl > 0)
properties.setAbsoluteExpiryTime(new AMQPTimestamp(ttl));
long timestamp = message.getJMSTimestamp();
if (timestamp > 0)
properties.setCreationTime(new AMQPTimestamp(timestamp));
Map daMap = null;
Map maMap = null;
Map ftMap = null;
Map apMap = null;
String firstAcquirerName = prefixVendor + "FirstAcquirer";
String subject = prefixVendor + "Subject";
String contentType = prefixVendor + "ContentType";
String contentEncoding = prefixVendor + "ContentEncoding";
String replyToGroupId = prefixVendor + "ReplyToGroupID";
for (Enumeration _enum = message.getPropertyNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
if (name.equals(amqpNative) || name.equals(messageFormat) || name.equals(Util.PROP_EXPIRATION_CURRENT_TIME_ADD) || name.equals(Util.PROP_AMQP_TO_ADDRESS))
continue;
if (name.equals(firstAcquirerName))
header.setFirstAcquirer(new AMQPBoolean(message.getBooleanProperty(firstAcquirerName)));
else if (name.equals(MessageImpl.PROP_USER_ID))
properties.setUserId(new AMQPBinary(message.getStringProperty(MessageImpl.PROP_USER_ID).getBytes()));
else if (name.equals(subject))
properties.setSubject(new AMQPString(message.getStringProperty(subject)));
else if (name.equals(contentType))
properties.setContentType(new AMQPSymbol(message.getStringProperty(contentType)));
else if (name.equals(contentEncoding))
properties.setContentEncoding(new AMQPSymbol(message.getStringProperty(contentEncoding)));
else if (name.equals("JMSXGroupID") && message.getObjectProperty(Util.PROP_GROUP_ID) instanceof String)
properties.setGroupId(new AMQPString(message.getStringProperty(Util.PROP_GROUP_ID)));
else if (name.equals("JMSXGroupSeq") && message.getObjectProperty(Util.PROP_GROUP_SEQ) instanceof Long)
properties.setGroupSequence(new SequenceNo(message.getLongProperty(Util.PROP_GROUP_SEQ)));
else if (name.equals(replyToGroupId))
properties.setReplyToGroupId(new AMQPString(message.getStringProperty(replyToGroupId)));
else if (name.startsWith(prefixDA)) {
if (daMap == null)
daMap = new HashMap();
daMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixDA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixMA)) {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixMA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixFT)) {
if (ftMap == null)
ftMap = new HashMap();
ftMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixFT.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(nameTranslator.translate(name)), Util.convertJMStoAMQP(message.getObjectProperty(name)));
}
}
if (message.getJMSType() != null) {
if (jmsTypeProp != null) {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(jmsTypeProp), Util.convertJMStoAMQP(message.getJMSType()));
} else {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol("x-opt-jms-type"), new AMQPString(message.getJMSType()));
}
}
amqpMessage.setHeader(header);
amqpMessage.setProperties(properties);
if (daMap != null)
amqpMessage.setDeliveryAnnotations(new DeliveryAnnotations(daMap));
if (maMap != null)
amqpMessage.setMessageAnnotations(new MessageAnnotations(maMap));
if (apMap != null)
amqpMessage.setApplicationProperties(new ApplicationProperties(apMap));
if (ftMap != null)
amqpMessage.setFooter(new Footer(ftMap));
bodyFactory.createBody(message, amqpMessage);
delivery.setAmqpMessage(amqpMessage);
dbos.rewind();
amqpMessage.writeContent(dbos);
byte[] payload = new byte[dbos.getCount()];
System.arraycopy(dbos.getBuffer(), 0, payload, 0, dbos.getCount());
delivery.setData(payload);
delivery.setMessageFormat(0);
} catch (IOException e) {
e.printStackTrace();
throw new AMQPException(e.toString());
}
}
use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.
the class Replier method serviceRequests.
public void serviceRequests() {
try {
for (int i = 0; i < nMsgs; i++) {
TxnIdIF txnIdIF = txc.createTxnId();
AMQPMessage request = consumer.receive();
request.setTxnIdIF(txnIdIF);
if (request != null) {
messageFactory.verify(request);
if (!request.isSettled())
request.accept();
Properties prop = request.getProperties();
if (prop == null)
throw new Exception("Properties not set in request: " + request);
AddressIF replyTo = prop.getReplyTo();
if (replyTo == null)
throw new Exception("replyTo not set in request: " + request);
Producer p = getSession().createProducer(replyTo.getValueString(), qos);
AMQPMessage reply = messageFactory.createReplyMessage(request);
reply.setTxnIdIF(txnIdIF);
Properties prop2 = new Properties();
prop2.setTo(replyTo);
prop2.setCorrelationId(prop.getMessageId());
reply.setProperties(prop2);
p.send(reply);
p.close();
} else
throw new Exception("Msg == null at i=" + i);
txc.commit(txnIdIF);
}
} catch (Exception e) {
fail("test failed: " + e);
}
}
Aggregations