Search in sources :

Example 1 with AMQPBoolean

use of com.swiftmq.amqp.v100.types.AMQPBoolean in project swiftmq-ce by iitsoftware.

the class JMSMappingInboundTransformer method transformHeader.

protected void transformHeader(Header header, MessageImpl jmsMessage) throws Exception {
    AMQPBoolean durable = header.getDurable();
    if (durable != null) {
        if (durable.getValue())
            jmsMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        else
            jmsMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    } else
        jmsMessage.setJMSDeliveryMode(defaultDeliveryMode);
    AMQPUnsignedByte priority = header.getPriority();
    if (priority != null)
        jmsMessage.setJMSPriority(priority.getValue());
    else
        jmsMessage.setJMSPriority(defaultPriority);
    Milliseconds ttl = header.getTtl();
    if (ttl != null) {
        long lTTL = ttl.getValue();
        if (lTTL > 0) {
            long current = System.currentTimeMillis();
            jmsMessage.setJMSExpiration(current + lTTL);
            jmsMessage.setLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD, current);
        }
    } else {
        if (defaultTtl > 0)
            jmsMessage.setJMSExpiration(System.currentTimeMillis() + defaultTtl);
    }
    AMQPBoolean firstAcquirer = header.getFirstAcquirer();
    if (firstAcquirer != null)
        jmsMessage.setBooleanProperty(prefixVendor + "FirstAcquirer", firstAcquirer.getValue());
}
Also used : Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)

Example 2 with AMQPBoolean

use of com.swiftmq.amqp.v100.types.AMQPBoolean 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());
    }
}
Also used : Destination(javax.jms.Destination) SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) HashMap(java.util.HashMap) JMSException(javax.jms.JMSException) Enumeration(java.util.Enumeration) IOException(java.io.IOException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) MessageImpl(com.swiftmq.jms.MessageImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with AMQPBoolean

use of com.swiftmq.amqp.v100.types.AMQPBoolean in project swiftmq-client by iitsoftware.

the class AMQPRepo method add.

AMQPRepo add(File file, String appname) throws Exception {
    String filename = file.getName();
    String content = loadFile(file);
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("file"), new AMQPString(filename));
    propMap.put(new AMQPString("operation"), new AMQPString("add"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    request.setAmqpValue(new AmqpValue(new AMQPString(content)));
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success)
        System.out.println(filename + " added to repository " + appname);
    else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 4 with AMQPBoolean

use of com.swiftmq.amqp.v100.types.AMQPBoolean in project swiftmq-client by iitsoftware.

the class AMQPRepo method remove.

AMQPRepo remove(File file, String appname) throws Exception {
    String filename = file.getName();
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("file"), new AMQPString(filename));
    propMap.put(new AMQPString("operation"), new AMQPString("remove"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success)
        System.out.println(filename + " removed from repository " + appname);
    else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AMQPBoolean

use of com.swiftmq.amqp.v100.types.AMQPBoolean in project swiftmq-client by iitsoftware.

the class AMQPRepo method list.

AMQPRepo list(String appname) throws Exception {
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("operation"), new AMQPString("list"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success) {
        System.out.println("Content of repository " + appname + ":");
        System.out.println();
        int n = Integer.parseInt(((AMQPString) (body.getValue().get(new AMQPString("nfiles")))).getValue());
        for (int i = 0; i < n; i++) System.out.println(((AMQPString) (body.getValue().get(new AMQPString("storetime" + i)))).getValue() + "\t" + ((AMQPString) (body.getValue().get(new AMQPString("file" + i)))).getValue());
        System.out.println();
    } else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)6 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)5 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)4 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)4 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)4 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)4 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)2 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)2 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)2 Handle (com.swiftmq.amqp.v100.generated.transport.definitions.Handle)2 Seconds (com.swiftmq.amqp.v100.generated.transport.definitions.Seconds)2 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)2 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)1