谁能帮助我,我会崩溃,所以谢谢你 调用错误的客户端如下,错误: 调用错误的客户端如下,错误:
- Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
{http://xml.apache.org/axis/}hostname:geduo_pc
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2470)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hxc.soap.HxcNewsServiceSoap12BindingStub.find(HxcNewsServiceSoap12BindingStub.java:254)
at com.hxc.soap.Test.main(Test.java:11)
Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
... 4 more
服务器代码:(axis2 + hibernate + spring)
public class HxcNewsService implements IHxcNewsService {
private IDao dao;
public void setDao(IDao dao) {
this.dao = dao;
}
public HxcNews find(int id){
return (HxcNews) dao.find("com.ews.bean.HxcNews",id);
}
}
public class Dao<T> extends HibernateDaoSupport implements IDao<T> {
public T find(String str,int id) {
try {
T t = (T) getHibernateTemplate().get(str, id);
return t;
} catch (RuntimeException re) {
throw re;
}
}
客户代码:
public class Test {
public static void main(String[] args) {
try {
HxcNewsServicePortType hxcNewsServicePortType = new HxcNewsServiceLocator().getHxcNewsServiceHttpSoap12Endpoint();
HxcNews news = hxcNewsServicePortType.find(1);
System.out.println(news.getTitle());
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
我认为错误是由于find()
类的HcxNewsService
方法返回的xml输出所致。一些XML IS成功返回,并且它没有足够好地形成反序列化(从中构造一个对象)。
如堆栈跟踪中所述......
“encountered a child element, which is NOT expected, in something it was trying to deserialize
”(SAXParser不理解XML意味着xml未正确形成)。
可能的调试选项是尝试直接从DAO获取xml绑定对象...记录它......
public class Dao<T> extends HibernateDaoSupport implements IDao<T> {
public T find(String str,int id) {
try {
T t = (T) getHibernateTemplate().get(str, id);
System.out.println.t.toString()); // OR...
LOGGER.info(t.toString());
return t;
} cach (RuntimeException re) {
throw re;
}
}
}
如果失败,请在服务器中调用代码执行相同的方法...
public class HxcNewsService implements IHxcNewsService {
private IDao dao;
public void setDao(IDao dao) {
this.dao = dao;
}
public HxcNews find(int id){
// before returning, see what is database returning...
LOGGER.log(dao.find("com.ews.bean.HxcNews",id));
return (HxcNews) dao.find("com.ews.bean.HxcNews",id);
}
}
让我们知道你最终如何解决它。