Search in sources :

Example 46 with FullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project activemq-artemis by apache.

the class HttpAcceptorHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
    FullHttpRequest request = (FullHttpRequest) msg;
    HttpMethod method = request.method();
    // if we are a post then we send upstream, otherwise we are just being prompted for a response.
    if (method.equals(HttpMethod.POST)) {
        ctx.fireChannelRead(ReferenceCountUtil.retain(((FullHttpRequest) msg).content()));
        // add a new response
        responses.put(new ResponseHolder(System.currentTimeMillis() + responseTime, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)));
        ReferenceCountUtil.release(msg);
        return;
    }
    super.channelRead(ctx, msg);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Example 47 with FullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project cdap by caskdata.

the class AppFabricClient method addSchedule.

public void addSchedule(ApplicationId application, ScheduleDetail scheduleDetail) throws Exception {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/versions/%s/schedules/%s", getNamespacePath(application.getNamespace()), application.getApplication(), application.getVersion(), scheduleDetail.getName());
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri);
    request.content().writeCharSequence(GSON.toJson(scheduleDetail), StandardCharsets.UTF_8);
    HttpUtil.setContentLength(request, request.content().readableBytes());
    programLifecycleHttpHandler.addSchedule(request, responder, application.getNamespace(), application.getApplication(), application.getVersion(), scheduleDetail.getName());
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Add schedule failed");
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 48 with FullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project cdap by caskdata.

the class AppFabricClient method suspend.

public void suspend(String namespaceId, String appId, String scheduleName) throws Exception {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/schedules/%s/suspend", getNamespacePath(namespaceId), appId, scheduleName);
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri);
    HttpUtil.setContentLength(request, request.content().readableBytes());
    programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, "schedules", scheduleName, "suspend");
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Suspend workflow schedules failed");
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 49 with FullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project cdap by caskdata.

the class AppFabricClient method setServiceInstances.

public void setServiceInstances(String namespaceId, String applicationId, String serviceName, int instances) throws Exception {
    MockResponder responder = new MockResponder();
    String uri = String.format("%s/apps/%s/services/%s/instances", getNamespacePath(namespaceId), applicationId, serviceName);
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri);
    JsonObject json = new JsonObject();
    json.addProperty("instances", instances);
    request.content().writeCharSequence(json.toString(), StandardCharsets.UTF_8);
    HttpUtil.setContentLength(request, request.content().readableBytes());
    programLifecycleHttpHandler.setServiceInstances(request, responder, namespaceId, applicationId, serviceName);
    verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Set service instances failed");
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) JsonObject(com.google.gson.JsonObject)

Example 50 with FullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project component-runtime by Talend.

the class PassthroughHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest request) {
    if (HttpMethod.CONNECT.name().equalsIgnoreCase(request.method().name())) {
        final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER);
        setKeepAlive(response, true);
        setContentLength(response, 0);
        if (api.getSslContext() != null) {
            final SSLEngine sslEngine = api.getSslContext().createSSLEngine();
            sslEngine.setUseClientMode(false);
            ctx.channel().pipeline().addFirst("ssl", new SslHandler(sslEngine, true));
            final String uri = request.uri();
            final String[] parts = uri.split(":");
            ctx.channel().attr(BASE).set("https://" + parts[0] + (parts.length > 1 && !"443".equals(parts[1]) ? ":" + parts[1] : ""));
        }
        ctx.writeAndFlush(response);
        return;
    }
    // copy to use in a separated thread
    final FullHttpRequest req = request.copy();
    api.getExecutor().execute(() -> doHttpRequest(req, ctx));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) SSLEngine(javax.net.ssl.SSLEngine) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)287 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)180 Test (org.junit.jupiter.api.Test)74 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)69 Test (org.junit.Test)64 ByteBuf (io.netty.buffer.ByteBuf)54 HttpResponse (io.netty.handler.codec.http.HttpResponse)49 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)43 URI (java.net.URI)35 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)31 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)30 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)30 AsciiString (io.netty.util.AsciiString)25 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)23 Map (java.util.Map)22 ChannelPromise (io.netty.channel.ChannelPromise)21 HttpMethod (io.netty.handler.codec.http.HttpMethod)20 IOException (java.io.IOException)19 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)18 ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)16