Search in sources :

Example 6 with DefaultFullHttpRequest

use of com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest in project couchbase-jvm-clients by couchbase.

the class CoreHttpRequest method encode.

@Override
public FullHttpRequest encode() {
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, pathAndQueryString(), content);
    request.headers().add(headers);
    context().authenticator().authHttpRequest(serviceType(), request);
    return request;
}
Also used : FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 7 with DefaultFullHttpRequest

use of com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest in project couchbase-jvm-clients by couchbase.

the class QueryRequest method encode.

@Override
public FullHttpRequest encode() {
    ByteBuf content = Unpooled.wrappedBuffer(query);
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, URI, content);
    request.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
    request.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes());
    request.headers().set(HttpHeaderNames.USER_AGENT, context().environment().userAgent().formattedLong());
    authenticator.authHttpRequest(serviceType(), request);
    return request;
}
Also used : FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 8 with DefaultFullHttpRequest

use of com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest in project couchbase-jvm-clients by couchbase.

the class BucketConfigRequest method encode.

@Override
public FullHttpRequest encode() {
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format(PATH, bucketName));
    authenticator.authHttpRequest(serviceType(), request);
    return request;
}
Also used : FullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 9 with DefaultFullHttpRequest

use of com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest in project couchbase-jvm-clients by couchbase.

the class SearchMock method loadSearchTestCase.

/**
 * Given JSON in the form expected, e.g. those from https://github.com/chvck/sdk-testcases which contains the
 * returned JSON from the search service in a field "data", returns the completed SearchResult that the API
 * would return.
 */
public static SearchResult loadSearchTestCase(InputStream json) throws ExecutionException, InterruptedException, IOException {
    // The idea is to fake packets that have come from the search service.
    // Start by preparing the packets.
    JsonObject jo = JsonObject.fromJson(toByteArray(json));
    JsonObject data = jo.getObject("data");
    byte[] b = data.toString().getBytes(StandardCharsets.UTF_8);
    ByteBuf bytes = Unpooled.wrappedBuffer(b);
    HttpContent content = new DefaultLastHttpContent(bytes);
    HttpResponse resp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    // Fake some core stuff
    Core mockedCore = mock(Core.class);
    CoreEnvironment env = CoreEnvironment.create();
    CoreContext ctx = new CoreContext(mockedCore, 0, env, PasswordAuthenticator.create("Administrator", "password"));
    // Our ChunkedSearchMessageHandler needs to be initialised by pretending we've sent an outbound SearchRequest
    // through it
    SearchRequest req = new SearchRequest(Duration.ofSeconds(10), ctx, BestEffortRetryStrategy.INSTANCE, null, null, null, null);
    // ChunkedSearchMessageHandler will try to encode() the SearchRequest.  Rather than mocking everything required
    // to get that working, just mock the encode method.
    SearchRequest spiedReq = spy(req);
    doReturn(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "localhost")).when(spiedReq).encode();
    doAnswer(v -> {
        EndpointContext endpointContext = new EndpointContext(ctx, new HostAndPort(null, 0), null, null, null, Optional.of("bucket"), null);
        BaseEndpoint endpoint = mock(BaseEndpoint.class);
        when(endpoint.context()).thenReturn(endpointContext);
        when(endpoint.pipelined()).thenReturn(false);
        // ChunkedSearchMessageHandler does most of the work in handling responses from the service
        ChunkedSearchMessageHandler handler = new ChunkedSearchMessageHandler(endpoint, endpointContext);
        // Netty's EmbeddedChannel lets us test ChannelHandlers like ChunkedSearchMessageHandler.  It's a Netty Channel
        // that doesn't touch the network at all.
        final EmbeddedChannel channel = new EmbeddedChannel(handler);
        // Writing the request is necessary to estabish some initial state inChunkedSearchMessageHandler
        channel.writeAndFlush(spiedReq);
        // Finally we can do the interesting bit of passing our fake FTS service response into
        // ChunkedSearchMessageHandler
        channel.writeInbound(resp);
        channel.writeInbound(content);
        return null;
    }).when(mockedCore).send(any());
    CompletableFuture<SearchResult> future = SearchAccessor.searchQueryAsync(mockedCore, req, DefaultJsonSerializer.create());
    SearchResult result = future.get();
    return result;
}
Also used : SearchRequest(com.couchbase.client.core.msg.search.SearchRequest) CoreContext(com.couchbase.client.core.CoreContext) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) JsonObject(com.couchbase.client.java.json.JsonObject) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) SearchResult(com.couchbase.client.java.search.result.SearchResult) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) HostAndPort(com.couchbase.client.core.util.HostAndPort) DefaultLastHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) DefaultLastHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent) HttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent) Core(com.couchbase.client.core.Core)

Aggregations

DefaultFullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)9 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)7 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)4 Core (com.couchbase.client.core.Core)2 HttpMethod (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod)2 GenericManagerRequest (com.couchbase.client.core.msg.manager.GenericManagerRequest)2 Duration (java.time.Duration)2 Map (java.util.Map)2 CoreContext (com.couchbase.client.core.CoreContext)1 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 WaitUntilReadyCompletedEvent (com.couchbase.client.core.cnc.events.core.WaitUntilReadyCompletedEvent)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 ArrayNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)1 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)1 HttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent)1 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)1