Search in sources :

Example 46 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class SaslAuthenticationHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
    if (msg instanceof ByteBuf) {
        ByteBuf response = (ByteBuf) msg;
        roundtripsToGo--;
        if (successful(response) || status(response) == STATUS_AUTH_CONTINUE) {
            byte opcode = opcode(response);
            try {
                if (MemcacheProtocol.Opcode.SASL_AUTH.opcode() == opcode) {
                    handleAuthResponse(ctx, (ByteBuf) msg);
                } else if (MemcacheProtocol.Opcode.SASL_STEP.opcode() == opcode) {
                    completeAuth(ctx, (ByteBuf) msg);
                }
            } catch (Exception ex) {
                failConnect(ctx, "Unexpected error during SASL auth", response, ex, status(response));
            }
        } else if (STATUS_AUTH_ERROR == status(response)) {
            maybeFailConnect(ctx, "Authentication Failure - Potential causes: invalid credentials or if " + "LDAP is enabled ensure PLAIN SASL mechanism is exclusively used on the PasswordAuthenticator (insecure) or " + "TLS is used (recommended)", response, null, status(response));
        } else {
            failConnect(ctx, "Unexpected Status 0x" + Integer.toHexString(status(response)) + " during SASL auth", response, null, status(response));
        }
    } else {
        failConnect(ctx, "Unexpected response type on channel read, this is a bug - please report. " + msg, null, null, (short) 0);
    }
    ReferenceCountUtil.release(msg);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) TimeoutException(java.util.concurrent.TimeoutException) SaslException(javax.security.sasl.SaslException)

Example 47 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesNotCompressIfDisabledPrepend.

@Test
void doesNotCompressIfDisabledPrepend() {
    PrependRequest request = new PrependRequest(timeout, coreContext, cid, retryStrategy, key, longContent, cas, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(false));
    assertEquals(0, datatype(encoded));
    assertEquals(Unpooled.wrappedBuffer(longContent), body(encoded).get());
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 48 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesNotCompressIfTooShortInsert.

@Test
void doesNotCompressIfTooShortInsert() {
    InsertRequest request = new InsertRequest(key, shortContent, expiry, flags, timeout, coreContext, cid, retryStrategy, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(true));
    assertEquals(0, datatype(encoded));
    assertEquals(Unpooled.wrappedBuffer(shortContent), body(encoded).get());
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 49 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class DecompressionTest method decompressesGetAndTouch.

@Test
void decompressesGetAndTouch() {
    ByteBuf response = decodeHexDump(readResource("compressed_get_and_touch_response.txt", DecompressionTest.class));
    long encodedExpiry = 1;
    GetAndTouchRequest request = new GetAndTouchRequest("mydoc", Duration.ofSeconds(1), mock(CoreContext.class), CollectionIdentifier.fromDefault("bucket"), BestEffortRetryStrategy.INSTANCE, encodedExpiry, null);
    GetAndTouchResponse decoded = request.decode(response, null);
    assertEquals(readResource("dummy.json", DecompressionTest.class), new String(decoded.content(), UTF_8));
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 50 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class DecompressionTest method decompressesReplicaGet.

@Test
void decompressesReplicaGet() {
    ByteBuf response = decodeHexDump(readResource("compressed_replica_get_response.txt", DecompressionTest.class));
    ReplicaGetRequest request = new ReplicaGetRequest("mydoc", Duration.ofSeconds(1), mock(CoreContext.class), CollectionIdentifier.fromDefault("bucket"), BestEffortRetryStrategy.INSTANCE, (short) 1, null);
    GetResponse decoded = request.decode(response, null);
    assertEquals(readResource("dummy.json", DecompressionTest.class), new String(decoded.content(), UTF_8));
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)107 Test (org.junit.jupiter.api.Test)54 InetSocketAddress (java.net.InetSocketAddress)17 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)12 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)11 Duration (java.time.Duration)10 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)9 CoreContext (com.couchbase.client.core.CoreContext)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 CompressionConfig (com.couchbase.client.core.env.CompressionConfig)6 ResponseStatus (com.couchbase.client.core.msg.ResponseStatus)6 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)6 ChannelHandlerContext (com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext)5 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 ArrayList (java.util.ArrayList)5 DurabilityTimeoutCoercedEvent (com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent)4 FeaturesNegotiatedEvent (com.couchbase.client.core.cnc.events.io.FeaturesNegotiatedEvent)4 CompositeByteBuf (com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf)4 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)4 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)4