最近在用java 做基于xfire的webservice 来做两个数据同步,在A端从数据库读取到一个list然后序列化为byte数组,传递给B端,结果B端收到的byte数据长度和A端的发出的数据长度不一致导致不能反序列化,有没有遇到类似问题的,求解决啊! |
|
20分 |
这不应该吧?传输过程是否丢包了?网络连接是否稳定?
|
网络是局域网,传输过程不知道是否丢包,对方收到时会报java.io.EOFException… |
|
20分 |
文件结束异常,还没收完全
|
知道是没有收完,可是为什么会出现没有收完的情况呢?有没有什么解决办法? |
|
60分 |
抛异常了肯定就出错了啊。去看抛异常的代码 |
等下,再出异常了我把异常贴出来,顺便把部分代码页贴出来 |
|
public static byte[] writeList2ByteArray(List objList) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(baos); oos.writeObject(objList); return baos.toByteArray(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { oos.close(); baos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } public static List readFromByte(byte[] b) { ByteArrayInputStream bais = new ByteArrayInputStream(b); ObjectInputStream ois = null; try { ois = new ObjectInputStream(bais); Serializable obj = (Serializable) ois.readObject(); if (obj instanceof List) { return (List) obj; } } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { try { ois.close(); bais.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } public OptionResult doPost(String tablename,String seqname,int localseq,int lastsyncseq,byte[] b,List<TableInfo> tlist) { logger.info("\n\n\n%%%%%% tablename " + tablename+" ,receive byte :" + (b == null?0 : b.length) + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n"); OptionResult result = new OptionResult(); try{ if(b == null || b.length == 0){ result.setSuccess(true); result.setMsg("无数据,忽略"); return result; } logger.info("对象机:" + DbSyncConfig.TARGET_MACHINE_WEB_SERVICE_URL); logger.info("开始同步doPost:tablename="+ tablename +",lastsyncseq="+lastsyncseq + ",localseq="+localseq); com.cimc.imeeting.webservice.syn.client.DbSyncronizer service = new com.cimc.imeeting.webservice.syn.client.DbSyncronizer(); com.cimc.imeeting.webservice.syn.client.DbSyncronizerPortType portType = service.getDbSyncronizerHttpPort(); com.cimc.imeeting.webservice.syn.client.OptionResult or = portType.doWrite(tablename,seqname, localseq, lastsyncseq,b); if(or.isSuccess()){ for(TableInfo ti : tlist){ if(tablename.equals(ti.getTablename())){ ti.setLastsyncseqwrite(localseq); } } XmlUtilSync.getInstance().saveXml(tlist); logger.info("本次同步结果保存到本地文件OKAY:tablename="+ tablename +",lastsyncseq="+lastsyncseq + ",localseq="+localseq); } else{ logger.info("对象机操作失败,失败原因是:" + or.getMsg()); } result.setSuccess(true); }catch (WebServiceException e) { result.setMsg(e.getMessage()); result.setSuccess(false); sendSMS(DbSyncConfig.SMS_NOTICE_CELLPHONE , DbSyncConfig.SMS_NOTICE_CONTENT_WEBSERVICE_CONNECTION_EXCEPTION + new Date().toString() + e.getMessage()); logger.error("WebServiceException :" + e.getMessage()); }catch(Exception ex){ result.setMsg(ex.getMessage()); result.setSuccess(false); } return result; } public OptionResult doWrite(String tablename, String seqname, int localseq, int lastsyncseq, byte[] b) { OptionResult result = new OptionResult(); try{ //FIXME check the data before write. DBUtil util = new DBUtil(); int lastId = util.writeToLocal(tablename, b); result.setSuccess(true); result.setMsg(lastId + ""); }catch(Exception ex){ result.setMsg(ex.getMessage()); result.setSuccess(false); } return result; } 上面是序列化和反序列化,还有调用的代码,异常就出在反序列化中抛出的! |
|
java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281) at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3019) at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:2820) at java.io.ObjectInputStream.readUTF(ObjectInputStream.java:1051) at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:616) at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:809) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1565) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at java.util.ArrayList.readObject(ArrayList.java:593) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at com.cimc.imeeting.webservice.syn.DBUtil.readFromByte(DBUtil.java:329) at com.cimc.imeeting.webservice.syn.DBUtil.writeToLocal(DBUtil.java:370) at com.cimc.imeeting.webservice.syn.DbSyncronizerImpl.doWrite(DbSyncronizerImpl.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:59) at org.codehaus.xfire.service.invoker.ObjectInvoker.invoke(ObjectInvoker.java:45) at org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(ServiceInvocationHandler.java:320) at org.codehaus.xfire.service.binding.ServiceInvocationHandler$1.run(ServiceInvocationHandler.java:86) at org.codehaus.xfire.service.binding.ServiceInvocationHandler.execute(ServiceInvocationHandler.java:134) at org.codehaus.xfire.service.binding.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:109) at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131) at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64) at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38) at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304) at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129) at org.codehaus.xfire.transport.http.XFireServlet.doPost(XFireServlet.java:116) at javax.servlet.http.HttpServlet.service(HttpServlet.java:643) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) |
|
我也遇到了同样的问题id,同求解答啊~
|