use of org.springframework.web.util.UriComponentsBuilder in project open-kilda by telstra.
the class SwitchIntegrationService method getIslLinkPortsInfo.
/**
* Gets the isl links port info.
*
* @return the isl links port info
*/
public List<IslLink> getIslLinkPortsInfo(final LinkProps keys) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_LINKS);
builder = setLinkProps(keys, builder);
String fullUri = builder.build().toUriString();
HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
if (RestClientManager.isValidResponse(response)) {
List<IslLink> links = restClientManager.getResponseList(response, IslLink.class);
return links;
}
return null;
}
use of org.springframework.web.util.UriComponentsBuilder in project connectors-workspace-one by vmware.
the class SalesforceControllerTest method expectSalesforceRequest.
private ResponseActions expectSalesforceRequest(String soqlQuery) throws IOException {
UriComponentsBuilder builder = fromHttpUrl(SERVER_URL).path(ACCOUNT_SEARCH_PATH).queryParam("q", soqlQuery);
URI tmp = builder.build().toUri();
return mockSF.expect(requestTo(tmp)).andExpect(method(HttpMethod.GET)).andExpect(MockRestRequestMatchers.header(HttpHeaders.AUTHORIZATION, "Bearer abc"));
}
use of org.springframework.web.util.UriComponentsBuilder in project connectors-workspace-one by vmware.
the class SalesforceControllerTest method testAddConversations.
@Test
void testAddConversations() throws Exception {
UriComponentsBuilder addTaskReqBuilder = fromHttpUrl(SERVER_URL).path(LINK_OPPORTUNITY_TASK_PATH);
UriComponentsBuilder addAttachmentReqBuilder = fromHttpUrl(SERVER_URL).path(LINK_ATTACHMENT_TASK_PATH);
Map<String, String> userContactDetailMap = getUserContactDetails("/salesforce/request/conversations.txt");
expectSalesforceRequest(String.format(QUERY_FMT_CONTACT_ID, userContactDetailMap.get("contact_email"), userContactDetailMap.get("user_email"))).andRespond(withSuccess(sfExistingContactId, APPLICATION_JSON));
mockSF.expect(requestTo(addTaskReqBuilder.build().toUri())).andExpect(method(HttpMethod.POST)).andExpect(MockRestRequestMatchers.header(HttpHeaders.AUTHORIZATION, "Bearer abc")).andRespond(withSuccess(sfResponseTaskCreated, APPLICATION_JSON));
mockSF.expect(requestTo(addAttachmentReqBuilder.build().toUri())).andExpect(method(HttpMethod.POST)).andExpect(MockRestRequestMatchers.header(HttpHeaders.AUTHORIZATION, "Bearer abc")).andRespond(withSuccess(sfResponseAttachmentCreated, APPLICATION_JSON));
perform(requestAddConversationAsAttcahment("abc", "/salesforce/request/conversations.txt")).andExpect(status().isOk());
mockSF.verify();
}
use of org.springframework.web.util.UriComponentsBuilder in project tutorials by eugenp.
the class ApiClient method invokeAPI.
/**
* Invoke API by sending HTTP request with the given options.
*
* @param <T> the return type to use
* @param path The sub-path of the HTTP URL
* @param method The request method
* @param queryParams The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param accept The request's Accept header
* @param contentType The request's Content-Type header
* @param authNames The authentications to apply
* @param returnType The return type into which to deserialize the response
* @return The response body in chosen type
*/
public <T> T invokeAPI(String path, HttpMethod method, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, Object> formParams, List<MediaType> accept, MediaType contentType, String[] authNames, ParameterizedTypeReference<T> returnType) throws RestClientException {
updateParamsForAuth(authNames, queryParams, headerParams);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path);
if (queryParams != null) {
builder.queryParams(queryParams);
}
final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri());
if (accept != null) {
requestBuilder.accept(accept.toArray(new MediaType[accept.size()]));
}
if (contentType != null) {
requestBuilder.contentType(contentType);
}
addHeadersToRequest(headerParams, requestBuilder);
addHeadersToRequest(defaultHeaders, requestBuilder);
RequestEntity<Object> requestEntity = requestBuilder.body(selectBody(body, formParams, contentType));
ResponseEntity<T> responseEntity = restTemplate.exchange(requestEntity, returnType);
statusCode = responseEntity.getStatusCode();
responseHeaders = responseEntity.getHeaders();
if (responseEntity.getStatusCode() == HttpStatus.NO_CONTENT) {
return null;
} else if (responseEntity.getStatusCode().is2xxSuccessful()) {
if (returnType == null) {
return null;
}
return responseEntity.getBody();
} else {
// The error handler built into the RestTemplate should handle 400 and 500 series errors.
throw new RestClientException("API returned " + statusCode + " and it wasn't handled by the RestTemplate error handler");
}
}
use of org.springframework.web.util.UriComponentsBuilder in project spring-integration by spring-projects.
the class AbstractHttpRequestExecutingMessageHandler method generateUri.
private URI generateUri(Message<?> requestMessage) {
Object uri = this.uriExpression.getValue(this.evaluationContext, requestMessage);
Assert.state(uri instanceof String || uri instanceof URI, "'uriExpression' evaluation must result in a 'String' or 'URI' instance, not: " + (uri == null ? "null" : uri.getClass()));
Map<String, ?> uriVariables = determineUriVariables(requestMessage);
UriComponentsBuilder uriComponentsBuilder = uri instanceof String ? UriComponentsBuilder.fromUriString((String) uri) : UriComponentsBuilder.fromUri((URI) uri);
UriComponents uriComponents = uriComponentsBuilder.buildAndExpand(uriVariables);
try {
return this.encodeUri ? uriComponents.toUri() : new URI(uriComponents.toUriString());
} catch (URISyntaxException e) {
throw new MessageHandlingException(requestMessage, "Invalid URI [" + uri + "]", e);
}
}
Aggregations