play.libs.ws.WSRequest Java Examples
The following examples show how to use
play.libs.ws.WSRequest.
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: HttpRequestHelper.java From remote-monitoring-services-java with MIT License | 6 votes |
public static void checkStatusCode(WSResponse response, WSRequest request) throws ResourceNotFoundException, ConflictingResourceException, ExternalDependencyException { if (response.getStatus() == 200) { return; } log.info(String.format("Config returns %s for request %s", response.getStatus(), request.getUrl().toString())); switch (response.getStatus()) { case 404: throw new ResourceNotFoundException(String.format("%s, request URL = %s,", response.getBody(), request.getUrl())); case 409: throw new ConflictingResourceException(String.format("%s, request URL = %s,", response.getBody(), request.getUrl())); default: throw new ExternalDependencyException( String.format("WS-request failed, status code = %s, content = %s, request URL = %s", response.getStatus(), response.getBody(), request.getUrl())); } }
Example #2
Source File: AzureResourceManagerClientTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Before public void setUp() { this.wsClient = mock(WSClient.class); this.wsRequest = mock(WSRequest.class); this.wsResponse = mock(WSResponse.class); this.mockUserManagementClient = mock(UserManagementClient.class); ActionsConfig actionsConfig = new ActionsConfig( mockArmEndpointUrl, mockApiVersion, mockUrl, mockResourceGroup, mockSubscriptionId); ServicesConfig config = new ServicesConfig( "http://telemetryurl", "http://storageurl", "http://usermanagementurl", "http://simurl", "template", "mapsKey", actionsConfig); this.client = new AzureResourceManagerClient(config, this.wsClient, this.mockUserManagementClient); }
Example #3
Source File: AzureResourceManagerClientTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = 100000) @Category({UnitTest.class}) public void getOffice365IsEnabled_ReturnsFalseIfNotAuthorized() throws NotAuthorizedException, ExternalDependencyException, ExecutionException, InterruptedException { // Arrange WSRequest wsRequest = mock(WSRequest.class); WSResponse wsResponse = mock(WSResponse.class); when(mockUserManagementClient.getTokenAsync()).thenReturn(CompletableFuture.completedFuture("foo")); when(wsClient.url(any())).thenReturn(wsRequest); when(wsRequest.get()).thenReturn(CompletableFuture.completedFuture(wsResponse)); when(wsResponse.getStatus()).thenReturn(HttpStatus.SC_UNAUTHORIZED); // Act boolean result = this.client.isOffice365EnabledAsync().toCompletableFuture().get(); // Assert Assert.assertFalse(result); }
Example #4
Source File: AzureResourceManagerClientTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = 100000, expected = ExecutionException.class) @Category({UnitTest.class}) public void getOffice365IsEnabled_ReturnsFalseIfForbidden() throws NotAuthorizedException, ExternalDependencyException, ExecutionException, InterruptedException { // Arrange WSRequest wsRequest = mock(WSRequest.class); WSResponse wsResponse = mock(WSResponse.class); when(mockUserManagementClient.getTokenAsync()).thenReturn(CompletableFuture.completedFuture("foo")); when(wsClient.url(any())).thenReturn(wsRequest); when(wsRequest.get()).thenReturn(CompletableFuture.completedFuture(wsResponse)); when(wsResponse.getStatus()).thenReturn(HttpStatus.SC_FORBIDDEN); // Act boolean result = this.client.isOffice365EnabledAsync().toCompletableFuture().get(); }
Example #5
Source File: Play26CallFactory.java From openapi-generator with Apache License 2.0 | 5 votes |
private void addHeaders(WSRequest wsRequest) { for(Map.Entry<String, List<String>> entry : request.headers().toMultimap().entrySet()) { List<String> values = entry.getValue(); for (String value : values) { wsRequest.setHeader(entry.getKey(), value); } } }
Example #6
Source File: Play26CallFactory.java From openapi-generator with Apache License 2.0 | 5 votes |
private void addBody(WSRequest wsRequest) throws IOException { MediaType mediaType = request.body().contentType(); if (mediaType != null) { wsRequest.setContentType(mediaType.toString()); } Buffer buffer = new Buffer(); request.body().writeTo(buffer); wsRequest.setBody(buffer.inputStream()); }
Example #7
Source File: WsRequestBuilder.java From remote-monitoring-services-java with MIT License | 5 votes |
public WSRequest prepareRequest(String url) { WSRequest wsRequest = this.ws .url(url) .addHeader("Content-Type", "application/json") .addHeader("Cache-Control", "no-cache") .addHeader("Referer", "IotHubManager"); wsRequest.setRequestTimeout(Duration.ofSeconds(10)); return wsRequest; }
Example #8
Source File: EmailActionExecutor.java From remote-monitoring-services-java with MIT License | 5 votes |
private WSRequest prepareRequest() { WSRequest wsRequest = this.wsClient .url(this.logicAppEndpointUrl) .addHeader("Csrf-Token", "no-check") .addHeader("Content-Type", "application/json"); return wsRequest; }
Example #9
Source File: WsRequestBuilder.java From remote-monitoring-services-java with MIT License | 5 votes |
public WSRequest prepareRequest(String url) { WSRequest wsRequest = this.ws .url(url) .addHeader("Content-Type", "application/json") .addHeader("Cache-Control", "no-cache") .addHeader("Referer", "Device Telemetry"); wsRequest.setRequestTimeout(Duration.ofSeconds(10)); return wsRequest; }
Example #10
Source File: DiagnosticsClient.java From remote-monitoring-services-java with MIT License | 5 votes |
private WSRequest prepareRequest() { String url = this.diagnosticsEndpointUrl + "/diagnosticsevents"; WSRequest wsRequest = this.wsClient .url(url) .addHeader("Content-Type", "application/json"); return wsRequest; }
Example #11
Source File: Rules.java From remote-monitoring-services-java with MIT License | 5 votes |
private WSRequest prepareRequest(String id) { String url = this.storageUrl; if (id != null) { url = url + "/" + id; } WSRequest wsRequest = this.wsClient .url(url) .addHeader("Content-Type", "application/json"); return wsRequest; }
Example #12
Source File: WsRequestBuilder.java From remote-monitoring-services-java with MIT License | 5 votes |
public WSRequest prepareRequest(String url) { WSRequest wsRequest = this.ws .url(url) .addHeader("Content-Type", "application/json") .addHeader("Cache-Control", "no-cache") .addHeader("Referer", "Config"); wsRequest.setRequestTimeout(Duration.ofSeconds(10)); return wsRequest; }
Example #13
Source File: AzureResourceManagerClient.java From remote-monitoring-services-java with MIT License | 5 votes |
@Override public CompletionStage<Boolean> isOffice365EnabledAsync() throws ExternalDependencyException, NotAuthorizedException { String logicAppTestConnectionUri = String.format("%ssubscriptions/%s/resourceGroups/%s" + "/providers/Microsoft.Web/connections/" + "office365-connector/extensions/proxy/" + "testconnection?api-version=%s", this.armEndpointUrl, this.subscriptionId, this.resourceGroup, this.managementApiVersion); // Gets token from auth service and adds to header WSRequest request = this.createRequest(logicAppTestConnectionUri); return request.get() .handle((response, error) -> { // If the call to testconnection fails with a 403, it means the application was not // assigned the correct permissions to make the request. This can happen if the person doing // the deployment is not an owner, or if there was an issue at deployment time. if (response.getStatus() == HttpStatus.SC_FORBIDDEN) { String message = String.format("The application is not authorized and has not been " + "assigned owner permissions for the subscription. Go to the Azure portal and " + "assign the application as an owner in order to retrieve the token."); log.error(message); throw new CompletionException(new NotAuthorizedException(message)); } WsResponseHelper.checkError(error, "Failed to check status of Office365 Logic App Connector."); // The testconnection call may return a 401, which means the user has not yet configured // the O365 Logic App by signing in with the sender email address. if (response.getStatus() != Http.Status.OK) { log.debug(String.format("Office365 Logic App Connector is not set up.")); return false; } return true; }); }
Example #14
Source File: Play26CallFactory.java From openapi-generator with Apache License 2.0 | 4 votes |
private void addCookies(WSRequest wsRequest) { for (final WSCookie cookie : getCookies()) { wsRequest.addCookie(cookie); } }
Example #15
Source File: IexQuoteServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 4 votes |
private WSRequest quoteRequest(String symbol) { String url = String.format("https://%s/1.0/stock/%s/quote", this.hostName, symbol); return wsClient.url(url); }