com.github.dockerjava.netty.handler.HttpConnectionHijackHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.docker-java
Show all versions of org.apache.servicemix.bundles.docker-java
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
package com.github.dockerjava.netty.handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpClientUpgradeHandler;
import io.netty.handler.codec.http.HttpRequest;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
public class HttpConnectionHijackHandler implements HttpClientUpgradeHandler.UpgradeCodec {
private CountDownLatch latch = new CountDownLatch(1);
private HttpResponseHandler httpResponseHandler;
public HttpConnectionHijackHandler(HttpResponseHandler httpResponseHandler) {
this.httpResponseHandler = httpResponseHandler;
}
@Override
public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeResponse) throws Exception {
httpResponseHandler.channelRead(ctx, upgradeResponse);
ctx.pipeline().addLast(httpResponseHandler);
latch.countDown();
}
@Override
public Collection setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest) {
return Collections.emptyList();
}
@Override
public CharSequence protocol() {
return "tcp";
}
public void awaitUpgrade() {
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}