本文整理匯總了Java中org.springframework.web.bind.annotation.ResponseStatus類的典型用法代碼示例。如果您正苦於以下問題:Java ResponseStatus類的具體用法?Java ResponseStatus怎麽用?Java ResponseStatus使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResponseStatus類屬於org.springframework.web.bind.annotation包,在下文中一共展示了ResponseStatus類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: exception
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
logger.error("Exception during execution of SpringSecurity application", throwable);
StringBuffer sb = new StringBuffer();
sb.append("Exception during execution of Spring Security application! ");
sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));
if (throwable != null && throwable.getCause() != null) {
sb.append("\n\nroot cause: ").append(throwable.getCause());
}
model.addAttribute("error", sb.toString());
ModelAndView mav = new ModelAndView();
mav.addObject("error", sb.toString());
mav.setViewName("error");
return mav;
}
示例2: processRuntimeException
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception {
BodyBuilder builder;
ErrorDTO errorDTO;
ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
if (responseStatus != null) {
builder = ResponseEntity.status(responseStatus.value());
errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason());
} else {
builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
}
log.error("Exception in rest call", ex);
errorDTO.add("error", "error", ex.getMessage());
return builder.body(errorDTO);
}
示例3: exception
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
logger.error("Exception during execution of SpringSecurity application", throwable);
StringBuffer sb = new StringBuffer();
sb.append("Exception during execution of Spring Security application! ");
sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));
if (throwable != null && throwable.getCause() != null) {
sb.append(" root cause: ").append(throwable.getCause());
}
model.addAttribute("error", sb.toString());
ModelAndView mav = new ModelAndView();
mav.addObject("error", sb.toString());
mav.setViewName("error");
return mav;
}
示例4: getFormModels
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ApiOperation(value = "分頁查詢表單模型", notes = "根據傳進來的查詢參數,獲取表單模型信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主鍵ID", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "category", value = "模型分類,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "key", value = "模型鍵,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "name", value = "模型名稱,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "tenantId", value = "租戶ID,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageNum", value = "分頁查詢開始查詢的頁碼", defaultValue = "1", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "pageSize", value = "分頁查詢每頁顯示的記錄數", defaultValue = "10", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "sortName", value = "排序的字段,可以多值以逗號分割", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "sortOrder", value = "排序的方式,可以為asc或desc,可以多值以逗號分割", required = false, dataType = "string", paramType = "query")
})
@RequestMapping(value = "/form-models", method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(value = HttpStatus.OK)
public PageResponse<FormModelResponse> getFormModels(@ApiIgnore @RequestParam Map<String, String> requestParams) {
Criteria<FormModel> criteria = new Criteria<FormModel>();
criteria.add(Restrictions.eq("id", requestParams.get("id"), true));
criteria.add(Restrictions.like("category", requestParams.get("category"), true));
criteria.add(Restrictions.like("key", requestParams.get("key"), true));
criteria.add(Restrictions.like("name", requestParams.get("name"), true));
criteria.add(Restrictions.like("tenantId", requestParams.get("tenantId"), true));
return responseFactory.createFormModelPageResponse(formModelRepository.findAll(criteria, getPageable(requestParams)));
}
示例5: create
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@Authorize(scopes = "roles:create")
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "/v1/roles", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public RoleRepresentation create(@RequestBody RoleRepresentation representation) {
Role role = roleConversionService.convert(representation);
Role created = roleService.create(role).orThrow();
return roleConversionService.convert(roleService.findById(created.getId()).orThrow());
}
示例6: exception
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
logger.error("Exception during execution of SpringSecurity application", throwable);
StringBuffer sb = new StringBuffer();
sb.append("Exception during execution of Spring Security application! ");
sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));
sb.append(", root cause: ").append((throwable != null && throwable.getCause() != null ? throwable.getCause() : "Unknown cause"));
model.addAttribute("error", sb.toString());
ModelAndView mav = new ModelAndView();
mav.addObject("error", sb.toString());
mav.setViewName("error");
return mav;
}
示例7: completeRegistration
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@PostMapping(value = "/complete/registration", headers = "Accept=application/json", params = "action=Submit")
@ResponseStatus(value = HttpStatus.ACCEPTED)
public String completeRegistration(@ModelAttribute final RegistrationRequest request, final Map<String, Object> model)
throws UserExistsException, IOException, InterruptedException {
LOGGER.info("Completing registration for transcript owner");
if (userService.isRegistered(request.getRecipientEmailAddress())) {
model.put("alreadyRegistered", true);
} else if (userService.completeRegistration(request)) {
LOGGER.info("Adding qualifications");
model.put("success", true);
RegistrationRequest registrationRequest = new RegistrationRequest();
model.put("registrationRequest", registrationRequest);
} else {
model.put("error", true);
}
return "registration";
}
示例8: changePassword
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/auth/changePassword", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void changePassword (
@RequestParam(value = "currentPassword") String currentPassword,
@RequestParam(value = "newPassword") String newPassword) throws IoTPException {
try {
SecurityUser securityUser = getCurrentUser();
UserCredentials userCredentials = userService.findUserCredentialsByUserId(securityUser.getId());
if (!passwordEncoder.matches(currentPassword, userCredentials.getPassword())) {
throw new IoTPException("Current password doesn't match!", IoTPErrorCode.BAD_REQUEST_PARAMS);
}
userCredentials.setPassword(passwordEncoder.encode(newPassword));
userService.saveUserCredentials(userCredentials);
} catch (Exception e) {
throw handleException(e);
}
}
示例9: activateProcessDefinition
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@RequestMapping(value = "/process-definition/{processDefinitionId}/activate", method = RequestMethod.PUT, produces = "application/json", name = "流程定義激活")
@ResponseStatus(value = HttpStatus.OK)
public void activateProcessDefinition(@PathVariable String processDefinitionId,@RequestBody(required=false) ProcessDefinitionActionRequest actionRequest) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
if (!processDefinition.isSuspended()) {
throw new FlowableConflictException("Process definition with id '" + processDefinition.getId() + " ' is already active");
}
if (actionRequest == null) {
repositoryService.activateProcessDefinitionById(processDefinitionId);
}else{
repositoryService.activateProcessDefinitionById(processDefinition.getId(), actionRequest.isIncludeProcessInstances(),actionRequest.getDate());
}
}
示例10: deletePlugin
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deletePlugin(@PathVariable("pluginId") String strPluginId) throws IoTPException {
checkParameter("pluginId", strPluginId);
try {
PluginId pluginId = new PluginId(toUUID(strPluginId));
PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId));
pluginService.deletePluginById(pluginId);
//actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.DELETED);
JsonObject json = new JsonObject();
json.addProperty(ThingsMetaKafkaTopics.TENANT_ID, plugin.getTenantId().toString());
json.addProperty(ThingsMetaKafkaTopics.PLUGIN_ID, plugin.getId().toString());
json.addProperty(ThingsMetaKafkaTopics.EVENT, ComponentLifecycleEvent.DELETED.name());
msgProducer.send(ThingsMetaKafkaTopics.METADATA_PLUGIN_TOPIC, plugin.getId().toString(), json.toString());
} catch (Exception e) {
throw handleException(e);
}
}
示例11: saveRelation
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relation", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void saveRelation(@RequestBody EntityRelation relation) throws IoTPException {
try {
checkNotNull(relation);
checkEntityId(relation.getFrom());
checkEntityId(relation.getTo());
if (relation.getTypeGroup() == null) {
relation.setTypeGroup(RelationTypeGroup.COMMON);
}
relationService.saveRelation(relation).get();
} catch (Exception e) {
throw handleException(e);
}
}
示例12: handleHttpRequestMethodNotSupportedException
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
//對於接口方法不匹配的異常處理
public BasicResult handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException e) {
logError("httpRequestMethodNotSupportedException", e.getMessage(), e);
return BasicResult
.fail(BasicResultCode.METHOD_NOT_ALLOW_ERROR.getCode(),
BasicResultCode.METHOD_NOT_ALLOW_ERROR.getMsg(),
e.getMessage());
}
示例13: handle
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@ExceptionHandler(ServletRequestBindingException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ErrorResponse handle(final ServletRequestBindingException ex) {
log.error("Missing parameter", ex);
return new ErrorResponse("MISSING_PARAMETER", ex.getMessage());
}
示例14: returnTask
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@RequestMapping(value="/task/{taskId}/return", method = RequestMethod.PUT, name="任務回退")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public List<TaskResponse> returnTask(@PathVariable("taskId") String taskId,@RequestBody(required=false) TaskActionRequest actionRequest) {
List<TaskResponse> responses = new ArrayList<TaskResponse>();
Task task = getTaskFromRequest(taskId);
if(task.getAssignee()==null){
taskService.setAssignee(taskId, Authentication.getAuthenticatedUserId());
}
/* List<Task> tasks = taskExtService.returnTask(task.getId());
for(Task nextTask : tasks){
TaskExt taskExt = taskExtService.getTaskExtById(nextTask.getId());
responses.add(restResponseFactory.createTaskResponse(taskExt));
}*/
return responses;
}
示例15: sendActivationEmail
import org.springframework.web.bind.annotation.ResponseStatus; //導入依賴的package包/類
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/user/sendActivationMail", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void sendActivationEmail(
@RequestParam(value = "email") String email,
HttpServletRequest request) throws IoTPException {
try {
User user = checkNotNull(userService.findUserByEmail(email));
UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
if (!userCredentials.isEnabled()) {
String baseUrl = constructBaseUrl(request);
String activateUrl = String.format("%s/api/noauth/activate?activateToken=%s", baseUrl,
userCredentials.getActivateToken());
mailService.sendActivationEmail(activateUrl, email);
} else {
throw new IoTPException("User is already active!", IoTPErrorCode.BAD_REQUEST_PARAMS);
}
} catch (Exception e) {
throw handleException(e);
}
}