Search in sources :

Example 6 with TextMessageImpl

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;
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JMSException(javax.jms.JMSException) ContentHeaderProperties(com.swiftmq.amqp.v091.types.ContentHeaderProperties) MessageImpl(com.swiftmq.jms.MessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl)

Example 7 with TextMessageImpl

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;
    }
}
Also used : TextMessageImpl(com.swiftmq.jms.TextMessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 8 with TextMessageImpl

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);
}
Also used : Destination(javax.jms.Destination) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Field(com.swiftmq.amqp.v091.types.Field) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) ContentHeaderProperties(com.swiftmq.amqp.v091.types.ContentHeaderProperties) Delivery(com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)

Example 9 with TextMessageImpl

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();
}
Also used : TextMessageImpl(com.swiftmq.jms.TextMessageImpl)

Example 10 with TextMessageImpl

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;
}
Also used : TextMessageImpl(com.swiftmq.jms.TextMessageImpl) TextMessage(javax.jms.TextMessage)

Aggregations

TextMessageImpl (com.swiftmq.jms.TextMessageImpl)18 TextMessage (javax.jms.TextMessage)12 ContentHeaderProperties (com.swiftmq.amqp.v091.types.ContentHeaderProperties)2 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueueImpl (com.swiftmq.jms.QueueImpl)2 HashMap (java.util.HashMap)2 JMSException (javax.jms.JMSException)2 Field (com.swiftmq.amqp.v091.types.Field)1 Delivery (com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)1 XStream (com.thoughtworks.xstream.XStream)1 Dom4JDriver (com.thoughtworks.xstream.io.xml.Dom4JDriver)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Enumeration (java.util.Enumeration)1 Destination (javax.jms.Destination)1