我目前正在開發基於EJB3的SOAP webservice,我想知道什麼是處理未捕獲的異常並向客戶端返回格式良好的SOAP響應的最佳實踐。如何處理基於ejb 3的soap web服務中的異常
例如:
@WebMethod
public SomeResponse processSomeService(
@WebParam(name = "someParameters") SomeParameters someParameters)
{
// the EJB do something with the parameters
// and retrieve a response fot the client
SomeResponse theResponse = this.doSomething(someParameters);
return theResponse;
}
我必須趕上通用的異常,如:
@WebMethod
public SomeResponse processSomeService(
@WebParam(name = "someParameters") SomeParameters someParameters)
{
// the EJB do something with the parameters
// and retrieve a response to return to the client
try
{
SomeResponse theResponse = this.doSomething(someParameters);
}
catch (Exception ex)
{
// log the exception
logger.log(Level.SEVERE, "something is going wrong {0}", ex.getMessage());
// get a generic error response not to let the
// technical reason going to the client
SomeResponse theResponse = SomeResponse.createError();
}
return theResponse;
}
是否有爲了實現這個某種「最佳實踐」的?
謝謝
不幸的是,似乎某些異常沒有被ejb-container捕獲,並且通過SOAP響應返回給客戶端 – 2011-01-31 10:52:06
@Alexandre:當然可以。這就是容器應該做的事情,將運行時異常作爲SOAPFault返回。 – 2011-01-31 18:13:33