我试图在我的SOAP Web服务中调用一个方法,并且我的方法会抛出异常类中定义的一些自定义异常。 我无异常地启动它时,我的Web服务正常工作,但是当我添加时 我的异常并且我尝试运行我的应用程序,显示错误:"模块尚未部署。 有关详细信息,请参阅服务器日志。" 我试图解决我的问题,但我无法在Web服务中找到如何调用抛出异常的方法。 你能帮帮我吗?
这是我的Web服务代码:
package WebService;
import CMS.CMS_CardStatusException;
import CMS.CMS_Exception;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
/**
*
* @author User
*/
@WebService(targetNamespace = "http://WebService/")
public class NEC_WS {
/**
* Web service operation
*/
@WebMethod(operationName = "ChangeCardStatus")
public int changeCardStatus(@WebParam(name = "ApplicationId") int applicationId, @WebParam(name = "CardNumber") String cardNumber, @WebParam(name = "CardStatusId") int cardStatusId) throws CMS_Exception, CMS_CardStatusException {
CMS.Controller c = new CMS.Controller();
int res = c.ChangeCardStatus(cardNumber, applicationId, cardStatusId);
return res;
}
这是我在网络服务中调用的函数,如帖子所示:
public int ChangeCardStatus(String CardNumber, int ApplicationId, int cardStatusId) throws CMS_Exception, CMS_CardStatusException {
int result = 0;
int res = 0;
configFileURL = HibernateUtil.class.getResource("/hibernate.cfg.xml");
Configuration config2 = (new Configuration()).configure(configFileURL);
factory2 = config2.
addAnnotatedClass(GRM.ApplicationCardStatuses.class).
addAnnotatedClass(GRM.CardStatus.class).buildSessionFactory();
Session session2 = factory2.openSession();
Transaction tx2 = null;
try {
tx2 = session2.beginTransaction();
GRM.CardStatus cardState = new GRM.CardStatus();
GRM.CardStatus newCardState = new GRM.CardStatus(cardStatusId);
Query query1 = session2.createQuery("From GRM.ApplicationCardStatuses st where st.applicationId= ?");
query1.setParameter(0, ApplicationId);
if (query1.list().isEmpty() == true) {
throw new CMS_Exception("ApplicationId does not exist in the DataBase!");
} else {
List<GRM.ApplicationCardStatuses> cartesGRM = query1.list();
for (GRM.ApplicationCardStatuses carteGRM : cartesGRM) {
cardState = carteGRM.getCardStatus();
int PreviousStatusId = cardState.getCardStatusId();
res = CardStatusCompatibility(cardStatusId, PreviousStatusId);
if (res != 0) {
throw new CMS_CardStatusException(cardStatusId, PreviousStatusId, res);
} else {
carteGRM.setStatusDate(new Date());
carteGRM.setCardStatus(newCardState);
}
}
tx2.commit();
result = 0;
}
} catch (HibernateException e) {
if (tx2 != null) {
tx2.rollback();
}
e.printStackTrace();
result = 1;
} catch (CMS_Exception ex) {
System.out.println("Exception generated : " + ex.getMessage());
result = 1;
} catch (CMS_CardStatusException e) {
e.printStackTrace();
result = 1;
} finally {
session2.close();
}
return result;
}
这是我的异常类:
package CMS;
import javax.xml.ws.WebFault;
@WebFault(name="WebServiceCMS_Exception",
targetNamespace="http://WebService/")
public class CMS_Exception extends Exception {
private CMS_Exception faultInfo;
public CMS_Exception (){
// System.out.print("ApplicationId does not exist in the DataBase!");
}
public CMS_Exception( String msg) {
super(msg);
}
public CMS_Exception getFaultInfo() {
return faultInfo;
}
}