1

通過單視圖應用程序vaadin 7.7.7,spring-boot 1.5我從用戶檢查uri片段https:/ tld /#!category-name-1,如果類別存在秀項,如果沒有vaadin + spring boot:無法轉發到錯誤頁面請求

VaadinService.getCurrentResponse().sendError(404, "page not found!"); 

但我得到了錯誤的更新春天啓動1.5和7.7.7 vaadin(與嵌入式的tomcat)後:

Cannot forward to error page for request [/vaadinServlet/UIDL/] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false 

我怎麼能發送從vaadin HTTP錯誤頁面給用戶?

ErrorPageCutomizer.java

@Component 
public class ErrorPageCutomizer implements EmbeddedServletContainerCustomizer { 
    @Override 
    public void customize(ConfigurableEmbeddedServletContainer container) { 
     container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404")); 
     container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")); 
    } 
} 

RestController.java

import org.springframework.boot.autoconfigure.web.ErrorController; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class ErrorHandlingController implements ErrorController { 

    private static final String PATH = "/error"; 

    @RequestMapping(value = PATH + "/404") 
    public String error404() { 
     return "<div style='font-weight:bold; margin-top:200px; text-align:center; font-size:160%;'>Page not found...<br><a href=\"https://tld\">to home</a></div>"; 
    } 

    @RequestMapping(value = PATH + "/500") 
    public String error500() { 
     return "<div style='font-weight:bold; margin-top:200px; text-align:center; font-size:160%;'>500 Internal server error...</div>"; 
    } 

    @Override 
    public String getErrorPath() { 
     return PATH; 
    } 
} 

回答

0

Soliution是:

@Configuration 
public class AppInitializer implements WebApplicationInitializer { 

    @Bean 
    public ErrorPageFilter errorPageFilter() { 
     return new ErrorPageFilter(); 
    } 

    @Bean 
    public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) { 
     FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); 
     filterRegistrationBean.setFilter(filter); 
     filterRegistrationBean.setEnabled(false); 
     return filterRegistrationBean; 
    } 
} 
+1

它不適用於Vaadin 8.0.5和Spring引導1.5.3 –

-1

您是否嘗試過SystemMessagesProvider。在該提供者可以定義一個用於errorUrl各種錯誤:

public class YourServlet extends VaadinServlet 
{ 
    @Override 
    protected void servletInitialized() throws ServletException 
    { 
     super.servletInitialized(); 

     getService().setSystemMessagesProvider(new SystemMessagesProvider() 
     { 
      @Override 
      public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) 
      { 
       final CustomizedSystemMessages c = new CustomizedSystemMessages(); 
       final String errorUrl = "<url to errorpage>"; 
       c.setSessionExpiredURL(errorUrl); 
       c.setSessionExpiredNotificationEnabled(false); 

       c.setAuthenticationErrorURL(errorUrl); 
       c.setAuthenticationErrorNotificationEnabled(false); 

       c.setCommunicationErrorURL(errorUrl); 
       c.setCommunicationErrorNotificationEnabled(false); 

       c.setCookiesDisabledURL(errorUrl); 
       c.setCookiesDisabledNotificationEnabled(false); 

       c.setInternalErrorURL(errorUrl); 
       c.setInternalErrorNotificationEnabled(false); 

       c.setSessionExpiredURL(errorUrl); 
       c.setSessionExpiredNotificationEnabled(false); 
       return c; 
      } 
     }); 
    } 
+0

的問題是「我怎樣才能發送HTTP錯誤頁面從vaadin用戶?」。不是'我怎樣才能用Spring發送錯誤頁面'。我的建議就是這個。我希望能解釋爲什麼我的答案被降級。 –

+0

如果我發送:VaadinService.getCurrentResponse()。sendError(404,「page not found!」); 控制檯上出現以下錯誤: 「無法轉發到錯誤頁面請求[/],因爲響應已被提交,因此響應中可能有錯誤的狀態碼如果您的應用程序在WebSphere Application Server上運行,可以通過將com.ibm.ws.webcontainer.invokeFlushAfterService設置爲false來解決此問題「 定製sys msg不是我的意思 –

相關問題