use of org.springframework.web.util.UriComponentsBuilder in project ma-modules-public by infiniteautomation.
the class RealTimeDataRestController method getAll.
/**
* Get all of the Users Real Time Data
* @param request
* @param limit
* @return
*/
@ApiOperation(value = "List realtime values", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, value = "/list", produces = { "application/json" })
public ResponseEntity<List<RealTimeModel>> getAll(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
RestProcessResult<List<RealTimeModel>> result = new RestProcessResult<List<RealTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
ASTNode root = new ASTNode("limit", limit);
values = root.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
List<RealTimeModel> models = new ArrayList<RealTimeModel>();
UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
for (RealTimeDataPointValue value : values) {
if (value.getDataTypeId() == DataTypes.IMAGE) {
models.add(new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri()));
} else {
models.add(new RealTimeModel(value, value.getValue()));
}
}
return result.createResponseEntity(models);
}
return result.createResponseEntity();
}
use of org.springframework.web.util.UriComponentsBuilder in project spring-security-oauth by spring-projects.
the class OAuth2ClientContextFilter method redirectUser.
/**
* Redirect the user according to the specified exception.
*
* @param e
* The user redirect exception.
* @param request
* The request.
* @param response
* The response.
*/
protected void redirectUser(UserRedirectRequiredException e, HttpServletRequest request, HttpServletResponse response) throws IOException {
String redirectUri = e.getRedirectUri();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(redirectUri);
Map<String, String> requestParams = e.getRequestParams();
for (Map.Entry<String, String> param : requestParams.entrySet()) {
builder.queryParam(param.getKey(), param.getValue());
}
if (e.getStateKey() != null) {
builder.queryParam("state", e.getStateKey());
}
this.redirectStrategy.sendRedirect(request, response, builder.build().encode().toUriString());
}
use of org.springframework.web.util.UriComponentsBuilder in project wombat by PLOS.
the class Link method fillVariables.
private static String fillVariables(String path, final Map<String, ?> variables) {
UriComponentsBuilder builder = ServletUriComponentsBuilder.fromPath(path);
UriComponents.UriTemplateVariables uriVariables = (String name) -> {
Object value = variables.get(name);
if (value == null) {
throw new IllegalArgumentException("Missing required parameter " + name);
}
return value;
};
return builder.build().expand(uriVariables).encode().toString();
}
use of org.springframework.web.util.UriComponentsBuilder in project mots by motech-implementations.
the class IvrService method sendVotoRequest.
private <T> T sendVotoRequest(String url, MultiValueMap<String, String> params, ParameterizedTypeReference<T> responseType, HttpMethod method) throws IvrException {
params.add(API_KEY, ivrApiKey);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).queryParams(params);
HttpEntity<?> request = new HttpEntity<>(headers);
try {
ResponseEntity<T> responseEntity = restTemplate.exchange(builder.build().toString(), method, request, responseType);
return responseEntity.getBody();
} catch (RestClientResponseException ex) {
String responseBodyJson = ex.getResponseBodyAsString();
String responseMessage = responseBodyJson;
String clearVotoInfo = "";
try {
VotoResponseDto<String> votoResponse = mapper.readValue(responseBodyJson, new TypeReference<VotoResponseDto<String>>() {
});
if (votoResponse.getMessage() != null) {
responseMessage = votoResponse.getMessage();
clearVotoInfo = "Invalid IVR service response: " + responseMessage;
}
} catch (IOException e) {
responseMessage = responseBodyJson;
}
String message = "Invalid IVR service response: " + ex.getRawStatusCode() + " " + ex.getStatusText() + ", Response body: " + responseMessage;
throw new IvrException(message, ex, clearVotoInfo);
} catch (RestClientException ex) {
String message = "Error occurred when sending request to IVR service: " + ex.getMessage();
throw new IvrException(message, ex);
}
}
use of org.springframework.web.util.UriComponentsBuilder in project elastest-torm by elastest.
the class EsmServiceClient method provisionServiceInstance.
public String provisionServiceInstance(SupportServiceInstance serviceInstance, String instanceId, String accept_incomplete) {
String serviceInstanceData = "";
logger.info("Request a service instance.");
HttpEntity<String> entity = new HttpEntity<String>(utilTools.convertJsonString(serviceInstance, ProvisionView.class), headers);
Map<String, String> params = new HashMap<>();
params.put("instance_id", instanceId);
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(URL_ESM_PROVISION_INSTANCE).queryParam("accept_incomplete", accept_incomplete);
try {
httpClient.exchange(builder.buildAndExpand(params).toUri(), HttpMethod.PUT, entity, String.class);
logger.info("Registered service.");
} catch (Exception e) {
throw new RuntimeException("Exception provisioning service \"" + serviceInstance.getService_id() + "\" with instanceId \"" + instanceId + "\"", e);
}
return serviceInstanceData;
}
Aggregations