protected BufferChain wrapWithSasl(BufferChain bc) throws IOException { if (!this.connection.useSasl) return bc; // Looks like no way around this; saslserver wants a byte array. I have to make it one. // THIS IS A BIG UGLY COPY. byte [] responseBytes = bc.getBytes(); byte [] token; // synchronization may be needed since there can be multiple Handler // threads using saslServer or Crypto AES to wrap responses. if (connection.useCryptoAesWrap) { // wrap with Crypto AES synchronized (connection.cryptoAES) { token = connection.cryptoAES.wrap(responseBytes, 0, responseBytes.length); } } else { synchronized (connection.saslServer) { token = connection.saslServer.wrap(responseBytes, 0, responseBytes.length); } } if (RpcServer.LOG.isTraceEnabled()) { RpcServer.LOG.trace("Adding saslServer wrapped token of size " + token.length + " as call response."); } ByteBuffer[] responseBufs = new ByteBuffer[2]; responseBufs[0] = ByteBuffer.wrap(Bytes.toBytes(token.length)); responseBufs[1] = ByteBuffer.wrap(token); return new BufferChain(responseBufs); }
@Test public void testGetBackBytesWePutIn() { ByteBuffer[] bufs = wrapArrays(HELLO_WORLD_CHUNKS); BufferChain chain = new BufferChain(bufs); assertTrue(Bytes.equals(Bytes.toBytes("hello world"), chain.getBytes())); }
private BufferChain wrapWithSasl(BufferChain bc) throws IOException { if (!this.connection.useSasl) return bc; // Looks like no way around this; saslserver wants a byte array. I have to make it one. // THIS IS A BIG UGLY COPY. byte [] responseBytes = bc.getBytes(); byte [] token; // synchronization may be needed since there can be multiple Handler // threads using saslServer to wrap responses. synchronized (connection.saslServer) { token = connection.saslServer.wrap(responseBytes, 0, responseBytes.length); } if (LOG.isTraceEnabled()) { LOG.trace("Adding saslServer wrapped token of size " + token.length + " as call response."); } ByteBuffer bbTokenLength = ByteBuffer.wrap(Bytes.toBytes(token.length)); ByteBuffer bbTokenBytes = ByteBuffer.wrap(token); return new BufferChain(bbTokenLength, bbTokenBytes); }
@Test public void testGetBackBytesWePutIn() { ByteBuffer[] bufs = wrapArrays(HELLO_WORLD_CHUNKS); BufferChain chain = new BufferChain(bufs); assertTrue(Bytes.equals(Bytes.toBytes("hello world"), chain.getBytes())); }