Java Code Examples for com.linecorp.armeria.common.RequestHeaders#of()
The following examples show how to use
com.linecorp.armeria.common.RequestHeaders#of() .
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: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 6 votes |
@Test void deleteFileInvalidRevision() { final WebClient client = dogma.httpClient(); addFooJson(client); addBarTxt(client); final String body = '{' + " \"path\": \"/foo.json\"," + " \"type\": \"REMOVE\"," + " \"commitMessage\" : {" + " \"summary\" : \"Delete foo.json\"" + " }" + '}'; final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX + "?revision=2", HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final AggregatedHttpResponse res = client.execute(headers, body).aggregate().join(); assertThat(ResponseHeaders.of(res.headers()).status()).isEqualTo(HttpStatus.CONFLICT); assertThatJson(res.contentUtf8()).isEqualTo( '{' + " \"exception\": \"" + ChangeConflictException.class.getName() + "\"," + " \"message\": \"${json-unit.ignore}\"" + '}'); }
Example 2
Source File: ListCommitsAndDiffTest.java From centraldogma with Apache License 2.0 | 6 votes |
private static void createProject(CentralDogmaExtension dogma) { final WebClient client = dogma.httpClient(); // the default project used for unit tests RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, "/api/v1/projects", HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); String body = "{\"name\": \"myPro\"}"; client.execute(headers, body).aggregate().join(); // the default repository used for unit tests headers = RequestHeaders.of(HttpMethod.POST, "/api/v1/projects/myPro/repos", HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); body = "{\"name\": \"myRepo\"}"; client.execute(headers, body).aggregate().join(); // default files used for unit tests addFooFile(client); }
Example 3
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 6 votes |
@Test void watchRepository() { final WebClient client = dogma.httpClient(); addFooJson(client); final RequestHeaders headers = RequestHeaders.of(HttpMethod.GET, CONTENTS_PREFIX, HttpHeaderNames.IF_NONE_MATCH, "-1"); final CompletableFuture<AggregatedHttpResponse> future = client.execute(headers).aggregate(); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)) .isExactlyInstanceOf(TimeoutException.class); editFooJson(client); await().atMost(3, TimeUnit.SECONDS).untilAsserted(future::isDone); final AggregatedHttpResponse res = future.join(); final String expectedJson = '{' + " \"revision\" : 3" + '}'; final String actualJson = res.contentUtf8(); assertThatJson(actualJson).isEqualTo(expectedJson); }
Example 4
Source File: ProjectServiceV1Test.java From centraldogma with Apache License 2.0 | 6 votes |
@Test void unremoveProject() { final WebClient client = dogma.httpClient(); createProject(client, "bar"); final String projectPath = PROJECTS_PREFIX + "/bar"; client.delete(projectPath).aggregate().join(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.PATCH, projectPath, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON_PATCH); final String unremovePatch = "[{\"op\":\"replace\",\"path\":\"/status\",\"value\":\"active\"}]"; final AggregatedHttpResponse aRes = client.execute(headers, unremovePatch).aggregate().join(); assertThat(ResponseHeaders.of(aRes.headers()).status()).isEqualTo(HttpStatus.OK); final String expectedJson = '{' + " \"name\": \"bar\"," + " \"creator\": {" + " \"name\": \"System\"," + " \"email\": \"[email protected]\"" + " }," + " \"url\": \"/api/v1/projects/bar\"," + " \"createdAt\": \"${json-unit.ignore}\"" + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); }
Example 5
Source File: RepositoryServiceV1Test.java From centraldogma with Apache License 2.0 | 6 votes |
@Test void createRepositoryInAbsentProject() { final WebClient client = dogma.httpClient(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, PROJECTS_PREFIX + "/absentProject" + REPOS, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final String body = "{\"name\": \"myRepo\"}"; final AggregatedHttpResponse aRes = client.execute(headers, body).aggregate().join(); assertThat(ResponseHeaders.of(aRes.headers()).status()).isEqualTo(HttpStatus.NOT_FOUND); final String expectedJson = '{' + " \"exception\": \"" + ProjectNotFoundException.class.getName() + "\"," + " \"message\": \"Project 'absentProject' does not exist.\"" + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); }
Example 6
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void watchFileTimeout() { final WebClient client = dogma.httpClient(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.GET, CONTENTS_PREFIX + "/foo.json", HttpHeaderNames.IF_NONE_MATCH, "-1", HttpHeaderNames.PREFER, "wait=5"); // 5 seconds final CompletableFuture<AggregatedHttpResponse> future = client.execute(headers).aggregate(); await().between(4, TimeUnit.SECONDS, 6, TimeUnit.SECONDS).until(future::isDone); assertThat(ResponseHeaders.of(future.join().headers()).status()).isSameAs(HttpStatus.NOT_MODIFIED); }
Example 7
Source File: HttpServerTest.java From armeria with Apache License 2.0 | 5 votes |
@ParameterizedTest @ArgumentsSource(ClientAndProtocolProvider.class) void testStrings_noAcceptEncoding(WebClient client) throws Exception { final RequestHeaders req = RequestHeaders.of(HttpMethod.GET, "/strings"); final CompletableFuture<AggregatedHttpResponse> f = client.execute(req).aggregate(); final AggregatedHttpResponse res = f.get(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isNull(); assertThat(res.headers().get(HttpHeaderNames.VARY)).isNull(); assertThat(res.contentUtf8()).isEqualTo("Armeria is awesome!"); }
Example 8
Source File: ProjectServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
private static AggregatedHttpResponse createProject(WebClient client, String name) { final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, PROJECTS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final String body = "{\"name\": \"" + name + "\"}"; return client.execute(headers, body).aggregate().join(); }
Example 9
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void listADirectoryWithoutSlash() { final WebClient client = dogma.httpClient(); final String body = '{' + " \"path\" : \"/a.json/b.json/c.json/d.json\"," + " \"type\" : \"UPSERT_JSON\"," + " \"content\" : {\"a\": \"bar\"}," + " \"commitMessage\" : {" + " \"summary\" : \"Add d.json in weird directory structure\"" + " }" + '}'; final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); client.execute(headers, body).aggregate().join(); final String expectedJson = '[' + " {" + " \"revision\": 2," + " \"path\": \"/a.json/b.json\"," + " \"type\": \"DIRECTORY\"," + " \"url\": \"/api/v1/projects/myPro/repos/myRepo/contents/a.json/b.json\"" + " }" + ']'; // List directory without slash. final AggregatedHttpResponse res1 = client .get("/api/v1/projects/myPro/repos/myRepo/list/a.json").aggregate().join(); assertThatJson(res1.contentUtf8()).isEqualTo(expectedJson); // Listing directory with a slash is same with the listing director without slash which is res1. final AggregatedHttpResponse res2 = client .get("/api/v1/projects/myPro/repos/myRepo/list/a.json/").aggregate().join(); assertThatJson(res2.contentUtf8()).isEqualTo(expectedJson); }
Example 10
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void watchFileWithJsonPathQuery() { final WebClient client = dogma.httpClient(); addFooJson(client); final RequestHeaders headers = RequestHeaders.of(HttpMethod.GET, CONTENTS_PREFIX + "/foo.json?jsonpath=%24.a", HttpHeaderNames.IF_NONE_MATCH, "-1"); final CompletableFuture<AggregatedHttpResponse> future = client.execute(headers).aggregate(); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)) .isExactlyInstanceOf(TimeoutException.class); // An irrelevant change should not trigger a notification. addBarTxt(client); assertThatThrownBy(() -> future.get(500, TimeUnit.MILLISECONDS)) .isExactlyInstanceOf(TimeoutException.class); // Make a relevant change now. editFooJson(client); final String expectedJson = '{' + " \"revision\" : 4," + " \"entry\": {" + " \"revision\" : 4," + " \"path\": \"/foo.json\"," + " \"type\": \"JSON\"," + " \"content\": \"baz\"," + " \"url\": \"/api/v1/projects/myPro/repos/myRepo/contents/foo.json\"" + " }" + '}'; final AggregatedHttpResponse res = future.join(); final String actualJson = res.contentUtf8(); assertThatJson(actualJson).isEqualTo(expectedJson); }
Example 11
Source File: MergeFileTest.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void mismatchedValueWhileMerging() { final WebClient client = dogma.httpClient(); addFilesForMergeJson(client); final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final String body = '{' + " \"path\" : \"/foo10.json\"," + " \"type\" : \"UPSERT_JSON\"," + " \"content\" : {\"a\": 1}," + " \"commitMessage\" : {" + " \"summary\" : \"Add foo3.json\"" + " }" + '}'; client.execute(headers, body).aggregate().join(); final String queryString = "path=/foo.json" + '&' + "path=/foo1.json" + '&' + "path=/foo2.json" + '&' + "path=/foo10.json"; final AggregatedHttpResponse aRes = client.get("/api/v1/projects/myPro/repos/myRepo/merge?" + queryString).aggregate().join(); assertThat(aRes.status()).isEqualTo(HttpStatus.BAD_REQUEST); final String expectedJson = '{' + " \"exception\": \"com.linecorp.centraldogma.common.QueryExecutionException\"," + " \"message\": \"Failed to merge tree. /a/ type: NUMBER (expected: STRING)\"" + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); }
Example 12
Source File: ContentPreviewingServiceTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void contentPreviewBeforeEncoding() { final WebClient client = WebClient.builder(server.httpUri()) .decorator(DecodingClient.newDecorator()) .build(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, "/beforeEncoding", HttpHeaderNames.CONTENT_TYPE, "text/plain"); assertThat(client.execute(headers, "Armeria").aggregate().join().contentUtf8()) .isEqualTo("Hello Armeria!"); final RequestLog requestLog = contextCaptor.get().log().whenComplete().join(); assertThat(requestLog.requestContentPreview()).isEqualTo("Armeria"); assertThat(requestLog.responseContentPreview()).isEqualTo("Hello Armeria!"); }
Example 13
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void addFiles() { final WebClient client = dogma.httpClient(); final String body = '{' + " \"commitMessage\" : {" + " \"summary\" : \"Add foo.json\"," + " \"detail\": \"Add because we need it.\"," + " \"markup\": \"PLAINTEXT\"" + " }," + " \"changes\" : [" + " {" + " \"path\" : \"/foo0.json\"," + " \"type\" : \"UPSERT_JSON\"," + " \"content\" : {\"a\": \"bar\"}" + " }," + " {" + " \"path\" : \"/foo1.json\"," + " \"type\" : \"UPSERT_JSON\"," + " \"content\" : {\"b\": \"bar\"}" + " }" + " ]" + '}'; final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final AggregatedHttpResponse aRes = client.execute(headers, body).aggregate().join(); final String expectedJson = '{' + " \"revision\": 2," + " \"pushedAt\": \"${json-unit.ignore}\"" + '}'; final String actualJson = aRes.contentUtf8(); assertThatJson(actualJson).isEqualTo(expectedJson); }
Example 14
Source File: RepositoryServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void unremoveAbsentRepository() { final WebClient client = dogma.httpClient(); final RequestHeaders headers = RequestHeaders.of(HttpMethod.PATCH, REPOS_PREFIX + "/baz", HttpHeaderNames.CONTENT_TYPE, "application/json-patch+json"); final String unremovePatch = "[{\"op\":\"replace\",\"path\":\"/status\",\"value\":\"active\"}]"; final AggregatedHttpResponse aRes = client.execute(headers, unremovePatch).aggregate().join(); assertThat(ResponseHeaders.of(aRes.headers()).status()).isEqualTo(HttpStatus.NOT_FOUND); }
Example 15
Source File: AnnotatedServiceRequestConverterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testDefaultRequestConverter_bean3() throws Exception { final WebClient client = WebClient.of(server.httpUri()); final ObjectMapper mapper = new ObjectMapper(); AggregatedHttpResponse response; // test for RequestBean3 final RequestBean3 expectedRequestBean = new RequestBean3(3349); expectedRequestBean.userName = "john"; expectedRequestBean.age = 25; expectedRequestBean.gender = MALE; expectedRequestBean.permissions = Arrays.asList("perm1", "perm2"); expectedRequestBean.clientName = "TestClient"; final String expectedResponseContent = mapper.writeValueAsString(expectedRequestBean); // Normal Request: POST + Form Data final HttpData formData = HttpData.ofAscii("age=25&gender=male"); RequestHeaders reqHeaders = RequestHeaders.of(HttpMethod.POST, "/2/default/bean3/john/3349", HttpHeaderNames.of("x-user-permission"), "perm1,perm2", HttpHeaderNames.of("x-client-name"), "TestClient", HttpHeaderNames.CONTENT_TYPE, MediaType.FORM_DATA); response = client.execute(AggregatedHttpRequest.of(reqHeaders, formData)).aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.OK); assertThat(response.contentUtf8()).isEqualTo(expectedResponseContent); // Normal Request: GET + Query String reqHeaders = RequestHeaders.of(HttpMethod.GET, "/2/default/bean3/john?age=25&gender=MALE&departmentNo=3349", HttpHeaderNames.of("x-user-permission"), "perm1,perm2", HttpHeaderNames.of("x-client-name"), "TestClient"); response = client.execute(AggregatedHttpRequest.of(reqHeaders)).aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.OK); assertThat(response.contentUtf8()).isEqualTo(expectedResponseContent); }
Example 16
Source File: ContentServiceV1Test.java From centraldogma with Apache License 2.0 | 5 votes |
@Test void emptyChangeSet() { final WebClient client = dogma.httpClient(); // Add /foo.json and then remove it, which is essentially a no-op. final String body = '{' + " \"commitMessage\": {" + " \"summary\": \"do nothing\"," + " \"detail\": \"\"," + " \"markup\": \"PLAINTEXT\"" + " }," + " \"changes\": [" + " {" + " \"path\": \"/foo.json\"," + " \"type\": \"UPSERT_JSON\"," + " \"content\": {}" + " }," + " {" + " \"path\": \"/foo.json\"," + " \"type\": \"REMOVE\"" + " }" + " ]" + '}'; final RequestHeaders headers = RequestHeaders.of(HttpMethod.POST, CONTENTS_PREFIX, HttpHeaderNames.CONTENT_TYPE, MediaType.JSON); final AggregatedHttpResponse res = client.execute(headers, body).aggregate().join(); assertThat(ResponseHeaders.of(res.headers()).status()).isEqualTo(HttpStatus.CONFLICT); assertThatJson(res.contentUtf8()).isEqualTo( '{' + " \"exception\": \"" + RedundantChangeException.class.getName() + "\"," + " \"message\": \"${json-unit.ignore}\"" + '}'); }
Example 17
Source File: AnnotatedServiceRequestConverterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testDefaultRequestConverter_bean2() throws Exception { final WebClient client = WebClient.of(server.httpUri()); final ObjectMapper mapper = new ObjectMapper(); AggregatedHttpResponse response; // test for RequestBean2 final RequestBean2 expectedRequestBean = new RequestBean2(98765L, "abcd-efgh"); expectedRequestBean.userName = "john"; expectedRequestBean.age = 25; expectedRequestBean.gender = MALE; expectedRequestBean.permissions = Arrays.asList("perm1", "perm2"); expectedRequestBean.clientName = "TestClient"; final String expectedResponseContent = mapper.writeValueAsString(expectedRequestBean); // Normal Request: POST + Form Data final HttpData formData = HttpData.ofAscii("age=25&gender=male"); RequestHeaders reqHeaders = RequestHeaders.of(HttpMethod.POST, "/2/default/bean2/john/98765", HttpHeaderNames.of("x-user-permission"), "perm1,perm2", HttpHeaderNames.of("x-client-name"), "TestClient", HttpHeaderNames.of("uid"), "abcd-efgh", HttpHeaderNames.CONTENT_TYPE, MediaType.FORM_DATA); response = client.execute(AggregatedHttpRequest.of(reqHeaders, formData)).aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.OK); assertThat(response.contentUtf8()).isEqualTo(expectedResponseContent); // Normal Request: GET + Query String reqHeaders = RequestHeaders.of(HttpMethod.GET, "/2/default/bean2/john?age=25&gender=MALE&serialNo=98765", HttpHeaderNames.of("x-user-permission"), "perm1,perm2", HttpHeaderNames.of("x-client-name"), "TestClient", HttpHeaderNames.of("uid"), "abcd-efgh"); response = client.execute(AggregatedHttpRequest.of(reqHeaders)).aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.OK); assertThat(response.contentUtf8()).isEqualTo(expectedResponseContent); }
Example 18
Source File: FileWriter.java From curiostack with MIT License | 4 votes |
private CompletableFuture<Void> doUploadChunk(ByteBuf chunk, boolean endOfFile) { int length = chunk.readableBytes(); long limit = filePosition + length; StringBuilder range = new StringBuilder("bytes "); if (length == 0) { range.append('*'); } else { range.append(filePosition).append('-').append(limit - 1); } range.append('/'); if (endOfFile) { range.append(limit); } else { range.append('*'); } RequestHeaders headers = RequestHeaders.of( HttpMethod.PUT, uploadUrl, HttpHeaderNames.CONTENT_RANGE, range.toString()); HttpData data = new ByteBufHttpData(chunk, true); chunk.retain(); return httpClient .execute(headers, data) .aggregate(eventLoop) .thenComposeAsync( msg -> { ResponseHeaders responseHeaders = msg.headers(); if (!responseHeaders.status().codeClass().equals(HttpStatusClass.SUCCESS) && responseHeaders.status().code() != 308) { chunk.release(); throw new RuntimeException( "Unsuccessful response uploading chunk: endOfFile: " + endOfFile + " Request headers: " + headers + "\n" + " Response headers: " + responseHeaders + "\n" + msg.content().toStringUtf8()); } String responseRange = responseHeaders.get(HttpHeaderNames.RANGE); if (responseRange == null) { chunk.release(); return completedFuture(null); } long responseLimit = rangeHeaderLimit(responseHeaders.get(HttpHeaderNames.RANGE)); filePosition = responseLimit + 1; int notUploaded = (int) (limit - 1 - responseLimit); if (notUploaded > 0) { chunk.readerIndex(chunk.writerIndex() - notUploaded); if (endOfFile) { return doUploadChunk(chunk, true); } if (unfinishedChunk == null) { copyUnfinishedBuffer(chunk); } else { ByteBuf newUnfinished = alloc.buffer(chunk.readableBytes() + unfinishedChunk.readableBytes()); newUnfinished.writeBytes(chunk).writeBytes(unfinishedChunk); unfinishedChunk.release(); unfinishedChunk = newUnfinished; } } chunk.release(); return completedFuture(null); }, eventLoop); }
Example 19
Source File: ContentPreviewerFactoryTest.java From armeria with Apache License 2.0 | 4 votes |
private static RequestHeaders reqHeaders(MediaType contentType) { return RequestHeaders.of(HttpMethod.POST, "/", HttpHeaderNames.CONTENT_TYPE, contentType); }
Example 20
Source File: RouteTest.java From armeria with Apache License 2.0 | 4 votes |
private static RoutingContext consumeType(HttpMethod method, MediaType contentType) { final RequestHeaders headers = RequestHeaders.of(method, PATH, HttpHeaderNames.CONTENT_TYPE, contentType); return DefaultRoutingContext.of(virtualHost(), "example.com", PATH, null, headers, false); }