Reputation: 7018
Error at method initiateBatchProcess : unreported exception must be caught or declared to be thrown. I have a custom exception class with @webFault annotation to handle jaxb exception as suggested in this link.
My initiateBatchProcess()
method is already extending custom exception class but still its showing error
@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();
}
Custom Exception class:
@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 class:
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 Class:
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;
}
}
Upvotes: 0
Views: 408
Reputation: 5318
ResponseInfo.initiateBatchProcess()
declares to throw a checked exception Exception
but it's not handled in WT.initiateBatchProcess()
.
Your have either to declare WT.initiateBatchProcess()
to throw Exception
or catch Exception
and rethrow it as MyServiceException
(that could be done either in ResponseInfo or in WT class).
EDIT: second option implementation would look like this:
@WebMethod(operationName = "initiateBatchProcess")
public @WebResult(name = "Response") ArrayList initiateBatchProcess(@WebParam (name = "BatchID")int BatchId, @WebParam (name = "MPTRef")String MPTRef) throws MyServiceException
{
ArrayList returnValue = null;
try {
returnValue = result.initiateBatchProcess();
} catch (Exception e) {
throw new MyServiceException(e);
}
return returnValue;
}
I've added a MyServiceException(Exception e)
constructor for simplicity but you could modify the code according to your needs.
Upvotes: 1