本文整理汇总了Java中org.springframework.http.HttpStatus.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.valueOf方法的具体用法?Java HttpStatus.valueOf怎么用?Java HttpStatus.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.valueOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleUnauthorizedException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@ExceptionHandler(APIException.class)
public ResponseEntity<String> handleUnauthorizedException(APIException exception) throws InvalidProtocolBufferException {
Status.Builder statusBuilder = Status.newBuilder();
statusBuilder.setCode(exception.getApiExceptionType().getId());
statusBuilder.setReason(exception.getApiExceptionType().getMessage());
statusBuilder.setInfo(exception.getInfo());
statusBuilder.setStatus(Status.StatusFlag.FAILURE);
Status status = statusBuilder.build();
String json;
json = ProtoBufUtils.toJson(status);
return new ResponseEntity<String>(json,HttpStatus.valueOf(exception.getApiExceptionType().getHttpCode()));
}
示例2: reportDayPost
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasAuthority('chef')")
public ResponseEntity<Object> reportDayPost(@ApiParam(value = "",required=true ) @PathVariable("day") String day) throws ApiException{
try {
reportService.reportDayPost(day);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (ApiException ex) {
int exCode = ex.getCode();
return new ResponseEntity<>(HttpStatus.valueOf(exCode));
} catch (Exception e) {
Error error = new Error();
error.setError("500");
error.setMessage(e.getMessage());
return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
示例3: MetricsRest
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
public MetricsRest(Map.Entry<String,Number> metric) {
String[] parts = metric.getKey().split("\\.");
// length == min 4 parts (a metric name can have several dots)
if(parts.length >= 4) {
// parts[2] == http status code
this.status = HttpStatus.valueOf(Integer.valueOf(parts[2]));
if(parts.length - 1 == 3) {
// metric name has no dots, so take only parts[3]
this.name = parts[3];
} else {
// parts[3]..parts[length-1] == http status code
this.name = String.join(".", Arrays.copyOfRange(parts, 3, parts.length));
}
this.value = metric.getValue().longValue();
}
}
示例4: setUpServiceRequests
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private void setUpServiceRequests() throws RestClientException, MalformedURLException {
List<String> requestedServiceOfferings = new ArrayList<String>(Arrays.asList(getServiceLabel()));
List<String> serviceAlternatives = input.getService().getServiceAlternatives();
if (!CollectionUtils.isEmpty(serviceAlternatives)) {
requestedServiceOfferings.addAll(1, serviceAlternatives);
}
for (String requestedServiceOffering : requestedServiceOfferings) {
Map<String, Object> serviceRequest = new HashMap<String, Object>();
serviceRequest.put(SPACE_GUID, SPACE_ID);
serviceRequest.put(SERVICE_NAME, input.getService().getName());
serviceRequest.put("service_plan_guid", getUUID(requestedServiceOffering));
serviceRequest.put(SERVICE_PARAMETERS, input.getService().getCredentials());
serviceRequests.put(requestedServiceOffering, serviceRequest);
}
if (input.getDefaultServiceOfferingHttpReturnCode() != 0) {
HttpStatus httpStatusCode = HttpStatus.valueOf(input.getDefaultServiceOfferingHttpReturnCode());
Mockito.when(restTemplate.postForObject(getUrl("/v2/service_instances?accepts_incomplete=false", new URL(CONTROLLER_ENDPOINT)),
serviceRequests.get(getServiceLabel()), String.class)).thenThrow(new CloudFoundryException(httpStatusCode));
}
}
示例5: getStatus
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request
.getAttribute("javax.servlet.error.status_code");
if (statusCode != null) {
try {
return HttpStatus.valueOf(statusCode);
}
catch (Exception ex) {
}
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
示例6: getStatus
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request
.getAttribute("javax.servlet.error.status_code");
if (statusCode != null) {
try {
return HttpStatus.valueOf(statusCode);
}
catch (Exception ex) {
}
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
示例7: getStatus
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
if (statusCode == null) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return HttpStatus.valueOf(statusCode);
}
示例8: getStatus
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@SuppressWarnings("static-method")
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request
.getAttribute("javax.servlet.error.status_code");
if (statusCode != null) {
return HttpStatus.valueOf(statusCode);
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
示例9: createResponse
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> ResponseEntity<T> createResponse(Object instance, Response response) {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
for (String key : response.headers().keySet()) {
headers.put(key, new LinkedList<>(response.headers().get(key)));
}
return new ResponseEntity<>((T) instance, headers, HttpStatus.valueOf(response.status()));
}
示例10: getStatusCode
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.valueOf(this.response.status());
}
示例11: ordersIdPut
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasAuthority('hungry')")
public ResponseEntity<Object> ordersIdPut(@ApiParam(value = "", required = true) @PathVariable("id") Long id,
@ApiParam(value = "") @RequestParam(value = "userid", required = false, defaultValue = "0") Long userid,
@ApiParam(value = "The order items to modify") @RequestBody UpdateOrderItems updateOrderItems, Errors errors) throws ApiException {
if (errors.hasErrors()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
try {
//OrderUpdate orderUpdate = ordersService.ordersIdPut(id, updateOrderItems, userid);
return new ResponseEntity<>(ordersService.ordersIdPut(id, updateOrderItems, userid), HttpStatus.OK);
} catch (OptimisticLockException ex) {
try {
DailyOrder dailyOrder = ordersService.ordersIdGet(id,updateOrderItems.getDailyMenuId(),updateOrderItems.getDailyMenuVersion(), updateOrderItems.getDailyMenuDate(), userid );
throw new ConcurrentModificationException(409, "Concurrent modification error.", dailyOrder);
} catch (ConcurrentDeletionException e) {
int exCode = e.getCode();
return new ResponseEntity<>(e.getResponseDTO() ,HttpStatus.valueOf(exCode));
} catch (ApiException ex1) {
Logger.getLogger(OrdersApiController.class.getName()).log(Level.SEVERE, null, ex1);
throw new ApiException(500, "Concurrent modification exception: internal error");
}
}
}
示例12: prepareClient
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private void prepareClient() {
for (SimpleService service : stepInput.servicesToDelete) {
Mockito.when(client.getServiceInstance(service.name)).thenReturn(createServiceInstance(service));
if (service.httpErrorCodeToReturnOnDelete != null) {
HttpStatus httpStatusToReturnOnDelete = HttpStatus.valueOf(service.httpErrorCodeToReturnOnDelete);
Mockito.doThrow(new CloudFoundryException(httpStatusToReturnOnDelete)).when(client).deleteService(service.name);
}
}
}
示例13: getStatus
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE);
if (statusCode == null) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return HttpStatus.valueOf(statusCode);
}
示例14: getStatusCode
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
public HttpStatus getStatusCode() throws IOException {
// TODO:springmvc不允许自定义http错误码
return HttpStatus.valueOf(response.getStatusCode());
}
示例15: httpClientErrorException
import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@ExceptionHandler(value = HttpClientErrorException.class)
public ResponseEntity<Object> httpClientErrorException(HttpClientErrorException exception) {
logger.error(exception.getMessage(), exception);
return new ResponseEntity<>(exception.getMessage(), new HttpHeaders(),
HttpStatus.valueOf(exception.getRawStatusCode()));
}