在我的春季项目中,我收到通知后会收到通知服务的通知,如何在浏览器中显示通知数据。 这是我的代码。
@RequestMapping(value = "/notify/userregister", method = RequestMethod.POST)
public ResponseEntity<String> registerNotification(@RequestBody @Valid RegistrationInfo registrationInfo) throws IOException {
if(registrationInfo != null && registrationInfo.getregistrationInfo()!= null && registrationInfo.getregistrationInfo.size() > 0 ){
for(int i=0;i<registrationInfo.getregistrationInfo.size();i++ ){
logger.info("registration notification data:"+registrationInfo.getregistrationInfo().get(i).getUserAccessId()+registrationInfo.getregistrationInfo().get(i).getRegistrationTime));
}
return new ResponseEntity<String>(HttpStatus.OK);
}
else{
return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
}
}
当我的服务器运行时,注册服务发送通知数据。我能够在日志文件中查看数据,并使用200个代码确认注册服务。我想在浏览器中显示通知数据(例如:registrationInfo.getregistrationInfo()。get(i).getUserAccessId())。目前显示“Whitelabel错误页面此应用程序没有显示/错误的显式映射,因此您将此视为回退。这是一个意外错误....”。如何在我的浏览器上摆脱此错误消息?
答案 0 :(得分:0)
https://gist.github.com/jonikarppinen/662c38fb57a23de61c8b
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* Based on the helpful answer at http://stackoverflow.com/q/25356781/56285,
* with error details in response body added.
*
* @author Joni Karppinen
* @since 20.2.2015
*/
@RestController
public class CustomErrorController implements ErrorController {
private static final String PATH = "/error";
@Value("${debug}")
private boolean debug;
@Autowired
private ErrorAttributes errorAttributes;
@RequestMapping(value = PATH)
ErrorJson error(HttpServletRequest request, HttpServletResponse response) {
// Appropriate HTTP response code (e.g. 404 or 500) is automatically set by Spring.
// Here we just define response body.
return new ErrorJson(response.getStatus(), getErrorAttributes(request, debug));
}
@Override
public String getErrorPath() {
return PATH;
}
private Map<String, Object> getErrorAttributes(HttpServletRequest request, boolean includeStackTrace) {
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
}
}