use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.
the class RouterPathTest method testRouterDeployPathLookUp.
@Test
public void testRouterDeployPathLookUp() throws Exception {
String path = "/v3/namespaces/default//apps/";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.
the class DefaultStreamManager method send.
@Override
public void send(File file, String contentType) throws Exception {
String path = String.format("/v3/namespaces/%s/streams/%s/batch", streamId.getNamespaceId(), streamId.getId());
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, path);
request.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
HttpUtil.setTransferEncodingChunked(request, true);
final MockResponder responder = new MockResponder();
final BodyConsumer bodyConsumer = streamHandler.batch(request, responder, streamId.getNamespaceId(), streamId.getId());
Preconditions.checkNotNull(bodyConsumer, "BodyConsumer from stream batch load call should not be null");
ByteStreams.readBytes(Files.newInputStreamSupplier(file), new ByteProcessor<BodyConsumer>() {
@Override
public boolean processBytes(byte[] buf, int off, int len) throws IOException {
bodyConsumer.chunk(Unpooled.wrappedBuffer(buf, off, len), responder);
return true;
}
@Override
public BodyConsumer getResult() {
bodyConsumer.finished(responder);
return bodyConsumer;
}
});
Preconditions.checkState(HttpResponseStatus.OK.equals(responder.getStatus()), "Failed to load events to stream %s in batch", streamId);
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project ballerina by ballerina-lang.
the class HttpUtil method createHttpCarbonMessage.
public static HTTPCarbonMessage createHttpCarbonMessage(boolean isRequest) {
HTTPCarbonMessage httpCarbonMessage;
if (isRequest) {
httpCarbonMessage = new HTTPCarbonMessage(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""));
} else {
httpCarbonMessage = new HTTPCarbonMessage(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
}
httpCarbonMessage.completeMessage();
return httpCarbonMessage;
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project activemq-artemis by apache.
the class NettyConnector method createConnection.
@Override
public Connection createConnection() {
if (channelClazz == null) {
return null;
}
// HORNETQ-907 - strip off IPv6 scope-id (if necessary)
SocketAddress remoteDestination = new InetSocketAddress(host, port);
InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
if (inetAddress instanceof Inet6Address) {
Inet6Address inet6Address = (Inet6Address) inetAddress;
if (inet6Address.getScopeId() != 0) {
try {
remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}
logger.debug("Remote destination: " + remoteDestination);
ChannelFuture future;
// port 0 does not work so only use local address if set
if (localPort != 0) {
SocketAddress localDestination;
if (localAddress != null) {
localDestination = new InetSocketAddress(localAddress, localPort);
} else {
localDestination = new InetSocketAddress(localPort);
}
future = bootstrap.connect(remoteDestination, localDestination);
} else {
future = bootstrap.connect(remoteDestination);
}
future.awaitUninterruptibly();
if (future.isSuccess()) {
final Channel ch = future.channel();
SslHandler sslHandler = ch.pipeline().get(SslHandler.class);
if (sslHandler != null) {
Future<Channel> handshakeFuture = sslHandler.handshakeFuture();
if (handshakeFuture.awaitUninterruptibly(30000)) {
if (handshakeFuture.isSuccess()) {
ChannelPipeline channelPipeline = ch.pipeline();
ActiveMQChannelHandler channelHandler = channelPipeline.get(ActiveMQChannelHandler.class);
channelHandler.active = true;
} else {
ch.close().awaitUninterruptibly();
ActiveMQClientLogger.LOGGER.errorCreatingNettyConnection(handshakeFuture.cause());
return null;
}
} else {
// handshakeFuture.setFailure(new SSLException("Handshake was not completed in 30 seconds"));
ch.close().awaitUninterruptibly();
return null;
}
}
if (httpUpgradeEnabled) {
// Send a HTTP GET + Upgrade request that will be handled by the http-upgrade handler.
try {
// get this first incase it removes itself
HttpUpgradeHandler httpUpgradeHandler = (HttpUpgradeHandler) ch.pipeline().get("http-upgrade");
String scheme = "http";
if (sslEnabled) {
scheme = "https";
}
String ipv6Host = IPV6Util.encloseHost(host);
URI uri = new URI(scheme, null, ipv6Host, port, null, null, null);
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
request.headers().set(HttpHeaderNames.HOST, ipv6Host);
request.headers().set(HttpHeaderNames.UPGRADE, ACTIVEMQ_REMOTING);
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderNames.UPGRADE);
final String serverName = ConfigurationHelper.getStringProperty(TransportConstants.ACTIVEMQ_SERVER_NAME, null, configuration);
if (serverName != null) {
request.headers().set(TransportConstants.ACTIVEMQ_SERVER_NAME, serverName);
}
final String endpoint = ConfigurationHelper.getStringProperty(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, null, configuration);
if (endpoint != null) {
request.headers().set(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME, endpoint);
}
// Get 16 bit nonce and base 64 encode it
byte[] nonce = randomBytes(16);
String key = base64(nonce);
request.headers().set(SEC_ACTIVEMQ_REMOTING_KEY, key);
ch.attr(REMOTING_KEY).set(key);
logger.debugf("Sending HTTP request %s", request);
// Send the HTTP request.
ch.writeAndFlush(request);
if (!httpUpgradeHandler.awaitHandshake()) {
ch.close().awaitUninterruptibly();
return null;
}
} catch (URISyntaxException e) {
ActiveMQClientLogger.LOGGER.errorCreatingNettyConnection(e);
return null;
}
} else {
ChannelPipeline channelPipeline = ch.pipeline();
ActiveMQChannelHandler channelHandler = channelPipeline.get(ActiveMQChannelHandler.class);
channelHandler.active = true;
}
// No acceptor on a client connection
Listener connectionListener = new Listener();
NettyConnection conn = new NettyConnection(configuration, ch, connectionListener, !httpEnabled && batchDelay > 0, false);
connectionListener.connectionCreated(null, conn, protocolManager);
return conn;
} else {
Throwable t = future.cause();
if (t != null && !(t instanceof ConnectException)) {
ActiveMQClientLogger.LOGGER.errorCreatingNettyConnection(future.cause());
}
return null;
}
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.
the class AppFabricClient method getProgramSchedules.
public List<ScheduleDetail> getProgramSchedules(String namespace, String app, String workflow) throws NotFoundException {
MockResponder responder = new MockResponder();
String uri = String.format("%s/apps/%s/workflows/%s/schedules", getNamespacePath(namespace), app, workflow);
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
try {
workflowHttpHandler.getWorkflowSchedules(request, responder, namespace, app, workflow, null, null, null);
} catch (Exception e) {
// cannot happen
throw Throwables.propagate(e);
}
List<ScheduleDetail> schedules = responder.decodeResponseContent(SCHEDULE_DETAILS_TYPE, GSON);
verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Getting workflow schedules failed");
return schedules;
}
Aggregations