【问题标题】:What is the reason of java.lang.reflect.InvocationTargetException when calling a SOAP WS?调用 SOAP WS 时 java.lang.reflect.InvocationTargetException 的原因是什么?
【发布时间】:2015-04-01 13:30:38
【问题描述】:

我只是想了解 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.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:313) ... 32 更多原因: com.sun.xml.ws.fault.ServerSOAPFaultException:客户端收到来自服务器的 SOAP 错误:com.sun.enterprise.container.common.spi.util.InjectionException:为类创建托管对象时出错:类 com.hojat.LibrarySoapWS.ws .AuthorWS 请查看服务器日志以查找有关失败确切原因的更多详细信息。 com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193) 在 com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:131) 在 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) 在 com.sun.proxy.$Proxy312.getAllAuthors(Unknown Source)'

【问题讨论】:

  • 进一步查看堆栈跟踪,原因将在某处的“Caused By”中
  • 我已经添加了堆栈跟踪。但我想不通。请您看一下并给我提示吗?
  • 堆栈跟踪不可读,请格式化,使每一行都可见
  • 你现在可以阅读了。

标签: web-services soap


【解决方案1】:

问题出在服务器端,从堆栈跟踪中可以看出

: 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.

所以检查服务器日志。

【讨论】:

    猜你喜欢
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    相关资源
    最近更新 更多