HttpParameters httpParameters() { HttpParameters result = httpParameters; if (result == null) { synchronized (this) { result = httpParameters; if (result == null) { httpParameters = result = httpParametersOf(context.query(), request.headers().contentType(), message); } } } return result; }
private static Optional<Iterable<String>> getJsonPaths(ServiceRequestContext ctx) { final String query = ctx.query(); if (query != null) { final List<String> jsonPaths = new QueryStringDecoder(query, false).parameters().get( "jsonpath"); if (jsonPaths != null) { return Optional.of(ImmutableList.copyOf(jsonPaths)); } } return Optional.empty(); } }
private static Optional<Iterable<String>> getJsonPaths(ServiceRequestContext ctx) { final String query = ctx.query(); if (query != null) { final List<String> jsonPaths = new QueryStringDecoder(query, false).parameters().get( "jsonpath"); if (jsonPaths != null) { return Optional.of(ImmutableList.copyOf(jsonPaths)); } } return Optional.empty(); } }
private static Optional<Iterable<String>> getJsonPaths(ServiceRequestContext ctx) { final String query = ctx.query(); if (query != null) { final List<String> jsonPaths = new QueryStringDecoder(query, false).parameters().get( "jsonpath"); if (jsonPaths != null) { return Optional.of(ImmutableList.copyOf(jsonPaths)); } } return Optional.empty(); } }
private static String getPath(ServiceRequestContext ctx) { // check the path param first final String path = ctx.pathParam("path"); if (!isNullOrEmpty(path)) { return path; } // then check HTTP query final String query = ctx.query(); if (query != null) { final List<String> params = new QueryStringDecoder(query, false).parameters().get("path"); if (params != null) { return params.get(0); } } // return empty string if there's no path return ""; }
public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request, Class<?> expectedResultType) throws Exception { final String queryString = ctx.query(); if (queryString != null) {
private static String getPath(ServiceRequestContext ctx) { // check the path param first final String path = ctx.pathParam("path"); if (!isNullOrEmpty(path)) { return path; } // then check HTTP query final String query = ctx.query(); if (query != null) { final List<String> params = new QueryStringDecoder(query, false).parameters().get("path"); if (params != null) { return params.get(0); } } // return empty string if there's no path return ""; }
private static String getPath(ServiceRequestContext ctx) { // check the path param first final String path = ctx.pathParam("path"); if (!isNullOrEmpty(path)) { return path; } // then check HTTP query final String query = ctx.query(); if (query != null) { final List<String> params = new QueryStringDecoder(query, false).parameters().get("path"); if (params != null) { return params.get(0); } } // return empty string if there's no path return ""; }
@Test public void convertJsonPathQuery() throws Exception { final ServiceRequestContext ctx = mock(ServiceRequestContext.class); final String jsonFilePath = "/a.json"; when(ctx.pathParam("path")).thenReturn(jsonFilePath); final String httpQuery = "?jsonpath=%22%24.a%22"; // "$.a" when(ctx.query()).thenReturn(httpQuery); final Optional<Query<?>> query = convert(ctx); assert query.isPresent(); assertThat(query.get().type()).isSameAs(QueryType.JSON_PATH); assertThat(query.get().path()).isEqualTo(jsonFilePath); assertThat(query.get().expressions().get(0)).isEqualTo("\"$.a\""); }
@Test public void withoutExpression() throws Exception { final ServiceRequestContext ctx = mock(ServiceRequestContext.class); // even though the file is a JSON file, the converted query's type will be IDENTITY because there's no // expression final String jsonFilePath = "/a.json"; when(ctx.pathParam("path")).thenReturn(jsonFilePath); when(ctx.query()).thenReturn(""); final Optional<Query<?>> query = convert(ctx); assert query.isPresent(); assertThat(query.get().type()).isSameAs(QueryType.IDENTITY); assertThat(query.get().path()).isEqualTo(jsonFilePath); }
public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request, Class<?> expectedResultType) throws Exception { final String queryString = ctx.query(); if (queryString != null) {
@Test public void convert() throws Exception { final ServiceRequestContext ctx = mock(ServiceRequestContext.class); final String queryString = "path=/foo.json" + '&' + "pa%22th=/foo1.json" + '&' + "optional_path=/foo2.json" + '&' + "path=/foo3.json" + '&' + "jsonpath=$.a" + '&' + "revision=9999"; when(ctx.query()).thenReturn(queryString); @SuppressWarnings("unchecked") final MergeQuery<JsonNode> mergeQuery = (MergeQuery<JsonNode>) converter.convertRequest( ctx, mock(AggregatedHttpMessage.class), null); assertThat(mergeQuery).isEqualTo( MergeQuery.ofJsonPath( ImmutableList.of(MergeSource.ofRequired("/foo.json"), MergeSource.ofOptional("/foo2.json"), MergeSource.ofRequired("/foo3.json")), ImmutableList.of("$.a"))); } }