Example usage for io.netty.util AsciiString of

List of usage examples for io.netty.util AsciiString of

Introduction

In this page you can find the example usage for io.netty.util AsciiString of.

Prototype

public static AsciiString of(CharSequence string) 

Source Link

Document

Returns an AsciiString containing the given character sequence.

Usage

From source file:org.jboss.aerogear.webpush.netty.WebPushFrameListener.java

License:Apache License

private static Optional<Integer> getTtl(final Http2Headers headers) {
    final CharSequence ttlHeader = headers.get(TTL_HEADER);
    if (ttlHeader != null) {
        Optional.of(AsciiString.of(ttlHeader).parseInt());
    }/*  ww  w .  j a  v a2s .  c om*/
    return Optional.empty();
}

From source file:org.jboss.aerogear.webpush.WebPushClient.java

License:Apache License

public void notify(final String endpointUrl, final String payload, final String receiptUrl, int ttl)
        throws Exception {
    final Http2Headers headers = http2Headers(POST, endpointUrl);
    if (receiptUrl != null && !receiptUrl.isEmpty()) {
        headers.add(PUSH_RECEIPT_HEADER, AsciiString.of(receiptUrl));
    }/*from  www .j a v  a 2s . c  o m*/
    if (ttl > 0) {
        headers.addInt(TTL_HEADER, ttl);
    }
    writeRequest(headers, copiedBuffer(payload, UTF_8));
}

From source file:org.jboss.aerogear.webpush.WebPushClient.java

License:Apache License

private Http2Headers http2Headers(final HttpMethod method, final String url) {
    final URI hostUri = URI.create("https://" + host + ":" + port + "/" + url);
    final Http2Headers headers = new DefaultHttp2Headers().method(AsciiString.of(method.name()));
    headers.path(asciiString(url));//from  ww w  . ja v a2  s  .  co  m
    headers.authority(asciiString(hostUri.getAuthority()));
    headers.scheme(asciiString(hostUri.getScheme()));
    return headers;
}

From source file:org.restnext.core.http.RequestImpl.java

License:Apache License

/**
 * Create a new instance./* w  w  w  .j a v  a 2 s  .c  o  m*/
 *
 * @param context netty channel handler context
 * @param request netty full http request
 */
public RequestImpl(final ChannelHandlerContext context, final FullHttpRequest request) {
    Objects.requireNonNull(request, "request");
    Objects.requireNonNull(context, "context");

    this.charset = HttpUtil.getCharset(request, StandardCharsets.UTF_8);
    this.version = HttpVersion.HTTP_1_0.equals(request.protocolVersion()) ? Version.HTTP_1_0 : Version.HTTP_1_1;
    this.method = Method.valueOf(request.method().name());
    this.uri = URI.create(normalize(request.uri()));
    this.baseUri = createBaseUri(context, request);
    this.keepAlive = HttpUtil.isKeepAlive(request);

    // copy the inbound netty request headers.
    this.headers = new MultivaluedHashMap<>();
    for (Map.Entry<String, String> entry : request.headers()) {
        this.headers.add(entry.getKey().toLowerCase(), entry.getValue());
    }

    this.parameters = new MultivaluedHashMap<>();
    // decode the inbound netty request uri parameters.
    QueryStringDecoder queryDecoder = new QueryStringDecoder(request.uri(), charset);
    for (Map.Entry<String, List<String>> entry : queryDecoder.parameters().entrySet()) {
        this.parameters.addAll(entry.getKey(), entry.getValue());
    }

    // decode the inbound netty request body parameters.
    if (Method.POST.equals(method)) {
        CharSequence charSequence = HttpUtil.getMimeType(request);
        AsciiString mimeType = charSequence != null ? AsciiString.of(charSequence) : AsciiString.EMPTY_STRING;
        boolean isFormData = mimeType.contains(HttpHeaderValues.FORM_DATA);

        if (isFormData) {
            // decode the inbound netty request body multipart/form-data parameters.
            HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(), request,
                    charset);
            try {
                for (InterfaceHttpData data : decoder.getBodyHttpDatas()) {
                    InterfaceHttpData.HttpDataType type = data.getHttpDataType();
                    switch (type) {
                    case Attribute: {
                        try {
                            Attribute attribute = (Attribute) data;
                            this.parameters.add(attribute.getName(), attribute.getValue());
                        } catch (IOException ignore) {
                            LOGGER.warn("Could not get attribute value");
                        }
                        break;
                    }
                    case FileUpload:
                        break;
                    case InternalAttribute:
                        break;
                    default: //nop
                    }
                }
            } finally {
                decoder.destroy();
            }
        } else {
            // decode the inbound netty request body raw | form-url-encoded | octet-stream parameters.
            this.content = request.content().hasArray() ? request.content().array()
                    : request.content().toString(charset).getBytes();
        }
    }
}

From source file:ratpack.session.internal.CookieBasedSessionId.java

License:Apache License

private Optional<AsciiString> getCookieSessionId() {
    if (cookieSessionId == null) {
        if (terminated) {
            return Optional.empty();
        } else {//from  w  ww. ja  va  2  s .c  om
            Cookie match = null;
            for (Cookie cookie : request.getCookies()) {
                if (cookie.name().equals(cookieConfig.getIdName())) {
                    match = cookie;
                    break;
                }
            }
            cookieSessionId = (match == null || match.value().isEmpty()) ? Optional.empty()
                    : Optional.of(AsciiString.of(match.value()));
        }
    }

    return cookieSessionId;
}

From source file:ratpack.session.internal.DefaultSessionIdGenerator.java

License:Apache License

public AsciiString generateSessionId() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    UUID uuid = new UUID(random.nextLong(), random.nextLong());
    return AsciiString.of(uuid.toString());
}