Search in sources :

Example 6 with Header

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Header in project swiftmq-client by iitsoftware.

the class FrameReader method createSaslFrame.

/**
 * Creates a SaslFrameIF object.
 *
 * @param in input stream
 * @return frame
 */
public static SaslFrameIF createSaslFrame(LengthCaptureDataInput in) throws Exception {
    long frameSize = 0;
    byte dataOffset = 0;
    byte typeCode = 0;
    int channel = 0;
    byte[] extendedHeader = null;
    in.startCaptureLength();
    // frame header
    frameSize = in.readInt();
    dataOffset = in.readByte();
    typeCode = in.readByte();
    if (!((typeCode == AMQPFrame.TYPE_CODE_AMQP_FRAME) || (typeCode == AMQPFrame.TYPE_CODE_SASL_FRAME)))
        throw new IOException("Invalid frame type (" + typeCode + "), not an AMQP or SASL frame!");
    channel = in.readUnsignedShort();
    // extended header
    int doff = dataOffset;
    if (doff < 2)
        throw new Exception("Malformed frame, data offset is " + doff);
    if (doff > 2) {
        extendedHeader = new byte[doff * 4 - 8];
        in.readFully(extendedHeader);
    }
    // body
    long bodySize = frameSize - doff * 4;
    if (bodySize > 0) {
        if (bodySize > Integer.MAX_VALUE)
            throw new Exception("Frame body size (" + bodySize + ") is greater than Integer.MAX_VALUE (" + Integer.MAX_VALUE + ")");
    } else
        return new HeartbeatFrame(channel);
    AMQPFrame frame = (AMQPFrame) SaslFrameFactory.create(channel, AMQPTypeDecoder.decode(in));
    int plLength = (int) (frameSize - in.stopCaptureLength());
    if (plLength > 0) {
        byte[] b = new byte[plLength];
        in.readFully(b);
        frame.setPayload(b);
    }
    return frame;
}
Also used : AMQPFrame(com.swiftmq.amqp.v100.transport.AMQPFrame) HeartbeatFrame(com.swiftmq.amqp.v100.transport.HeartbeatFrame) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with Header

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Header in project swiftmq-client by iitsoftware.

the class FrameReader method createFrame.

/**
 * Creates a FrameIF object.
 *
 * @param in input stream
 * @return frame
 */
public static FrameIF createFrame(LengthCaptureDataInput in) throws Exception {
    long frameSize = 0;
    byte dataOffset = 0;
    byte typeCode = 0;
    int channel = 0;
    byte[] extendedHeader = null;
    in.startCaptureLength();
    // frame header
    frameSize = in.readInt();
    dataOffset = in.readByte();
    typeCode = in.readByte();
    if (!((typeCode == AMQPFrame.TYPE_CODE_AMQP_FRAME) || (typeCode == AMQPFrame.TYPE_CODE_SASL_FRAME)))
        throw new IOException("Invalid frame type (" + typeCode + "), not an AMQP or SASL frame!");
    channel = in.readUnsignedShort();
    // extended header
    int doff = dataOffset;
    if (doff < 2)
        throw new Exception("Malformed frame, data offset is " + doff);
    if (doff > 2) {
        extendedHeader = new byte[doff * 4 - 8];
        in.readFully(extendedHeader);
    }
    // body
    long bodySize = frameSize - doff * 4;
    if (bodySize > 0) {
        if (bodySize > Integer.MAX_VALUE)
            throw new Exception("Frame body size (" + bodySize + ") is greater than Integer.MAX_VALUE (" + Integer.MAX_VALUE + ")");
    } else
        return new HeartbeatFrame(channel);
    AMQPFrame frame = (AMQPFrame) FrameFactory.create(channel, AMQPTypeDecoder.decode(in));
    int plLength = (int) (frameSize - in.stopCaptureLength());
    if (plLength > 0) {
        byte[] b = new byte[plLength];
        in.readFully(b);
        frame.setPayload(b);
    }
    return frame;
}
Also used : AMQPFrame(com.swiftmq.amqp.v100.transport.AMQPFrame) HeartbeatFrame(com.swiftmq.amqp.v100.transport.HeartbeatFrame) IOException(java.io.IOException) IOException(java.io.IOException)

Example 8 with Header

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Header in project swiftmq-ce by iitsoftware.

the class JMSMappingInboundTransformer method transform.

public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl jmsMessage = null;
    try {
        AMQPMessage amqpMessage = null;
        if (frame.getMorePayloads() != null) {
            List morePayloads = frame.getMorePayloads();
            byte[][] b = new byte[morePayloads.size() + 1][];
            b[0] = frame.getPayload();
            for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
            amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
        } else
            amqpMessage = new AMQPMessage(frame.getPayload());
        jmsMessage = messageFactory.create(amqpMessage);
        jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
        jmsMessage.setBooleanProperty(amqpNative, false);
        Header header = amqpMessage.getHeader();
        if (header != null)
            transformHeader(header, jmsMessage);
        DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
        if (deliveryAnnotations != null)
            transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
        MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
        if (messageAnnotations != null)
            transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
        Properties properties = amqpMessage.getProperties();
        if (properties != null)
            transformProperties(properties, jmsMessage, destinationFactory);
        ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
        if (applicationProperties != null)
            transformApplicationProperties(applicationProperties, jmsMessage);
        Footer footer = amqpMessage.getFooter();
        if (footer != null)
            transformMap(footer.getValue(), jmsMessage, prefixFT);
    } catch (Exception e) {
        throw new AMQPException(e.toString());
    }
    jmsMessage.reset();
    return jmsMessage;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl)

Aggregations

IOException (java.io.IOException)6 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)4 AMQPFrame (com.swiftmq.amqp.v100.transport.AMQPFrame)3 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)2 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)2 HeartbeatFrame (com.swiftmq.amqp.v100.transport.HeartbeatFrame)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 List (java.util.List)2 JMSException (javax.jms.JMSException)2 ProtocolHeader (com.swiftmq.amqp.ProtocolHeader)1 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1 MessageIdString (com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString)1 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)1 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)1 Semaphore (com.swiftmq.tools.concurrent.Semaphore)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1