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();
// If the user name has a '/' in it, then interpret it as
// 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 {