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