Search in sources :

Example 1 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQBytesMessage method initializeWriting.

private void initializeWriting() throws OpenwireException {
    checkReadOnlyBody();
    if (this.dataOut == null) {
        this.bytesOut = new ByteArrayOutputStream();
        OutputStream os = bytesOut;
        if (Settings.enable_compression()) {
            // we are compressed.
            try {
                os.write(new byte[4]);
            } catch (IOException e) {
                throw new OpenwireException(e);
            }
            length = 0;
            compressed = true;
            final Deflater deflater = new Deflater(Deflater.BEST_SPEED);
            os = new FilterOutputStream(new DeflaterOutputStream(os, deflater)) {

                public void write(byte[] arg0) throws IOException {
                    length += arg0.length;
                    out.write(arg0);
                }

                public void write(byte[] arg0, int arg1, int arg2) throws IOException {
                    length += arg2;
                    out.write(arg0, arg1, arg2);
                }

                public void write(int arg0) throws IOException {
                    length++;
                    out.write(arg0);
                }

                @Override
                public void close() throws IOException {
                    super.close();
                    deflater.end();
                }
            };
        }
        this.dataOut = new DataOutputStream(os);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException) Deflater(java.util.zip.Deflater) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(org.fusesource.hawtbuf.ByteArrayOutputStream)

Example 2 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQMapMessage method loadContent.

/**
 * Builds the message body from data
 *
 * @throws OpenwireException
 */
private void loadContent() throws OpenwireException {
    try {
        if (getContent() != null && map.isEmpty()) {
            Buffer content = getContent();
            InputStream is = new ByteArrayInputStream(content);
            if (isCompressed()) {
                is = new InflaterInputStream(is);
            }
            DataInputStream dataIn = new DataInputStream(is);
            map = MarshallingSupport.unmarshalPrimitiveMap(dataIn);
            dataIn.close();
        }
    } catch (IOException e) {
        throw new OpenwireException(e);
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InflaterInputStream(java.util.zip.InflaterInputStream)

Example 3 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException in project fabric8 by jboss-fuse.

the class BaseDataStreamMarshaller method looseMarshalThrowable.

protected void looseMarshalThrowable(OpenWireFormat wireFormat, Throwable o, DataByteArrayOutputStream dataOut) throws IOException {
    dataOut.writeBoolean(o != null);
    if (o != null) {
        String className = o instanceof OpenwireException ? ((OpenwireException) o).getClassName() : o.getClass().getName();
        looseMarshalString(new UTF8Buffer(className), dataOut);
        looseMarshalString(new UTF8Buffer(o.getMessage()), dataOut);
        if (wireFormat.isStackTraceEnabled()) {
            StackTraceElement[] stackTrace = o.getStackTrace();
            dataOut.writeShort(stackTrace.length);
            for (int i = 0; i < stackTrace.length; i++) {
                StackTraceElement element = stackTrace[i];
                looseMarshalString(new UTF8Buffer(element.getClassName()), dataOut);
                looseMarshalString(new UTF8Buffer(element.getMethodName()), dataOut);
                looseMarshalString(new UTF8Buffer(element.getFileName()), dataOut);
                dataOut.writeInt(element.getLineNumber());
            }
            looseMarshalThrowable(wireFormat, o.getCause(), dataOut);
        }
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer)

Example 4 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException in project fabric8 by jboss-fuse.

the class BaseDataStreamMarshaller method tightMarshalThrowable2.

protected void tightMarshalThrowable2(OpenWireFormat wireFormat, Throwable o, DataByteArrayOutputStream dataOut, BooleanStream bs) throws IOException {
    if (bs.readBoolean()) {
        String className = o instanceof OpenwireException ? ((OpenwireException) o).getClassName() : o.getClass().getName();
        tightMarshalString2(new UTF8Buffer(className), dataOut, bs);
        tightMarshalString2(new UTF8Buffer(o.getMessage()), dataOut, bs);
        if (wireFormat.isStackTraceEnabled()) {
            StackTraceElement[] stackTrace = o.getStackTrace();
            dataOut.writeShort(stackTrace.length);
            for (int i = 0; i < stackTrace.length; i++) {
                StackTraceElement element = stackTrace[i];
                tightMarshalString2(new UTF8Buffer(element.getClassName()), dataOut, bs);
                tightMarshalString2(new UTF8Buffer(element.getMethodName()), dataOut, bs);
                tightMarshalString2(new UTF8Buffer(element.getFileName()), dataOut, bs);
                dataOut.writeInt(element.getLineNumber());
            }
            tightMarshalThrowable2(wireFormat, o.getCause(), dataOut, bs);
        }
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer)

Example 5 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readByte.

public byte readByte() throws OpenwireException {
    initializeReading();
    try {
        this.dataIn.mark(10);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new OpenwireException("reached end of data");
        }
        if (type == MarshallingSupport.BYTE_TYPE) {
            return this.dataIn.readByte();
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return Byte.valueOf(this.dataIn.readUTF()).byteValue();
        }
        if (type == MarshallingSupport.NULL) {
            this.dataIn.reset();
            throw new NullPointerException("Cannot convert NULL value to byte.");
        } else {
            this.dataIn.reset();
            throw new OpenwireException(" not a byte type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            throw new OpenwireException(ioe);
        }
        throw mfe;
    } catch (EOFException e) {
        throw new OpenwireException(e);
    } catch (IOException e) {
        throw new OpenwireException(e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Aggregations

OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)18 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException)3 InflaterInputStream (java.util.zip.InflaterInputStream)3 Buffer (org.fusesource.hawtbuf.Buffer)3 ByteArrayInputStream (org.fusesource.hawtbuf.ByteArrayInputStream)3 IOException (java.io.IOException)2 UTF8Buffer (org.fusesource.hawtbuf.UTF8Buffer)2 Constructor (java.lang.reflect.Constructor)1 URL (java.net.URL)1 Deflater (java.util.zip.Deflater)1 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)1 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)1