Web 服务错误:在此上下文中,类 xxx 及其任何超类均未知
我们有一个托管在Web Sphere 7.0.0.19 服务器上的JAX-WS 服务。该服务是使用@WebService注释实现的。如果我们点击服务来请求 WSDL,我们就会成功地将 XML 返回给我们。但是,如果我们调用 Web 服务方法,它会返回以下错误:
javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class com.penske.newreuse.vo.ApplicationConfigVO nor any of its super class is known to this context.]
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
查看我们的日志记录,我们的代码已成功调用,并且返回了预期的数据。然而,当数据被编组以发送回客户端时,就会发生故障。
ApplicationConfigVO 类位于单独的 jar 文件中,我们尝试将其取出并将源直接包含在服务中,没有任何更改。
我将 @XmlSeeAlso(ApplicationConfigVO.class) 添加到 ApplicationConfigVO 对象,但仍然没有任何变化。
这是 Web 服务代码:
@WebService(serviceName="WebServiceConfigService")
public class WebServiceConfig {
private static Logger log = Logger.getLogger(WebServiceConfig.class);
public ApplicationConfigVO[] loadWsControlMode(int applicationId,String appsId) throws Exception {
log.info("loadWsControlMode WebService Invoked Application ID :"+ appsId);
List returnList = null;
ApplicationConfigVO[] resultArray = null;
try {
ApplicationConfigVO modelObj = new ApplicationConfigVO();
modelObj.setApplicationId(applicationId);
IApplicationConfigDAO daoObj = DAOFactory.getApplicationConfigDAO();
returnList = daoObj.loadWsControlMode(modelObj);
if(null != returnList && returnList.size()>0){
resultArray = new ApplicationConfigVO[returnList.size()];
//Populate the ApplicationConfigVO array from arraylist
modelObj = new ApplicationConfigVO();
for(int i=0;i<returnList.size();i++){
modelObj = (ApplicationConfigVO)returnList.get(i);
resultArray[i] = modelObj;
}//End of for loop
}
} catch (Exception e) {
log.error(DAWebServiceUtil.stackTraceToString(e));
throw e;
}
return resultArray;
}
这是 ApplicationConfigVO 类:
public class ApplicationConfigVO implements Serializable{
private int applicationId;
private String webServiceControlMode = null;
private int webServiceId;
private String webServiceName = null;
private int webServiceMethodId;
private int opModeId;
private String webServiceMethodDesc = null;
private int dataBaseTypeId;
private String dataBaseTypeDesc = null;
... // various getters and setters following java bean rules
}
We have a JAX-WS service hosted on a Web Sphere 7.0.0.19 server. The service is implemented using @WebService annotations. If we hit the service to ask for the WSDL, we successfully have the XML returned to us. However, if we call a web service method, it returns the following error:
javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class com.penske.newreuse.vo.ApplicationConfigVO nor any of its super class is known to this context.]
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
Looking at our logging, our code is successfully called, and we return the data expected. However, it is when the data is being marshalled to be sent back to the client that the fault occurs.
The ApplicationConfigVO class was in a separate jar file, we tried and pulled it out and included the source directly with the service, no change.
I added @XmlSeeAlso(ApplicationConfigVO.class) to the ApplicationConfigVO object, but still no change.
This is the web service code:
@WebService(serviceName="WebServiceConfigService")
public class WebServiceConfig {
private static Logger log = Logger.getLogger(WebServiceConfig.class);
public ApplicationConfigVO[] loadWsControlMode(int applicationId,String appsId) throws Exception {
log.info("loadWsControlMode WebService Invoked Application ID :"+ appsId);
List returnList = null;
ApplicationConfigVO[] resultArray = null;
try {
ApplicationConfigVO modelObj = new ApplicationConfigVO();
modelObj.setApplicationId(applicationId);
IApplicationConfigDAO daoObj = DAOFactory.getApplicationConfigDAO();
returnList = daoObj.loadWsControlMode(modelObj);
if(null != returnList && returnList.size()>0){
resultArray = new ApplicationConfigVO[returnList.size()];
//Populate the ApplicationConfigVO array from arraylist
modelObj = new ApplicationConfigVO();
for(int i=0;i<returnList.size();i++){
modelObj = (ApplicationConfigVO)returnList.get(i);
resultArray[i] = modelObj;
}//End of for loop
}
} catch (Exception e) {
log.error(DAWebServiceUtil.stackTraceToString(e));
throw e;
}
return resultArray;
}
This is the ApplicationConfigVO class:
public class ApplicationConfigVO implements Serializable{
private int applicationId;
private String webServiceControlMode = null;
private int webServiceId;
private String webServiceName = null;
private int webServiceMethodId;
private int opModeId;
private String webServiceMethodDesc = null;
private int dataBaseTypeId;
private String dataBaseTypeDesc = null;
... // various getters and setters following java bean rules
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我尝试了很多方法都无济于事。所以我赌了,我修改了方法以返回一个List而不是ApplicationConfigVO[]。此时我认为这是一个类加载器问题,但我不能确定。无论哪种情况,切换到列表最终都会更容易,希望没有其他事情会困扰我们
Well I tried any number of things to no avail. So I punted, I modified the method to return a List instead of the ApplicationConfigVO[]. At this point I think it is a classloader issue, but I cannot be sure. In either case, the switch over to a list was ultimately easier and hopefully nothing else will bite us