服务端的 EJB 代码如下:
@WebService(name = "TravelAgent", serviceName = "TravelAgentService")
@Stateless
public class TravelAgentBean implements TravelAgentRemote {
......
@WebMethod
@WebResult(name = "List")
public List test(@WebParam(name = "name") String name)
{
System.out.println("name : ");System.out.println(name);
Query query = manager.createQuery("from Cabin c");
List list = query.getResultList();
return list;
}
......
}
客户端的 PHP 代码如下:
$client = new SoapClient($wsdl_url);
$username = $client->test(array('name'=>'asdfhasldfjl'));
var_dump($username);
如果服务端是 @Stateless . 使用 Java 客户端调用是没有问题的,
服务端是 @WebService 时, 使用 new ArrayList 实现返回也是没有问题. 唯有 query.getResultList(); 返回时, 出现 WebServiceException 异常.
那位高手有空, 请指点下小弟. 小弟是新手. 3 个月前刚买了几本 java 的书看看.
QQ : 280016524
Email : degui.chen@qq.com
如下是服务器端抛出的异常:
22:44:45,127 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.3.GA/server/defau
lt/deploy/WebServicesDemo.jar/
22:44:45,228 INFO [DefaultEndpointRegistry] register: jboss.ws:context=WebServi
cesDemo,endpoint=TravelAgentBean
22:44:51,086 INFO [WSDLFilePublisher] WSDL published to: file:/C:/jboss-4.2.3.G
A/server/default/data/wsdl/WebServicesDemo.jar/TravelAgentService55191.wsdl
22:44:51,396 INFO [TomcatDeployer] deploy, ctxPath=/WebServicesDemo, warUrl=...
/tmp/deploy/WebServicesDemo.jar55190.war/
22:44:53,570 INFO [STDOUT] name :
22:44:53,570 INFO [STDOUT] asdfhasldfjl
22:44:54,691 INFO [STDOUT] list :
22:44:54,691 INFO [STDOUT] [chen.degui.domain.Cabin@1681460]
22:44:54,711 ERROR [RequestHandlerImpl] Error processing web service request
org.jboss.ws.WSException: javax.xml.ws.WebServiceException: javax.xml.bind.Marsh
alException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at org.jboss.ws.WSException.rethrow(WSException.java:68)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:325)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl
.java:201)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(Request
HandlerImpl.java:134)
at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java
:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
onnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
6)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at org.jboss.ws.core.jaxws.JAXBSerializer.handleMarshallException(JAXBSe
rializer.java:124)
at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:
87)
at org.jboss.ws.core.binding.SerializerSupport.serialize(SerializerSuppo
rt.java:57)
at org.jboss.ws.core.soap.ObjectContent.marshallObjectContents(ObjectCon
tent.java:159)
at org.jboss.ws.core.soap.ObjectContent.transitionTo(ObjectContent.java:
72)
at org.jboss.ws.core.soap.SOAPContentElement.transitionTo(SOAPContentEle
ment.java:141)
at org.jboss.ws.core.soap.SOAPBodyElementDoc.transitionTo(SOAPBodyElemen
tDoc.java:85)
at org.jboss.ws.core.soap.SOAPContentElement.writeElement(SOAPContentEle
ment.java:547)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElementInternal(SOAPEle
mentWriter.java:149)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElement(SOAPElementWrit
er.java:130)
at org.jboss.ws.core.soap.SOAPMessageImpl.writeTo(SOAPMessageImpl.java:3
25)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.sendResponse(RequestHandl
erImpl.java:392)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:321)
... 22 more
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:
320)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.jav
a:246)
at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:
81)
... 37 more
Caused by: javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any o
f its super class is known to this context.
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.j
ava:240)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.j
ava:255)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
r.java:647)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.seriali
zeItem(ArrayElementNodeProperty.java:65)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeLi
stBody(ArrayElementProperty.java:168)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Ar
rayERProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBean
InfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
r.java:679)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
ntBeanInfoImpl.java:151)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
ntBeanInfoImpl.java:185)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(Element
BeanInfoImpl.java:305)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
BeanInfoImpl.java:312)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
BeanInfoImpl.java:71)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.j
ava:488)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:
317)
... 39 more
Caused by: javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any o
f its super class is known to this context.
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextIm
pl.java:556)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
r.java:642)
... 51 more
22:44:54,861 ERROR [[TravelAgentBean]] Servlet.service() for servlet TravelAgent
Bean threw exception
javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its super
class is known to this context.
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextIm
pl.java:556)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
r.java:642)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.seriali
zeItem(ArrayElementNodeProperty.java:65)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeLi
stBody(ArrayElementProperty.java:168)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Ar
rayERProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBean
InfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerialize
r.java:679)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
ntBeanInfoImpl.java:151)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Eleme
ntBeanInfoImpl.java:185)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(Element
BeanInfoImpl.java:305)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
BeanInfoImpl.java:312)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Element
BeanInfoImpl.java:71)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.j
ava:488)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:
317)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.jav
a:246)
at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:
81)
at org.jboss.ws.core.binding.SerializerSupport.serialize(SerializerSuppo
rt.java:57)
at org.jboss.ws.core.soap.ObjectContent.marshallObjectContents(ObjectCon
tent.java:159)
at org.jboss.ws.core.soap.ObjectContent.transitionTo(ObjectContent.java:
72)
at org.jboss.ws.core.soap.SOAPContentElement.transitionTo(SOAPContentEle
ment.java:141)
at org.jboss.ws.core.soap.SOAPBodyElementDoc.transitionTo(SOAPBodyElemen
tDoc.java:85)
at org.jboss.ws.core.soap.SOAPContentElement.writeElement(SOAPContentEle
ment.java:547)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElementInternal(SOAPEle
mentWriter.java:149)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElement(SOAPElementWrit
er.java:130)
at org.jboss.ws.core.soap.SOAPMessageImpl.writeTo(SOAPMessageImpl.java:3
25)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.sendResponse(RequestHandl
erImpl.java:392)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:321)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl
.java:201)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(Request
HandlerImpl.java:134)
at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java
:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
onnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
6)
at java.lang.Thread.run(Thread.java:619)
问题补充
多谢 Anatorian 的建议. :
下面是我添加的修改后的结果:
@Entity
@XmlRootElement
public class Cabin implements java.io.Serializable {
private int id;
private String name;
private int deckLevel;
private int shipId;
private int bedCount;@Id @Column(name = "CABIN_ID") public int getId() { ...............
异常为:
23:59:14,985 INFO [WSDLFilePublisher] WSDL published to: file:/C:/jboss-4.2.3.G
A/server/default/data/wsdl/WebServicesDemo.jar/TravelAgentService64072.wsdl
23:59:15,496 INFO [TomcatDeployer] deploy, ctxPath=/WebServicesDemo, warUrl=...
/tmp/deploy/WebServicesDemo.jar64071.war/
23:59:43,506 INFO [STDOUT] name :
23:59:43,506 INFO [STDOUT] asdfhasldfjl
23:59:45,689 INFO [STDOUT] list :
23:59:45,689 INFO [STDOUT] [chen.degui.domain.Cabin@175beef]
23:59:45,729 ERROR [RequestHandlerImpl] Error processing web service request
org.jboss.ws.WSException: javax.xml.ws.WebServiceException: javax.xml.bind.Marsh
alException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at org.jboss.ws.WSException.rethrow(WSException.java:68)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:325)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl
.java:201)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(Request
HandlerImpl.java:134)
at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java
:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
onnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
6)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at org.jboss.ws.core.jaxws.JAXBSerializer.handleMarshallException(JAXBSe
rializer.java:124)
at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:
87)
at org.jboss.ws.core.binding.SerializerSupport.serialize(SerializerSuppo
rt.java:57)
at org.jboss.ws.core.soap.ObjectContent.marshallObjectContents(ObjectCon
tent.java:159)
at org.jboss.ws.core.soap.ObjectContent.transitionTo(ObjectContent.java:
72)
at org.jboss.ws.core.soap.SOAPContentElement.transitionTo(SOAPContentEle
ment.java:141)
at org.jboss.ws.core.soap.SOAPBodyElementDoc.transitionTo(SOAPBodyElemen
tDoc.java:85)
at org.jboss.ws.core.soap.SOAPContentElement.writeElement(SOAPContentEle
ment.java:547)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElemen
tImpl.java:840)
at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.j
ava:825)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElementInternal(SOAPEle
mentWriter.java:149)
at org.jboss.ws.core.soap.SOAPElementWriter.writeElement(SOAPElementWrit
er.java:130)
at org.jboss.ws.core.soap.SOAPMessageImpl.writeTo(SOAPMessageImpl.java:3
25)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.sendResponse(RequestHandl
erImpl.java:392)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHand
lerImpl.java:321)
... 22 more
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class chen.degui.domain.Cabin nor any of its supe
r class is known to this context.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:
320)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.jav
a:246)
at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:
81)
问题补充
没有高手有空?