List of usage examples for io.netty.util AsciiString AsciiString
public AsciiString(CharSequence value)
From source file:org.cloudfoundry.reactor.util.MultipartHttpOutbound.java
License:Apache License
private static ByteBuf getHeaders(ByteBufAllocator allocator, HttpHeaders headers) { AsciiString s = AsciiString.EMPTY_STRING; for (Map.Entry<String, String> entry : headers) { s = s.concat(new AsciiString(entry.getKey())).concat(HEADER_DELIMITER).concat(entry.getValue()) .concat(CRLF);//from ww w . j av a 2s . com } return allocator.directBuffer(s.length()).writeBytes(s.toByteArray()); }
From source file:org.cloudfoundry.uaa.ClientsTest.java
License:Apache License
@Test public void updateMetadata() { String appIcon = Base64.getEncoder().encodeToString(new AsciiString("test-image").toByteArray()); this.uaaClient.clients() .updateMetadata(// www. j a v a2 s .co m UpdateMetadataRequest.builder().appIcon(appIcon).appLaunchUrl("http://test.app.launch.url") .clientId(this.clientId).showOnHomePage(true).clientName("test-name").build()) .then(requestGetMetadata(this.uaaClient, this.clientId)).as(StepVerifier::create) .consumeNextWith(metadata -> { assertThat(metadata.getAppIcon()).isEqualTo(appIcon); assertThat(metadata.getAppLaunchUrl()).isEqualTo("http://test.app.launch.url"); assertThat(metadata.getClientId()).isEqualTo(this.clientId); assertThat(metadata.getClientName()).isEqualTo("test-name"); assertThat(metadata.getShowOnHomePage()).isTrue(); }).expectComplete().verify(Duration.ofMinutes(5)); }
From source file:org.jboss.aerogear.webpush.netty.WebPushFrameListener.java
License:Apache License
public WebPushFrameListener(final WebPushServer webpushServer) { this.webpushServer = Objects.requireNonNull(webpushServer, "webpushServer must not be null"); this.authority = new AsciiString(webpushServer.config().host() + ":" + webpushServer.config().port()); this.subscriptionMaxAge = new AsciiString( "private, max-age=" + webpushServer.config().subscriptionMaxAge()); }
From source file:org.jboss.aerogear.webpush.netty.WebPushFrameListener.java
License:Apache License
private static AsciiString asLink(final AsciiString uri, WebLink rel) { return new AsciiString("<" + uri + ">;rel=\"" + rel + "\""); }
From source file:org.jboss.aerogear.webpush.netty.WebPushFrameListener.java
License:Apache License
private static AsciiString webpushUri(final Resource resource, final String id) { return new AsciiString(WEBPUSH_URI + resource.resourceName() + "/" + id); }
From source file:org.jboss.aerogear.webpush.WebPushClient.java
License:Apache License
private static AsciiString asciiString(final String str) { return new AsciiString(str); }
From source file:org.thingsplode.synapse.proxy.handlers.Request2HttpRequestEncoder.java
License:Apache License
private HttpRequest convert(Request request) throws SerializationException { if (request == null || request.getHeader() == null) { return null; }// w w w .ja va 2 s . c om HttpMethod m = null; if (request.getHeader().getMethod() != null) { m = HttpMethod.valueOf(request.getHeader().getMethod().toString()); } else if (request.getHeader().getUri() != null && !Util.isEmpty(request.getHeader().getUri().getQuery())) { m = HttpMethod.GET; } else if (request.getBody() != null) { m = HttpMethod.PUT; } else { m = HttpMethod.GET; } final HttpRequest out; if (request.getBody() != null) { Optional<String> contentTypeOpt = request.getRequestHeaderProperty(HttpHeaderNames.ACCEPT.toString()); MediaType mt = contentTypeOpt.isPresent() ? new MediaType(contentTypeOpt.get()) : new MediaType(MediaType.APPLICATION_JSON_CT); request.getHeader().addProperty(AbstractMessage.PROP_BODY_TYPE, request.getBody().getClass().getCanonicalName()); byte[] payload = EndpointProxy.SERIALIZATION_SERVICE.getSerializer(mt).marshall(request.getBody()); out = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, m, request.getHeader().getUri().getPath(), Unpooled.wrappedBuffer(payload)); out.headers().add(HttpHeaderNames.CONTENT_LENGTH, payload.length); } else { out = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, m, request.getHeader().getUri().getPath()); } if (request.getHeader().isKeepalive()) { out.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); } if (request.getHeader() != null && request.getHeader().getProperties() != null) { request.getHeader().getProperties().forEach((k, v) -> { out.headers().set(new AsciiString(k), new AsciiString(v != null ? v : "")); }); } return out; }
From source file:org.wso2.carbon.transport.http.netty.listener.http2.HTTP2SourceHandler.java
License:Open Source License
/** * This method handles the cleartext HTTP upgrade event. If an upgrade occurred, sends a simple response via HTTP/2 * on stream 1 (the stream specifically reserved for cleartext HTTP upgrade). * * @param ctx Channel context/* w w w . j a v a 2 s . c om*/ * @param evt Event * @throws Exception Throws when user event trigger has an error */ @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) { // Write an HTTP/2 response to the upgrade request Http2Headers headers = new DefaultHttp2Headers().status(OK.codeAsText()) .set(new AsciiString(Constants.UPGRADE_RESPONSE_HEADER), new AsciiString("true")); encoder().writeHeaders(ctx, 1, headers, 0, true, ctx.newPromise()); } super.userEventTriggered(ctx, evt); }
From source file:org.wso2.carbon.transport.http.netty.util.client.http2.HTTP2Client.java
License:Open Source License
public HTTP2Client(boolean ssl, String host, int port) throws Exception { try {//from www .j a va2 s . c o m final SslContext sslCtx; if (ssl) { SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; sslCtx = SslContextBuilder.forClient().sslProvider(provider) .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .trustManager(InsecureTrustManagerFactory.INSTANCE) .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN, // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers. SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers. SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)) .build(); } else { sslCtx = null; } workerGroup = new NioEventLoopGroup(); HTTP2ClientInitializer initializer = new HTTP2ClientInitializer(sslCtx, Integer.MAX_VALUE); // Configure the client. Bootstrap b = new Bootstrap(); b.group(workerGroup); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(host, port); b.handler(initializer); // Start the client. channel = b.connect().syncUninterruptibly().channel(); log.info("Connected to [" + host + ':' + port + ']'); // Wait for the HTTP/2 upgrade to occur. HTTP2SettingsHandler http2SettingsHandler = initializer.settingsHandler(); http2SettingsHandler.awaitSettings(TestUtil.HTTP2_RESPONSE_TIME_OUT, TestUtil.HTTP2_RESPONSE_TIME_UNIT); responseHandler = initializer.responseHandler(); scheme = ssl ? HttpScheme.HTTPS : HttpScheme.HTTP; hostName = new AsciiString(host + ':' + port); } catch (Exception ex) { log.error("Error while initializing http2 client " + ex); this.close(); } }
From source file:org.wso2.esb.integration.common.utils.clients.Http2Client.java
License:Open Source License
public Http2Response doGet(String url, Map<String, String> headers) { initChannel();//from w w w .j av a 2 s.c o m HttpScheme scheme = SSL ? HttpScheme.HTTPS : HttpScheme.HTTP; AsciiString hostName = new AsciiString(HOST + ':' + PORT); FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, url); if (!headers.isEmpty()) { for (Map.Entry h : headers.entrySet()) { request.headers().add((CharSequence) h.getKey(), h.getValue()); } } request.headers().add(HttpHeaderNames.HOST, hostName); request.headers().add(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), scheme.name()); request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP); request.headers().add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.DEFLATE); io.netty.channel.ChannelPromise p; int s = StreamId; if (responseHandler == null) { log.error("Response handler is null"); return null; } else if (channel == null) { log.error("Channel is null"); return null; } else { responseHandler.put(StreamId, channel.writeAndFlush(request), p = channel.newPromise()); StreamId += 2; Http2Response response; try { while (!p.isSuccess()) { log.info("Waiting for response"); Thread.sleep(20); } response = responseHandler.getResponse(s); } catch (InterruptedException e) { response = null; log.error(e.getStackTrace()); } return response; } }