当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatus.valueOf方法代码示例

本文整理汇总了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())); 


}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:18,代码来源:ExceptionControllerAdvice.java

示例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);
    }
}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:17,代码来源:ReportApiController.java

示例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();
	}
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:19,代码来源:MetricsRest.java

示例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));
    }

}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:24,代码来源:ServiceCreatorTest.java

示例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;
}
 
开发者ID:ShiftLeftSecurity,项目名称:HelloShiftLeft,代码行数:13,代码来源:AppErrorController.java

示例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;
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:13,代码来源:AppErrorController.java

示例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);
}
 
开发者ID:chaokunyang,项目名称:jkes,代码行数:8,代码来源:EndpointAdvice.java

示例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;
}
 
开发者ID:xjtushilei,项目名称:knowledge-forest-dialogue-recommendation,代码行数:11,代码来源:WxErrorController.java

示例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()));
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:11,代码来源:CustomDecode.java

示例10: getStatusCode

import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
public HttpStatus getStatusCode() throws IOException {
    return HttpStatus.valueOf(this.response.status());
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:5,代码来源:CustomDecode.java

示例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");
        }

    }

}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:29,代码来源:OrdersApiController.java

示例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);
        }
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:10,代码来源:DeleteServicesStepTest.java

示例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);
}
 
开发者ID:chanjarster,项目名称:spring-mvc-error-handling-example,代码行数:8,代码来源:BarControllerAdvice.java

示例14: getStatusCode

import org.springframework.http.HttpStatus; //导入方法依赖的package包/类
@Override
public HttpStatus getStatusCode() throws IOException {
  // TODO:springmvc不允许自定义http错误码
  return HttpStatus.valueOf(response.getStatusCode());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:6,代码来源:CseClientHttpResponse.java

示例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()));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:7,代码来源:ResourceExceptionHandler.java


注:本文中的org.springframework.http.HttpStatus.valueOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。