use of com.swiftmq.jms.TextMessageImpl in project swiftmq-ce by iitsoftware.
the class BasicInboundTransformer method transform.
public MessageImpl transform(MessageWrap messageWrap, DestinationFactory destinationFactory) throws JMSException {
MessageImpl msg = null;
ContentHeaderProperties prop = messageWrap.getContentHeaderProperties();
byte[] payload = getPayload(prop.getBodySize().intValue(), messageWrap.getBodyParts());
if (prop.getContentType() != null && prop.getContentType().startsWith("text/")) {
TextMessageImpl textMessage = new TextMessageImpl();
try {
textMessage.setText(new String(payload, "utf-8"));
} catch (UnsupportedEncodingException e) {
throw new JMSException(e.toString());
}
msg = textMessage;
} else
msg = new BytesMessageImpl(payload, payload.length);
msg.setLongProperty(messageFormat, Util.MESSAGE_FORMAT);
transformHeader(msg, prop, destinationFactory);
return msg;
}
use of com.swiftmq.jms.TextMessageImpl in project swiftmq-ce by iitsoftware.
the class MessageInterfaceListener method run.
public void run() {
try {
pullTransaction.commit();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception committing tx: " + e + ", exiting");
return;
}
try {
MessageImpl request = entry.getMessage();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, new message: " + request);
String result = null;
boolean showCommands = !request.propertyExists(PROP_SHOW_CMD_RESULT) || request.getBooleanProperty(PROP_SHOW_CMD_RESULT);
if (request instanceof TextMessageImpl)
result = executeCommands(((TextMessageImpl) request).getText(), showCommands);
else
result = "Invalid message type (" + request.getClass().getName() + "). Expect TextMessage!";
QueueImpl queue = getReplyQueue(request);
if (queue != null)
sendReply(queue, request, result);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
ctx.logSwiftlet.logError(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
}
if (closed)
return;
try {
pullTransaction = receiver.createTransaction(false);
pullTransaction.registerMessageProcessor(this);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception creating new tx: " + e + ", exiting");
return;
}
}
use of com.swiftmq.jms.TextMessageImpl in project swiftmq-ce by iitsoftware.
the class BasicOutboundTransformer method transform.
public Delivery transform(MessageImpl jmsMessage) throws Exception {
jmsMessage.reset();
ContentHeaderProperties prop = new ContentHeaderProperties();
byte[] body = null;
if (jmsMessage instanceof TextMessageImpl) {
String text = ((TextMessageImpl) jmsMessage).getText();
if (text != null)
body = text.getBytes("utf-8");
} else if (jmsMessage instanceof BytesMessageImpl) {
BytesMessageImpl bytesMessage = (BytesMessageImpl) jmsMessage;
if (bytesMessage.getBodyLength() > 0) {
body = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(body);
}
} else
throw new Exception("Unable to tranform (only Text/BytesMessages supported): " + jmsMessage);
// Fill props
prop.setWeight(0);
prop.setBodySize(Long.valueOf(body.length));
prop.setContentType(jmsMessage.getStringProperty(prefixVendor + "ContentType"));
prop.setContentEncoding(jmsMessage.getStringProperty(prefixVendor + "ContentEncoding"));
prop.setDeliveryMode(jmsMessage.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT ? 1 : 2);
prop.setPriority(jmsMessage.getJMSPriority());
prop.setCorrelationId(jmsMessage.getJMSCorrelationID());
Destination replyTo = jmsMessage.getJMSReplyTo();
if (replyTo != null)
prop.setReplyTo(replyTo.toString());
prop.setExpiration(String.valueOf(jmsMessage.getJMSExpiration()));
prop.setMessageId(jmsMessage.getJMSMessageID());
prop.setTimestamp(jmsMessage.getJMSTimestamp());
prop.setType(jmsMessage.getStringProperty(prefixVendor + "Type"));
prop.setUserId(jmsMessage.getStringProperty(prefixVendor + "UserId"));
prop.setAppId(jmsMessage.getStringProperty(prefixVendor + "AppId"));
prop.setClusterId(jmsMessage.getStringProperty(prefixVendor + "ClusterId"));
Map<String, Object> headers = new HashMap<String, Object>();
for (Enumeration _enum = jmsMessage.getPropertyNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
if (!name.startsWith(prefixVendor)) {
Object value = jmsMessage.getObjectProperty(name);
char type = toFieldType(value);
if (value instanceof String)
value = ((String) value).getBytes("utf-8");
headers.put(nameTranslator.translate(name), new Field(type, value));
}
}
if (headers.size() > 0)
prop.setHeaders(headers);
return new Delivery(prop, body);
}
use of com.swiftmq.jms.TextMessageImpl in project swiftmq-ce by iitsoftware.
the class MessageInterfaceListener method sendReply.
private void sendReply(QueueImpl queue, MessageImpl request, String result) throws Exception {
QueueSender sender = ctx.queueManager.createQueueSender(queue.getQueueName(), null);
QueuePushTransaction tx = sender.createTransaction();
TextMessageImpl replyMsg = (TextMessageImpl) MessageCloner.cloneMessage(request);
if (request.propertyExists(PROP_SUBJECT))
replyMsg.setStringProperty(PROP_SUBJECT, "Result for '" + request.getStringProperty(PROP_SUBJECT) + "'");
replyMsg.setJMSDestination(queue);
replyMsg.setJMSTimestamp(System.currentTimeMillis());
replyMsg.setJMSMessageID(nextId());
replyMsg.setJMSPriority(request.getJMSPriority());
replyMsg.setJMSDeliveryMode(request.getJMSDeliveryMode());
replyMsg.setText(result);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/sendReply: " + replyMsg);
tx.putMessage(replyMsg);
tx.commit();
sender.close();
}
use of com.swiftmq.jms.TextMessageImpl in project swiftmq-client by iitsoftware.
the class FileQueryRequest method toMessage.
public Message toMessage() throws JMSException {
TextMessage message = new TextMessageImpl();
message.setIntProperty(ProtocolFactory.DUMPID_PROP, ProtocolFactory.FILEQUERY_REQ);
fillMessage(message);
message.setText(selector);
return message;
}
Aggregations