Example usage for io.netty.handler.codec.http2 Http2HeadersFrame headers

List of usage examples for io.netty.handler.codec.http2 Http2HeadersFrame headers

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2HeadersFrame headers.

Prototype

Http2Headers headers();

Source Link

Document

A complete header list.

Usage

From source file:org.glassfish.jersey.netty.httpserver.JerseyHttp2ServerHandler.java

License:Open Source License

/**
 * Create Jersey {@link ContainerRequest} based on Netty {@link HttpRequest}.
 *
 * @param ctx          Netty channel context.
 * @param http2Headers Netty Http/2 headers.
 * @return created Jersey Container Request.
 */// w  w  w  .  j  a v a2 s  . co  m
private ContainerRequest createContainerRequest(ChannelHandlerContext ctx, Http2HeadersFrame http2Headers) {

    String path = http2Headers.headers().path().toString();

    String s = path.startsWith("/") ? path.substring(1) : path;
    URI requestUri = URI.create(baseUri + ContainerUtils.encodeUnsafeCharacters(s));

    ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri,
            http2Headers.headers().method().toString(), getSecurityContext(), new PropertiesDelegate() {

                private final Map<String, Object> properties = new HashMap<>();

                @Override
                public Object getProperty(String name) {
                    return properties.get(name);
                }

                @Override
                public Collection<String> getPropertyNames() {
                    return properties.keySet();
                }

                @Override
                public void setProperty(String name, Object object) {
                    properties.put(name, object);
                }

                @Override
                public void removeProperty(String name) {
                    properties.remove(name);
                }
            });

    // request entity handling.
    if (!http2Headers.isEndStream()) {

        ctx.channel().closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
            @Override
            public void operationComplete(Future<? super Void> future) throws Exception {
                isList.add(NettyInputStream.END_OF_INPUT_ERROR);
            }
        });

        requestContext.setEntityStream(new NettyInputStream(isList));
    } else {
        requestContext.setEntityStream(new InputStream() {
            @Override
            public int read() throws IOException {
                return -1;
            }
        });
    }

    // copying headers from netty request to jersey container request context.
    for (CharSequence name : http2Headers.headers().names()) {
        requestContext.headers(name.toString(), mapToString(http2Headers.headers().getAll(name)));
    }

    return requestContext;
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.Http2RequestReader.java

License:Open Source License

/**
 * Handles header frames//  w w w  .java2 s . co m
 *
 * @param frame
 */
public void onHeaderRead(Http2HeadersFrame frame) {
    Http2SourceRequest request;
    if (requestMap.containsKey(frame.streamId())) {
        request = requestMap.get(frame.streamId());
    } else {
        request = new Http2SourceRequest(frame.streamId(), chContext);
        request.setRequestType(Http2Constants.HTTP2_CLIENT_SENT_REQEUST);
        requestMap.put(frame.streamId(), request);
    }
    Set<CharSequence> headerSet = frame.headers().names();
    for (CharSequence header : headerSet) {
        request.setHeader(header.toString(), frame.headers().get(header).toString());
    }
    if (frame.isEndStream()) {
        try {
            messageHandler.processRequest(request);
            requestMap.remove(frame.streamId());
        } catch (Exception e) {
            log.error(e);
        }
    }
}

From source file:org.wso2.esb.integration.common.utils.clients.http2client.Http2Response.java

License:Open Source License

public Http2Response(Http2HeadersFrame frame) {
    responseFromHttp2Server = true;/*  w  w  w.jav  a  2  s .  c o m*/
    if (frame.isEndStream()) {
        endOfStream = true;
    }
    Iterator<Map.Entry<CharSequence, CharSequence>> iterator = frame.headers().iterator();
    while (iterator.hasNext()) {
        Map.Entry<CharSequence, CharSequence> header = iterator.next();
        String key = header.getKey().toString();
        key = (key.charAt(0) == ':') ? key.substring(1) : key;

        if (this.headers.containsKey(key)) {
            this.excessHeaders.put(key, header.getValue().toString());
        } else {
            this.headers.put(key, header.getValue().toString());
        }
    }
    if (headers.containsKey("status")) {
        status = Integer.parseInt(headers.get("status").toString());
    }
    if (headers.containsKey(HttpHeaderNames.CONTENT_TYPE)) {
        expectResponseBody = true;
    }
}

From source file:org.wso2.esb.integration.common.utils.servers.http2.Http2Handler.java

License:Open Source License

public void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception {
    if (headers.isEndStream() && (headers.headers().method().toString()).equalsIgnoreCase("GET")) {
        if (headers.headers().contains("http2-settings")) {
            return;
        }/*from w w w  . j a va  2 s . c  om*/
        Http2Headers headers1 = new DefaultHttp2Headers().status(OK.codeAsText());
        ctx.writeAndFlush(new DefaultHttp2HeadersFrame(headers1));
    }
}