2017-08-07 93 views
0

我在運行tomcat 8.5.6。當我的澤西休息服務返回400或409(我調試到代碼來驗證發生這種情況)Tomcat正在返回一個404響應(在Tomcat本地主機訪問日誌和瀏覽器中驗證)。tomcat 8爲所有400級響應返回404

當我在相同的情況下將相同的服務更改爲500時,將返回到瀏覽器。

想到Tomcat爲什麼要吸收所有400級響應並將其轉換爲404以及如何讓Tomcat返回所需的響應代碼?謝謝。

+0

不太確定這是一個SO問題。 –

回答

0

想通了。我在響應中添加了一些主體內容,並且正確的代碼開始流回客戶端。

} catch (UserAlreadyExistsException e) { 
     LOG.error(e, "user already exists"); 
     response = Response.status(Response.Status.CONFLICT).entity("user already exists").build(); 
    } catch (JSONException e) { 
     LOG.error(e, "bad request"); 
     response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); 
    } catch (Exception e) { 
     LOG.error(e, "server error"); 
     response = Response.serverError().entity(e.getMessage()).build(); 
    } 

    return response; 
0

Tomcat的新版本中做出更多更嚴格的驗證在HTTP頭中,您可以在你的頭PARAM多加一個「主機」或缺少「主機」。我有同樣的問題,我刪除重複