Search in sources :

Example 51 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class NonBlockingConnectionUndecidedDelegate method processData.

@Override
public boolean processData() throws IOException {
    try (QpidByteBuffer buffer = _netInputBuffer.duplicate()) {
        buffer.flip();
        final boolean hasSufficientData = buffer.remaining() >= NUMBER_OF_BYTES_FOR_TLS_CHECK;
        if (hasSufficientData) {
            final byte[] headerBytes = new byte[NUMBER_OF_BYTES_FOR_TLS_CHECK];
            buffer.get(headerBytes);
            if (looksLikeSSL(headerBytes)) {
                _parent.setTransportEncryption(TransportEncryption.TLS);
            } else {
                _parent.setTransportEncryption(TransportEncryption.NONE);
            }
        }
        return hasSufficientData;
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 52 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class InternalMessage method createMessage.

public static InternalMessage createMessage(final MessageStore store, final AMQMessageHeader header, final Serializable bodyObject, final boolean persistent, final String destinationName) {
    InternalMessageHeader internalHeader;
    if (header instanceof InternalMessageHeader) {
        internalHeader = (InternalMessageHeader) header;
    } else {
        internalHeader = new InternalMessageHeader(header);
    }
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    try (ObjectOutputStream os = new ObjectOutputStream(bytesOut)) {
        os.writeObject(bodyObject);
        os.close();
        byte[] bytes = bytesOut.toByteArray();
        final InternalMessageMetaData metaData = InternalMessageMetaData.create(persistent, internalHeader, bytes.length);
        MessageHandle<InternalMessageMetaData> handle = store.addMessage(metaData);
        final StoredMessage<InternalMessageMetaData> storedMessage;
        try (QpidByteBuffer wrap = QpidByteBuffer.wrap(bytes)) {
            handle.addContent(wrap);
        }
        storedMessage = handle.allContentAdded();
        return new InternalMessage(storedMessage, internalHeader, bodyObject, destinationName);
    } catch (IOException e) {
        throw new ConnectionScopedRuntimeException("Unexpected IO Exception on operation in memory", e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 53 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class FieldTable method getDataAsBytes.

public synchronized byte[] getDataAsBytes() {
    if (_encodedForm == null) {
        byte[] data = new byte[(int) getEncodedSize()];
        QpidByteBuffer buf = QpidByteBuffer.wrap(data);
        putDataInBuffer(buf);
        return data;
    } else {
        byte[] encodedCopy = new byte[_encodedForm.remaining()];
        _encodedForm.copyTo(encodedCopy);
        return encodedCopy;
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 54 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class ByteBufferBinding method objectToEntry.

@Override
public void objectToEntry(QpidByteBuffer data, final TupleOutput output) {
    try (QpidByteBuffer dup = data.duplicate()) {
        byte[] copyBuf = COPY_BUFFER.get();
        while (dup.hasRemaining()) {
            int length = Math.min(COPY_BUFFER_SIZE, dup.remaining());
            dup.get(copyBuf, 0, length);
            output.write(copyBuf, 0, length);
        }
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 55 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class MessageMetaDataBinding method entryToObject.

@Override
public StorableMessageMetaData entryToObject(DatabaseEntry entry) {
    try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(entry.getData(), entry.getOffset(), entry.getSize()))) {
        final int bodySize = stream.readInt() ^ 0x80000000;
        final int metaDataType = stream.readByte() & 0xff;
        MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(metaDataType);
        try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream)) {
            return type.createMetaData(buf);
        }
    } catch (IOException | RuntimeException e) {
        throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) MessageMetaDataType(org.apache.qpid.server.plugin.MessageMetaDataType) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)185 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)61 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)61 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)30 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)29 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 ArrayList (java.util.ArrayList)22 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)20 Test (org.junit.Test)13 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)12 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ByteBuffer (java.nio.ByteBuffer)8 LinkedHashMap (java.util.LinkedHashMap)8 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)8