【发布时间】:2015-05-20 21:29:30
【问题描述】:
initialBatchProcess 方法出错:必须捕获或声明要抛出未报告的异常。我有一个带有@webFault 注释的自定义异常类来处理这个link 中建议的jaxb 异常。
我的 initiateBatchProcess() 方法已经在扩展自定义异常类,但仍然显示错误
@WebService(serviceName = "WT_WebService")
public class WT
{
ResponseInfo result = new ResponseInfo();
@WebMethod(operationName = "initiateBatchProcess")
public @WebResult(name = "Response") ArrayList initiateBatchProcess(@WebParam (name = "BatchID")int BatchId, @WebParam (name = "MPTRef")String MPTRef) throws MyServiceException
{
return result.initiateBatchProcess();
}
自定义异常类:
@WebFault(name="MyServiceException", faultBean = "com.ws.MyServiceFault", targetNamespace="http://wataniya.com/")
public class MyServiceException extends Exception {
private static final long serialVersionUID = 1L;
private MyServiceFault faultBean;
public MyServiceException() {
super();
}
public MyServiceException(String message, MyServiceFault faultBean, Throwable cause) {
super(message, cause);
this.faultBean = faultBean;
}
public MyServiceException(String message, MyServiceFault faultBean) {
super(message);
this.faultBean = faultBean;
}
public MyServiceFault getFaultInfo() {
return faultBean;
}
}
FaultBean 类:
public class MyServiceFault {
/**
* Fault Code
*/
private String faultCode;
/**
* Fault String
*/
private String faultString;
/**
* @return the faultCode
*/
public String getFaultCode() {
return faultCode;
}
/**
* @param faultCode the faultCode to set
*/
public void setFaultCode(String faultCode) {
this.faultCode = faultCode;
}
/**
* @return the faultString
*/
public String getFaultString() {
return faultString;
}
/**
* @param faultString the faultString to set
*/
public void setFaultString(String faultString) {
this.faultString = faultString;
}
}
ResponseInfo 类:
public class ResponseInfo
{
static Properties props = new Properties();
public ArrayList initiateBatchProcess() throws Exception
{
ArrayList list = new ArrayList();
props.load(ResponseInfo.class.getResourceAsStream("ResponseFields.properties"));
String method1_status = props.getProperty("method1_status");
String method1_comments = props.getProperty("method1_comments");
list.add(method1_status);
list.add(method1_comments);
return list;
}
}
【问题讨论】:
-
ResponseInfo.initiateBatchProcess() 方法呢,除了 MyServiceException 之外,它会抛出任何其他异常吗?
-
它只抛出未报告的异常
-
能否提供 ResponseInfo 类的来源,因为到目前为止我没有看到代码有任何问题?
-
@SergeyPauk 更新了问题
标签: java web-services jaxb