Java Code Examples for org.asynchttpclient.RequestBuilder#build()
The following examples show how to use
org.asynchttpclient.RequestBuilder#build() .
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: AsyncHttpClientEdgeGridSignatureCalculatorTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 6 votes |
@Test(dataProvider = "requests") public void testCalculateAndAddSignatureForGet(Request request) throws Exception { ClientCredential credential = ClientCredential.builder() .accessToken("akaa-dm5g2bfwoodqnc6k-ju7vlao2wz6oz2rp") .clientToken("akaa-k7glklzuxkkh2ycw-oadjphopvpn6yjoj") .clientSecret("SOMESECRET") .host("endpoint.net") .build(); RequestBuilder requestToUpdate = new RequestBuilder(request); new AsyncHttpClientEdgeGridSignatureCalculator(credential).calculateAndAddSignature( request, requestToUpdate); Request updatedRequest = requestToUpdate.build(); assertThat(updatedRequest.getHeaders().get("Authorization"), not(isEmptyOrNullString())); assertThat(updatedRequest.getHeaders().get("Host"), equalTo("endpoint.net")); assertThat(updatedRequest.getUri().getHost(), equalTo("endpoint.net")); }
Example 2
Source File: AsyncHttpClientEdgeGridSignatureCalculatorTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 6 votes |
@Test public void testPreservingQueryString() throws Exception { ClientCredential credential = ClientCredential.builder() .accessToken("akaa-dm5g2bfwoodqnc6k-ju7vlao2wz6oz2rp") .clientToken("akaa-k7glklzuxkkh2ycw-oadjphopvpn6yjoj") .clientSecret("SOMESECRET") .host("endpoint.net") .build(); Request request = new RequestBuilder().setUrl("http://localhost/test?x=y").build(); RequestBuilder requestToUpdate = new RequestBuilder(request); new AsyncHttpClientEdgeGridSignatureCalculator(credential).calculateAndAddSignature( request, requestToUpdate); Request updatedRequest = requestToUpdate.build(); assertThat(updatedRequest.getUri().getQuery(), equalTo("x=y")); }
Example 3
Source File: AsyncHttpClientEdgeGridSignatureCalculatorTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 6 votes |
@Test public void testNotDuplicatingQueryString() throws Exception { ClientCredential credential = ClientCredential.builder() .accessToken("akaa-dm5g2bfwoodqnc6k-ju7vlao2wz6oz2rp") .clientToken("akaa-k7glklzuxkkh2ycw-oadjphopvpn6yjoj") .clientSecret("SOMESECRET") .host("endpoint.net") .build(); Request request = new RequestBuilder().setUrl("http://localhost/test").addQueryParam("x", "y").build(); RequestBuilder requestToUpdate = new RequestBuilder(request); new AsyncHttpClientEdgeGridSignatureCalculator(credential).calculateAndAddSignature( request, requestToUpdate); Request updatedRequest = requestToUpdate.build(); assertThat(updatedRequest.getUri().getQuery(), equalTo("x=y")); }
Example 4
Source File: AzureAsyncContainerProvider.java From dremio-oss with Apache License 2.0 | 5 votes |
private Request buildRequest() throws URISyntaxException { // API - https://docs.microsoft.com/en-gb/rest/api/storageservices/datalakestoragegen2/path/list URIBuilder uriBuilder = new URIBuilder(uri); uriBuilder.addParameter("resource", "account"); uriBuilder.addParameter("continuation", continuation); uriBuilder.addParameter("maxResults", String.valueOf(PAGE_SIZE)); RequestBuilder requestBuilder = AzureAsyncHttpClientUtils.newDefaultRequestBuilder() .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .setUri(Uri.create(uriBuilder.build().toASCIIString())); return requestBuilder.build(); }
Example 5
Source File: AsyncHttpRequest.java From junit-servers with MIT License | 5 votes |
@Override protected HttpResponse doExecute() throws Exception { final HttpUrl endpoint = getEndpoint(); final String scheme = endpoint.getScheme(); final String userInfo = null; final String host = endpoint.getHost(); final int port = endpoint.getPort(); final String path = Utf8UrlEncoder.encodePath(endpoint.getPath()); final String query = null; final String fragment = null; final Uri uri = new Uri(scheme, userInfo, host, port, path, query, fragment); final String method = getMethod().getVerb(); final RequestBuilder builder = new RequestBuilder(method, true).setUri(uri); handleQueryParameters(builder); handleBody(builder); handleHeaders(builder); handleCookies(builder); final Request request = builder.build(); final ListenableFuture<Response> future = client.executeRequest(request); final long start = nanoTime(); final Response response = future.get(); final long duration = nanoTime() - start; return AsyncHttpResponseFactory.of(response, duration); }
Example 6
Source File: Zendesk.java From zendesk-java-client with Apache License 2.0 | 5 votes |
public ArticleAttachments createUploadArticle(long articleId, File file, boolean inline) throws IOException { RequestBuilder builder = reqBuilder("POST", tmpl("/help_center/articles/{id}/attachments.json").set("id", articleId).toString()); builder.setHeader("Content-Type", "multipart/form-data"); if (inline) builder.addBodyPart(new StringPart("inline", "true")); builder.addBodyPart( new FilePart("file", file, "application/octet-stream", StandardCharsets.UTF_8, file.getName())); final Request req = builder.build(); return complete(submit(req, handle(ArticleAttachments.class, "article_attachment"))); }
Example 7
Source File: HttpClient.java From galeb with Apache License 2.0 | 4 votes |
public Response execute(RequestBuilder builder) throws InterruptedException, java.util.concurrent.ExecutionException { Request request = builder.build(); ListenableFuture<Response> listenableFuture = asyncHttpClient.executeRequest(request); return listenableFuture.get(); }
Example 8
Source File: Zendesk.java From zendesk-java-client with Apache License 2.0 | 4 votes |
private Request req(String method, Uri template, String contentType, byte[] body) { RequestBuilder builder = reqBuilder(method, template.toString()); builder.addHeader("Content-type", contentType); builder.setBody(body); return builder.build(); }