當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。