Search in sources :

Example 11 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project curiostack by curioswitch.

the class UserCredentialsAccessTokenProvider method createRefreshRequestContent.

private static ByteBuf createRefreshRequestContent(UserCredentials credentials) {
    QueryStringEncoder formEncoder = new QueryStringEncoder("");
    formEncoder.addParam("client_id", credentials.getClientId());
    formEncoder.addParam("client_secret", credentials.getClientSecret());
    formEncoder.addParam("refresh_token", credentials.getRefreshToken());
    formEncoder.addParam("grant_type", GRANT_TYPE);
    String contentWithQuestionMark = formEncoder.toString();
    ByteBuf content = Unpooled.buffer(contentWithQuestionMark.length() - 1);
    ByteBufUtil.writeAscii(content, contentWithQuestionMark.substring(1));
    return content;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Example 12 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project vertx-web by vert-x3.

the class HTTPRequestValidationTest method testQueryParamsFailureWithIncludedTypes.

@Test
public void testQueryParamsFailureWithIncludedTypes() throws Exception {
    HTTPRequestValidationHandler validationHandler = HTTPRequestValidationHandler.create().addQueryParam("param1", ParameterType.BOOL, true).addQueryParam("param2", ParameterType.INT, true);
    router.get("/testQueryParams").handler(validationHandler);
    router.get("/testQueryParams").handler(routingContext -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.queryParameter("param1").getBoolean().toString() + params.queryParameter("param2").getInteger().toString());
    }).failureHandler(generateFailureHandler(true));
    QueryStringEncoder encoder = new QueryStringEncoder("/testQueryParams");
    encoder.addParam("param1", getFailureSample(ParameterType.BOOL));
    encoder.addParam("param2", getFailureSample(ParameterType.INT));
    testRequest(HttpMethod.GET, encoder.toString(), 400, "failure:NO_MATCH");
}
Also used : QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) URLEncoder(java.net.URLEncoder) HttpMethod(io.vertx.core.http.HttpMethod) MultiMap(io.vertx.core.MultiMap) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test) BodyHandler(io.vertx.ext.web.handler.BodyHandler) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 13 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project vertx-web by vert-x3.

the class HTTPRequestValidationTest method testQueryParamsArrayAndPathParamsFailureWithIncludedTypes.

@Test
public void testQueryParamsArrayAndPathParamsFailureWithIncludedTypes() throws Exception {
    HTTPRequestValidationHandler validationHandler = HTTPRequestValidationHandler.create().addPathParam("pathParam1", ParameterType.INT).addQueryParamsArray("awesomeArray", ParameterType.EMAIL, true).addQueryParam("anotherParam", ParameterType.DOUBLE, true);
    router.get("/testQueryParams/:pathParam1").handler(validationHandler);
    router.get("/testQueryParams/:pathParam1").handler(routingContext -> {
        RequestParameters params = routingContext.get("parsedParameters");
        routingContext.response().setStatusMessage(params.pathParameter("pathParam1").getInteger().toString() + params.queryParameter("awesomeArray").getArray().size() + params.queryParameter("anotherParam").getDouble().toString()).end();
    }).failureHandler(generateFailureHandler(true));
    String pathParam = getSuccessSample(ParameterType.INT).getInteger().toString();
    String arrayValue1 = getFailureSample(ParameterType.EMAIL);
    String arrayValue2 = getSuccessSample(ParameterType.EMAIL).getString();
    String anotherParam = getSuccessSample(ParameterType.DOUBLE).getDouble().toString();
    QueryStringEncoder encoder = new QueryStringEncoder("/testQueryParams/" + URLEncoder.encode(pathParam, "UTF-8"));
    encoder.addParam("awesomeArray", arrayValue1);
    encoder.addParam("awesomeArray", arrayValue2);
    encoder.addParam("anotherParam", anotherParam);
    testRequest(HttpMethod.GET, encoder.toString(), 400, "failure:NO_MATCH");
}
Also used : QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) URLEncoder(java.net.URLEncoder) HttpMethod(io.vertx.core.http.HttpMethod) MultiMap(io.vertx.core.MultiMap) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test) BodyHandler(io.vertx.ext.web.handler.BodyHandler) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) RequestParameters(io.vertx.ext.web.api.RequestParameters) Test(org.junit.Test)

Example 14 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project jocean-http by isdom.

the class QueryParamPreprocessor method call.

@Override
public RequestChanger call(final Object signalBean) {
    if (null == signalBean) {
        return null;
    }
    final Field[] queryFields = ReflectUtils.getAnnotationFieldsOf(signalBean.getClass(), QueryParam.class);
    if (queryFields.length > 0) {
        return new RequestChanger() {

            @Override
            public void call(final HttpRequest request) {
                // only GET method will assemble query parameters
                // or the QueryParam field explicit annotated HttpMethod via AnnotationWrapper
                // assemble query parameters
                final boolean isGetMethod = request.method().equals(HttpMethod.GET);
                final QueryStringEncoder encoder = new QueryStringEncoder(request.uri());
                for (Field field : queryFields) {
                    if (isGetMethod || Nettys.isFieldAnnotatedOfHttpMethod(field, request.method())) {
                        try {
                            final Object value = field.get(signalBean);
                            if (null != value) {
                                final String paramkey = field.getAnnotation(QueryParam.class).value();
                                encoder.addParam(paramkey, String.valueOf(value));
                            }
                        } catch (Exception e) {
                            LOG.warn("exception when get field({})'s value, detail:{}", field, ExceptionUtils.exception2detail(e));
                        }
                    }
                }
                request.setUri(encoder.toString());
            }

            @Override
            public int ordinal() {
                return 100;
            }
        };
    } else {
        return null;
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Field(java.lang.reflect.Field) QueryParam(javax.ws.rs.QueryParam) RequestChanger(org.jocean.http.rosa.impl.RequestChanger) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder)

Example 15 with QueryStringEncoder

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringEncoder in project jocean-http by isdom.

the class MessageUtil method addQueryParams.

private static void addQueryParams(final HttpRequest request, final Object bean) {
    final Field[] queryFields = ReflectUtils.getAnnotationFieldsOf(bean.getClass(), QueryParam.class);
    if (queryFields.length > 0) {
        final QueryStringEncoder encoder = new QueryStringEncoder(request.uri());
        for (Field field : queryFields) {
            try {
                final Object value = field.get(bean);
                if (null != value) {
                    final String paramkey = field.getAnnotation(QueryParam.class).value();
                    encoder.addParam(paramkey, String.valueOf(value));
                }
            } catch (Exception e) {
                LOG.warn("exception when get field({})'s value, detail:{}", field, ExceptionUtils.exception2detail(e));
            }
        }
        request.setUri(encoder.toString());
    }
}
Also used : Field(java.lang.reflect.Field) QueryParam(javax.ws.rs.QueryParam) HttpObject(io.netty.handler.codec.http.HttpObject) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

QueryStringEncoder (io.netty.handler.codec.http.QueryStringEncoder)18 MultiMap (io.vertx.core.MultiMap)6 ByteBuf (io.netty.buffer.ByteBuf)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 HttpMethod (io.vertx.core.http.HttpMethod)4 RequestParameters (io.vertx.ext.web.api.RequestParameters)4 BodyHandler (io.vertx.ext.web.handler.BodyHandler)4 URLEncoder (java.net.URLEncoder)4 Test (org.junit.Test)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)3 RequestContext (com.linecorp.armeria.common.RequestContext)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)2 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)2 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)2 HttpObject (io.netty.handler.codec.http.HttpObject)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 URI (java.net.URI)2 QueryParam (javax.ws.rs.QueryParam)2