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;
}
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");
}
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");
}
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;
}
}
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());
}
}
Aggregations