Java Code Examples for io.netty.handler.codec.http.QueryStringEncoder#addParam()
The following examples show how to use
io.netty.handler.codec.http.QueryStringEncoder#addParam() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryParametersTest.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Test public void call_multiple_characters() throws Exception { wireMockRule.stubFor(get(urlPathEqualTo("/team/my_team")).willReturn(ok())); String query = "RECHERCHE,35147,8;RECHERCHE,670620,1"; URI target = new URIBuilder("http://localhost:8082/test/my_team") .addParameter("q", "RECHERCHE,35147,8;RECHERCHE,670620,1") .build(); HttpResponse response = Request.Get(target).execute().returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); QueryStringEncoder encoder = new QueryStringEncoder("/team/my_team"); encoder.addParam("q", query); wireMockRule.verify(getRequestedFor(urlEqualTo(encoder.toString()))); }
Example 2
Source File: QueryParametersTest.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Test public void call_percent_character() throws Exception { wireMockRule.stubFor(get(urlPathEqualTo("/team/my_team")).willReturn(ok())); URI target = new URIBuilder("http://localhost:8082/test/my_team") .addParameter("username", "toto") .addParameter("password", "password%") .build(); HttpResponse response = Request.Get(target).execute().returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); QueryStringEncoder encoder = new QueryStringEncoder("/team/my_team"); encoder.addParam("username", "toto"); encoder.addParam("password", "password%"); wireMockRule.verify(getRequestedFor(urlEqualTo(encoder.toString()))); }
Example 3
Source File: OpenAPI3MultipleFilesValidationTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Test public void testCookieExpandedObjectTestOnlyAdditionalPropertiesFailure() throws Exception { Operation op = testSpec.getPaths() .get("/cookieTests/objectTests/onlyAdditionalProperties") .getGet(); OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl( op, op.getParameters(), testSpec, refsCache); loadHandlers("/cookieTests/objectTests/onlyAdditionalProperties", HttpMethod.GET, true, validationHandler, (routingContext) -> { routingContext.response().setStatusCode(200) .setStatusMessage("OK").end(); }); QueryStringEncoder params = new QueryStringEncoder("/"); params.addParam("param1", Integer.toString(5)); params.addParam("param2", "a"); params.addParam("wellKnownParam", "hello"); testRequestWithCookies(HttpMethod.GET, "/cookieTests/objectTests/onlyAdditionalProperties", params.toUri().getRawQuery(), 400, errorMessage(ValidationException.ErrorType.NO_MATCH)); }
Example 4
Source File: QueryParametersTest.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Test public void call_get_query_with_multiple_parameter_values() throws Exception { wireMockRule.stubFor(get(urlPathEqualTo("/team/my_team")).willReturn(ok())); URI target = new URIBuilder("http://localhost:8082/test/my_team") .addParameter("country", "fr") .addParameter("country", "es") .addParameter("type", "MAG") .build(); HttpResponse response = Request.Get(target).execute().returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); QueryStringEncoder encoder = new QueryStringEncoder("/team/my_team"); encoder.addParam("country", "fr"); encoder.addParam("country", "es"); encoder.addParam("type", "MAG"); wireMockRule.verify(getRequestedFor(urlEqualTo(encoder.toString()))); }
Example 5
Source File: RecurlyClient.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public ListenableFuture<Transactions> getTransactionsForAccount(String accountID, @Nullable Date beginTime, @Nullable Date endTime) { if (Strings.isNullOrEmpty(accountID)) { throw new IllegalArgumentException(ACCOUNT_ID_NULL); } QueryStringEncoder encoder = new QueryStringEncoder(Account.Tags.URL_RESOURCE + "/" + accountID + Transaction.Tags.URL_RESOURCE); DateFormat df = new SimpleDateFormat(ISO_8601_DATE_TIME_FORMAT); if (beginTime != null) { encoder.addParam("begin_time", df.format(beginTime)); } if (endTime != null) { encoder.addParam("end_time", df.format(endTime)); } AsyncTimer requestAsyncTimer = requestTaggingAsyncTimer.tag("op", "getTransactionsForAccount"); return requestAsyncTimer.time(doGET(encoder.toString(), Transactions.class)); }
Example 6
Source File: ProjectionManagerHttp.java From esjc with MIT License | 6 votes |
@Override public CompletableFuture<Void> create(String name, String query, CreateOptions options, UserCredentials userCredentials) { checkArgument(!isNullOrEmpty(name), "name is null or empty"); checkArgument(!isNullOrEmpty(query), "query is null or empty"); checkNotNull(options, "options is null"); QueryStringEncoder queryStringEncoder = new QueryStringEncoder(projectionsUri(options.mode)); queryStringEncoder.addParam("name", name); queryStringEncoder.addParam("type", "JS"); queryStringEncoder.addParam("enabled", Boolean.toString(options.enabled)); switch (options.mode) { case ONE_TIME: queryStringEncoder.addParam("checkpoints", Boolean.toString(options.checkpoints)); case CONTINUOUS: queryStringEncoder.addParam("emit", Boolean.toString(options.emit)); queryStringEncoder.addParam("trackemittedstreams", Boolean.toString(options.trackEmittedStreams)); } return post(queryStringEncoder.toString(), query, userCredentials, HttpResponseStatus.CREATED); }
Example 7
Source File: HTTPRequestValidationTest.java From vertx-web with Apache License 2.0 | 6 votes |
@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"); }
Example 8
Source File: HTTPRequestValidationTest.java From vertx-web with Apache License 2.0 | 6 votes |
@Test public void testQueryParamsWithIncludedTypes() 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()).end(); }).failureHandler(generateFailureHandler(false)); QueryStringEncoder encoder = new QueryStringEncoder("/testQueryParams"); String param1 = getSuccessSample(ParameterType.BOOL).getBoolean().toString(); String param2 = getSuccessSample(ParameterType.INT).getInteger().toString(); encoder.addParam("param1", param1); encoder.addParam("param2", param2); testRequest(HttpMethod.GET, encoder.toString(), 200, param1 + param2); }
Example 9
Source File: TunnelClientSocketClientHandler.java From arthas with Apache License 2.0 | 5 votes |
@Override public void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; String text = textFrame.text(); logger.info("receive TextWebSocketFrame: {}", text); QueryStringDecoder queryDecoder = new QueryStringDecoder(text); Map<String, List<String>> parameters = queryDecoder.parameters(); List<String> methodList = parameters.get("method"); String method = null; if (methodList != null && !methodList.isEmpty()) { method = methodList.get(0); } if ("agentRegister".equals(method)) { List<String> idList = parameters.get("id"); if (idList != null && !idList.isEmpty()) { this.tunnelClient.setId(idList.get(0)); } registerPromise.setSuccess(); } if ("startTunnel".equals(method)) { QueryStringEncoder queryEncoder = new QueryStringEncoder(this.tunnelClient.getTunnelServerUrl()); queryEncoder.addParam("method", "openTunnel"); queryEncoder.addParam("clientConnectionId", parameters.get("clientConnectionId").get(0)); queryEncoder.addParam("id", parameters.get("id").get(0)); URI forwardUri = queryEncoder.toUri(); logger.info("start ForwardClient, uri: {}", forwardUri); ForwardClient forwardClient = new ForwardClient(forwardUri, new URI(this.tunnelClient.getLocalServerUrl()), tunnelClient.getEventLoopGroup()); forwardClient.start(); } } }
Example 10
Source File: ProjectionManagerHttp.java From esjc with MIT License | 5 votes |
@Override public CompletableFuture<Void> delete(String name, DeleteOptions options, UserCredentials userCredentials) { checkArgument(!isNullOrEmpty(name), "name is null or empty"); checkNotNull(options, "options is null"); QueryStringEncoder queryStringEncoder = new QueryStringEncoder(projectionUri(name)); queryStringEncoder.addParam("deleteStateStream", Boolean.toString(options.deleteStateStream)); queryStringEncoder.addParam("deleteCheckpointStream", Boolean.toString(options.deleteCheckpointStream)); queryStringEncoder.addParam("deleteEmittedStreams", Boolean.toString(options.deleteEmittedStreams)); return delete(queryStringEncoder.toString(), userCredentials, HttpResponseStatus.OK); }
Example 11
Source File: ProjectionManagerHttp.java From esjc with MIT License | 5 votes |
@Override public CompletableFuture<Void> update(String name, String query, UpdateOptions options, UserCredentials userCredentials) { checkArgument(!isNullOrEmpty(name), "name is null or empty"); checkArgument(!isNullOrEmpty(query), "query is null or empty"); checkNotNull(options, "options is null"); QueryStringEncoder queryStringEncoder = new QueryStringEncoder(projectionUri(name) + "/query"); queryStringEncoder.addParam("type", "JS"); if (options.emit != null) { queryStringEncoder.addParam("emit", Boolean.toString(options.emit)); } return put(queryStringEncoder.toString(), query, userCredentials, HttpResponseStatus.OK); }
Example 12
Source File: QueryStringEncoderBenchmark.java From armeria with Apache License 2.0 | 5 votes |
private static String nettyEncode(QueryParamGetters params) { final QueryStringEncoder encoder = new QueryStringEncoder("", StandardCharsets.UTF_8); for (Entry<String, String> e : params) { encoder.addParam(e.getKey(), e.getValue()); } return encoder.toString(); }
Example 13
Source File: HTTPRequestValidationTest.java From vertx-web with Apache License 2.0 | 5 votes |
@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"); }
Example 14
Source File: ValidationHandlerProcessorsIntegrationTest.java From vertx-web with Apache License 2.0 | 4 votes |
@Test public void testCookieParamsSimpleTypes(VertxTestContext testContext) { Checkpoint checkpoint = testContext.checkpoint(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(parser) .cookieParameter(param("param1", booleanSchema())) .cookieParameter(param("param2", intSchema())) .build(); router .get("/testCookieParams") .handler(validationHandler) .handler(routingContext -> { RequestParameters params = routingContext.get("parsedParameters"); routingContext .response() .setStatusMessage( params.cookieParameter("param1").toString() + params.cookieParameter("param2").toString() ) .end(); }); QueryStringEncoder successParams = new QueryStringEncoder("/"); successParams.addParam("param1", "true"); successParams.addParam("param2", "10"); testRequest(client, HttpMethod.GET, "/testCookieParams") .with(cookie(successParams)) .expect(statusCode(200), statusMessage("true10")) .send(testContext, checkpoint); QueryStringEncoder failureParams = new QueryStringEncoder("/"); failureParams.addParam("param1", "true"); failureParams.addParam("param2", "bla"); testRequest(client, HttpMethod.GET, "/testCookieParams") .with(cookie(failureParams)) .expect(statusCode(400)) .expect(badParameterResponse( ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "param2", ParameterLocation.COOKIE )) .send(testContext, checkpoint); }
Example 15
Source File: ValidationHandlerProcessorsIntegrationTest.java From vertx-web with Apache License 2.0 | 4 votes |
@Test public void testCookieParamsAsync(VertxTestContext testContext) { Checkpoint checkpoint = testContext.checkpoint(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(parser) .cookieParameter(param("param1", booleanSchema())) .cookieParameter(param("param2", ref(JsonPointer.fromURI(URI.create("int_schema.json"))), ValueParser.LONG_PARSER)) .build(); router .get("/test") .handler(validationHandler) .handler(routingContext -> { RequestParameters params = routingContext.get("parsedParameters"); routingContext .response() .setStatusMessage( params.cookieParameter("param1").toString() + params.cookieParameter("param2").toString() ) .end(); }); QueryStringEncoder successParams = new QueryStringEncoder("/"); successParams.addParam("param1", "true"); successParams.addParam("param2", "10"); testRequest(client, HttpMethod.GET, "/test") .with(cookie(successParams)) .expect(statusCode(200), statusMessage("true10")) .send(testContext, checkpoint); QueryStringEncoder failureParams1 = new QueryStringEncoder("/"); failureParams1.addParam("param1", "true"); failureParams1.addParam("param2", "bla"); testRequest(client, HttpMethod.GET, "/test") .with(cookie(failureParams1)) .expect(statusCode(400)) .expect(badParameterResponse( ParameterProcessorException.ParameterProcessorErrorType.PARSING_ERROR, "param2", ParameterLocation.COOKIE )) .send(testContext, checkpoint); QueryStringEncoder failureParams2 = new QueryStringEncoder("/"); failureParams2.addParam("param1", "true"); failureParams2.addParam("param2", "15"); testRequest(client, HttpMethod.GET, "/test") .with(cookie(failureParams2)) .expect(statusCode(400)) .expect(badParameterResponse( ParameterProcessorException.ParameterProcessorErrorType.VALIDATION_ERROR, "param2", ParameterLocation.COOKIE )) .send(testContext, checkpoint); }
Example 16
Source File: HttpUploadClient.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Standard usage of HTTP API in Netty without file Upload (get is not able to achieve File upload * due to limitation on request size). * * @return the list of headers that will be used in every example after **/ private static List<Entry<String, String>> formget( Bootstrap bootstrap, String host, int port, String get, URI uriSimple) throws Exception { // XXX /formget // No use of HttpPostRequestEncoder since not a POST Channel channel = bootstrap.connect(host, port).sync().channel(); // Prepare the HTTP request. QueryStringEncoder encoder = new QueryStringEncoder(get); // add Form attribute encoder.addParam("getform", "GET"); encoder.addParam("info", "first value"); encoder.addParam("secondinfo", "secondvalue ���&"); // not the big one since it is not compatible with GET size // encoder.addParam("thirdinfo", textArea); encoder.addParam("thirdinfo", "third value\r\ntest second line\r\n\r\nnew line\r\n"); encoder.addParam("Send", "Send"); URI uriGet = new URI(encoder.toString()); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uriGet.toASCIIString()); HttpHeaders headers = request.headers(); headers.set(HttpHeaderNames.HOST, host); headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); headers.set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP + "," + HttpHeaderValues.DEFLATE); headers.set(HttpHeaderNames.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); headers.set(HttpHeaderNames.ACCEPT_LANGUAGE, "fr"); headers.set(HttpHeaderNames.REFERER, uriSimple.toString()); headers.set(HttpHeaderNames.USER_AGENT, "Netty Simple Http Client side"); headers.set(HttpHeaderNames.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); //connection will not close but needed // headers.set("Connection","keep-alive"); // headers.set("Keep-Alive","300"); headers.set( HttpHeaderNames.COOKIE, ClientCookieEncoder.STRICT.encode( new DefaultCookie("my-cookie", "foo"), new DefaultCookie("another-cookie", "bar")) ); // send request channel.writeAndFlush(request); // Wait for the server to close the connection. channel.closeFuture().sync(); // convert headers to list return headers.entries(); }
Example 17
Source File: VideoUtil.java From arcusplatform with Apache License 2.0 | 4 votes |
public static String getMp4Uri(String videoDownloadUrl, UUID recordingId, String exp, String sig) { QueryStringEncoder enc = new QueryStringEncoder(videoDownloadUrl + "/mp4/" + recordingId + ".mp4"); enc.addParam("exp", exp); enc.addParam("sig", sig); return enc.toString(); }
Example 18
Source File: VideoUtil.java From arcusplatform with Apache License 2.0 | 4 votes |
public static String getJpgUri(String videoStreamUrl, UUID recordingId, String exp, String sig) { QueryStringEncoder enc = new QueryStringEncoder(videoStreamUrl + "/jpg/" + recordingId + "/preview.jpg"); enc.addParam("exp", exp); enc.addParam("sig", sig); return enc.toString(); }
Example 19
Source File: QueryParametersTest.java From gravitee-gateway with Apache License 2.0 | 4 votes |
@Test public void call_get_query_with_json_content() throws Exception { wireMockRule.stubFor(get(urlPathEqualTo("/team/my_team")).willReturn(ok())); String query = "{\"key\": \"value\"}"; URI target = new URIBuilder("http://localhost:8082/test/my_team").addParameter(query, null).build(); HttpResponse response = Request.Get(target).execute().returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); QueryStringEncoder encoder = new QueryStringEncoder("/team/my_team"); encoder.addParam(query, null); wireMockRule.verify(getRequestedFor(urlEqualTo("/team/my_team?" + target.getRawQuery()))); }
Example 20
Source File: VideoUtil.java From arcusplatform with Apache License 2.0 | 4 votes |
public static String getHlsUri(String videoStreamUrl, UUID recordingId, String exp, String sig) { QueryStringEncoder enc = new QueryStringEncoder(videoStreamUrl + "/hls/" + recordingId + "/playlist.m3u8"); enc.addParam("exp", exp); enc.addParam("sig", sig); return enc.toString(); }