调用SOAP WS时java.lang.reflect.InvocationTargetException的原因是什么?

时间:2015-04-01 13:30:39

标签: web-services soap

我只是想了解Soap WS。所以我只写下一些简单的类。但是当我在GlassFish中部署此应用程序并对其进行测试时,服务器将返回java.lang.reflect.InvocationTargetException。谁能说出问题是什么?

@WebService
public class AuthorWS {
AuthorService authorService = new AuthorService();

@WebMethod
public Author getAuthorById(int authorId) {
    return authorService.getAuthorById(authorId);
}

@WebMethod
public ArrayList<Author> getAllAuthors() {
    return authorService.getAllAuthors();
}
}

服务类:

public class AuthorService {
AuthorDAO authorDAO = new AuthorDAO();
public Author getAuthorById(int authorId){

    return authorDAO.getAuthorById(authorId);
}
public ArrayList<Author> getAllAuthors(){
    return authorDAO.getAllAuthors();
}
}

DAO班级:

public class AuthorDAO {

public Author getAuthorById(int authorId){
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Criteria criteria = sessionFactory.openSession().createCriteria(Author.class);
    criteria.add(Restrictions.eq("authorId", authorId));
    return (Author) criteria.uniqueResult();

}
public ArrayList<Author> getAllAuthors(){
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Criteria criteria = sessionFactory.openSession().createCriteria(Author.class);
    return (ArrayList<Author>) criteria.list();
}

例外:

'由sun.reflect.DelegatingMethodAccessorImpl.invoke上的sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)处的sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)引起的java.lang.reflect.InvocationTargetException: DelegatingMethodAccessorImpl.java:43)在org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:313)的java.lang.reflect.Method.invoke(Method.java:483)中... 32更多引起: com.sun.xml.ws.fault.ServerSOAPFaultException:客户端从服务器收到SOAP Fault:com.sun.enterprise.container.common.spi.util.InjectionException:为类创建托管对象时出错:class com.hojat.LibrarySoapWS.ws .AuthorWS请参阅服务器日志以查找有关故障原因的更多详细信息。 at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:131)at com.sun.xml.ws .client.sei.StubHandler.readResponse(StubHandler.java:253)位于com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:203)的com.sun.xml.ws.db.DatabindingImpl.deserializeResponse (DatabindingImpl.java:290)位于com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)的com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java) :92)com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)at com.sun.proxy。$ Proxy312.getAllAuthors(Unknown Source)'

1 个答案:

答案 0 :(得分:0)

问题出在服务器端,正如您可以从堆栈跟踪中看到的那样

: Client received SOAP Fault from server:
 com.sun.enterprise.container.common.spi.util.InjectionException: 
Error creating managed object for class: 
class com.hojat.LibrarySoapWS.ws.AuthorWS 
Please see the server log to find more detail regarding exact cause of the failure.

请检查服务器日志。