Search in sources :

Example 6 with UTF8Buffer

use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.

the class BaseDataStreamMarshaller method tightUnmarshalString.

@SuppressWarnings("deprecation")
protected UTF8Buffer tightUnmarshalString(DataByteArrayInputStream dataIn, BooleanStream bs) throws IOException {
    if (bs.readBoolean()) {
        // ignored for now.
        boolean ascii = bs.readBoolean();
        int size = dataIn.readShort();
        if (size == 0) {
            return new UTF8Buffer("");
        } else {
            Buffer buffer = dataIn.readBuffer(size);
            return buffer.utf8();
        }
    } else {
        return null;
    }
}
Also used : UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) Buffer(org.fusesource.hawtbuf.Buffer) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer)

Example 7 with UTF8Buffer

use of org.fusesource.hawtbuf.UTF8Buffer 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 8 with UTF8Buffer

use of org.fusesource.hawtbuf.UTF8Buffer in project activemq-artemis by apache.

the class OpenWireMessageConverter method loadMapIntoProperties.

private static void loadMapIntoProperties(TypedProperties props, Map<String, Object> map) {
    for (Entry<String, Object> entry : map.entrySet()) {
        SimpleString key = new SimpleString(entry.getKey());
        Object value = entry.getValue();
        if (value instanceof UTF8Buffer) {
            value = ((UTF8Buffer) value).toString();
        }
        TypedProperties.setObjectProperty(key, value, props);
    }
}
Also used : UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 9 with UTF8Buffer

use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.

the class ProducerId method setProducerSessionKey.

/**
 * @param sessionKey
 */
private void setProducerSessionKey(String sessionKey) {
    // Parse off the value
    int p = sessionKey.lastIndexOf(":");
    if (p >= 0) {
        sessionId = Long.parseLong(sessionKey.substring(p + 1));
        sessionKey = sessionKey.substring(0, p);
    }
    // The rest is the value
    connectionId = new UTF8Buffer(sessionKey);
}
Also used : UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer)

Example 10 with UTF8Buffer

use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.

the class MqttProtocol method snoopConnectionParameters.

@Override
public void snoopConnectionParameters(final SocketWrapper socket, final Buffer received, final Handler<ConnectionParameters> handler) {
    final MqttProtocolDecoder h = new MqttProtocolDecoder(this);
    h.errorHandler(new Handler<String>() {

        @Override
        public void handle(String error) {
            LOG.info("STOMP protocol decoding error: " + error);
            socket.close();
        }
    });
    h.codecHandler(new Handler<MQTTFrame>() {

        @Override
        public void handle(MQTTFrame event) {
            try {
                if (event.messageType() == org.fusesource.mqtt.codec.CONNECT.TYPE) {
                    CONNECT connect = new CONNECT().decode(event);
                    ConnectionParameters parameters = new ConnectionParameters();
                    if (connect.clientId() != null) {
                        parameters.protocolClientId = connect.clientId().toString();
                    }
                    if (connect.userName() != null) {
                        parameters.protocolUser = connect.userName().toString();
                        // containing the virtual host info.
                        if (parameters.protocolUser.contains("/")) {
                            // Strip off the virtual host part of the username..
                            String[] parts = parameters.protocolUser.split("/", 2);
                            parameters.protocolVirtualHost = parts[0];
                            parameters.protocolUser = parts[1];
                            // Update the connect frame to strip out the virtual host from the username field...
                            connect.userName(new UTF8Buffer(parameters.protocolUser));
                            // re-write the received buffer /w  the updated connect frame
                            Buffer tail = received.getBuffer((int) h.getBytesDecoded(), received.length());
                            BufferSupport.setLength(received, 0);
                            append(received, connect.encode());
                            received.appendBuffer(tail);
                        }
                    }
                    handler.handle(parameters);
                } else {
                    LOG.info("Expected a CONNECT frame");
                    socket.close();
                }
            } catch (java.net.ProtocolException e) {
                LOG.info("Invalid MQTT frame: " + e, e);
                socket.close();
            }
        }
    });
    socket.readStream().dataHandler(h);
    h.handle(received);
}
Also used : Buffer(org.vertx.java.core.buffer.Buffer) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) ConnectionParameters(io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters) CONNECT(org.fusesource.mqtt.codec.CONNECT) MQTTFrame(org.fusesource.mqtt.codec.MQTTFrame)

Aggregations

UTF8Buffer (org.fusesource.hawtbuf.UTF8Buffer)11 Buffer (org.fusesource.hawtbuf.Buffer)4 IOException (java.io.IOException)3 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException)2 ObjectSerializationStrategy (io.fabric8.dosgi.api.ObjectSerializationStrategy)1 Serialization (io.fabric8.dosgi.api.Serialization)1 SerializationStrategy (io.fabric8.dosgi.api.SerializationStrategy)1 ConnectionParameters (io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 Exchange (org.apache.camel.Exchange)1 BufferEditor (org.fusesource.hawtbuf.BufferEditor)1 DataByteArrayOutputStream (org.fusesource.hawtbuf.DataByteArrayOutputStream)1 Callback (org.fusesource.mqtt.client.Callback)1 Listener (org.fusesource.mqtt.client.Listener)1 CONNECT (org.fusesource.mqtt.codec.CONNECT)1 MQTTFrame (org.fusesource.mqtt.codec.MQTTFrame)1 Buffer (org.vertx.java.core.buffer.Buffer)1