use of org.springframework.http.HttpStatus in project logback-access-spring-boot-starter by akihyro.
the class ResponseEntityAssert method hasStatusCode.
/**
* Verifies that the status code is equal to the given one.
*
* @param status the status.
* @return this instance.
* @see ResponseEntity#getStatusCode()
*/
public S hasStatusCode(HttpStatus status) {
HttpStatus actualStatusCode = actual.getStatusCode();
Assertions.assertThat(actualStatusCode).isEqualTo(status);
return myself;
}
use of org.springframework.http.HttpStatus in project dhis2-core by dhis2.
the class WebMessageService method send.
public void send(WebMessage webMessage, HttpServletResponse response, HttpServletRequest request) {
String type = request.getHeader("Accept");
type = !StringUtils.isEmpty(type) ? type : request.getContentType();
type = !StringUtils.isEmpty(type) ? type : MediaType.APPLICATION_JSON_VALUE;
HttpStatus httpStatus = HttpStatus.valueOf(webMessage.getHttpStatusCode());
if (httpStatus.is4xxClientError() || httpStatus.is5xxServerError()) {
response.setHeader("Cache-Control", CacheControl.noCache().cachePrivate().getHeaderValue());
}
// allow type to be overridden by path extension
if (request.getPathInfo().endsWith(".json")) {
type = MediaType.APPLICATION_JSON_VALUE;
} else if (request.getPathInfo().endsWith(".xml")) {
type = MediaType.APPLICATION_XML_VALUE;
}
if (isCompatibleWith(type, MediaType.APPLICATION_JSON)) {
sendJson(webMessage, response);
} else if (isCompatibleWith(type, MediaType.APPLICATION_XML)) {
sendXml(webMessage, response);
} else {
// default to json
sendJson(webMessage, response);
}
}
use of org.springframework.http.HttpStatus in project dhis2-core by dhis2.
the class ClickatellGateway method send.
@Override
public OutboundMessageResponse send(String subject, String text, Set<String> recipients, SmsGatewayConfig config) {
ClickatellGatewayConfig clickatellConfiguration = (ClickatellGatewayConfig) config;
HttpEntity<ClickatellRequestEntity> request = new HttpEntity<>(getRequestBody(text, recipients), getRequestHeaderParameters(clickatellConfiguration));
HttpStatus httpStatus = send(clickatellConfiguration.getUrlTemplate() + MAX_MESSAGE_PART, request, ClickatellResponseEntity.class);
return wrapHttpStatus(httpStatus);
}
use of org.springframework.http.HttpStatus in project dhis2-core by dhis2.
the class DefaultSynchronizationManager method isRemoteServerAvailable.
// -------------------------------------------------------------------------
// SynchronizatonManager implementation
// -------------------------------------------------------------------------
@Override
public AvailabilityStatus isRemoteServerAvailable() {
Configuration config = configurationService.getConfiguration();
if (!isRemoteServerConfigured(config)) {
return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
}
String url = systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
String username = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
String password = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_PASSWORD);
log.debug(String.format("Remote server ping URL: %s, username: %s", url, username));
HttpEntity<String> request = getBasicAuthRequestEntity(username, password);
ResponseEntity<String> response = null;
HttpStatus sc = null;
String st = null;
AvailabilityStatus status = null;
try {
response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
sc = response.getStatusCode();
} catch (HttpClientErrorException ex) {
sc = ex.getStatusCode();
st = ex.getStatusText();
} catch (HttpServerErrorException ex) {
sc = ex.getStatusCode();
st = ex.getStatusText();
} catch (ResourceAccessException ex) {
return new AvailabilityStatus(false, "Network is unreachable", HttpStatus.BAD_GATEWAY);
}
log.debug("Response status code: " + sc);
if (HttpStatus.FOUND.equals(sc)) {
status = new AvailabilityStatus(false, "No authentication was provided", sc);
} else if (HttpStatus.UNAUTHORIZED.equals(sc)) {
status = new AvailabilityStatus(false, "Authentication failed", sc);
} else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(sc)) {
status = new AvailabilityStatus(false, "Remote server experienced an internal error", sc);
} else if (HttpStatus.OK.equals(sc)) {
status = new AvailabilityStatus(true, "Authentication was successful", sc);
} else {
status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
}
log.info("Status: " + status);
return status;
}
use of org.springframework.http.HttpStatus in project cuba by cuba-platform.
the class ServicesController method invokeServiceMethodPost.
@PostMapping("/{serviceName}/{methodName}")
public ResponseEntity<String> invokeServiceMethodPost(@PathVariable String serviceName, @PathVariable String methodName, @RequestParam(required = false) String modelVersion, @RequestBody(required = false) String paramsJson) {
ServicesControllerManager.ServiceCallResult result = servicesControllerManager.invokeServiceMethodPost(serviceName, methodName, paramsJson, modelVersion);
HttpStatus status;
if (result == null) {
status = HttpStatus.NO_CONTENT;
result = new ServicesControllerManager.ServiceCallResult("", false);
} else {
status = HttpStatus.OK;
}
String contentType = result.isValidJson() ? "application/json;charset=UTF-8" : "text/plain;charset=UTF-8";
return ResponseEntity.status(status).header("Content-Type", contentType).body(result.getStringValue());
}
Aggregations