0

我正在尝试从 oracle db 中检索 blob 对象。blob 对象表示存储在 oracle db 中的 word 文档。

我检索 blob 并使用 utf8 编码转换为 java 字节,然后传递给一个安静的 web 服务。Restful webservice 接收 blob 对象并作为 json 传递给另一个客户端。此时我得到以下异常。任何人都可以帮忙解决这个问题吗?

org.omg.CORBA.DATA_CONVERSION: WARNING: IOP02410006: Invalid unicode pair detected during code set conversion  vmcid: OMG  minor code: 6  completed: No
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)at java.lang.reflect.Constructor.newInstance(Constructor.java:513)at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)  at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387) at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
    at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99) at $Proxy200.badUnicodePair(Unknown Source) at com.sun.corba.ee.impl.encoding.CodeSetConversion$JavaCTBConverter.convertCharArray(CodeSetConversion.java:335)   at com.sun.corba.ee.impl.encoding.CodeSetConversion$JavaCTBConverter.convert(CodeSetConversion.java:250)    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_2.write_wstring(CDROutputStream_1_2.java:470)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.writeWStringValue(CDROutputStream_1_0.java:737)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:956)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:976)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:706)
    at tputStream_1_0.write_value(CDROutputStream_1_0.java:962)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:976)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:196)
    at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.write(DynamicMethodMarshallerImpl.java:394)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:200)
    at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:227)
    at gov.ca.lc.refdata.__VotesRefDataBeanRemote_Remote_DynamicStub.getBillAnalysis(gov/ca/lc/refdata/__VotesRefDataBeanRemote_Remote_DynamicStub.java)
    at gov.ca.lc.refdata._VotesRefDataBeanRemote_Wrapper.getBillAnalysis(gov/ca/lc/refdata/_VotesRefDataBeanRemote_Wrapper.java)
    at gov.ca.lc.refdata.VotesWS.getBillAnalysis(VotesWS.java:102)
    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 com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
    at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:781)
    at com.sun.corba.ee.impl.encoding.CodeSetConversion$JavaCTBConverter.convertCharArray(CodeSetConversion.java:324)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_2.write_wstring(CDROutputStream_1_2.java:470)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.writeWStringValue(CDROutputStream_1_0.java:738)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:956)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:977)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:706)
    at com.sun.corba.ee.impl.encoding.CDROutputObject.write_value(CDROutputObject.java:528)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.writeObjectField(IIOPOutputStream.java:775)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.outputClassFields(IIOPOutputStream.java:846)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.defaultWriteObjectDelegate(IIOPOutputStream.java:245)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.outputObject(IIOPOutputStream.java:614)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:196)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueInternal(ValueHandlerImpl.java:235)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueWithVersion(ValueHandlerImpl.java:216)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:180)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.callWriteValue(CDROutputStream_1_0.java:852)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.writeRMIIIOPValueType(CDROutputStream_1_0.java:837)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:962)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:977)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_abstract_interface(CDROutputStream_1_0.java:692)
    at com.sun.corba.ee.impl.encoding.CDROutputObject.write_abstract_interface(CDROutputObject.java:546)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAbstractObject(Util.java:494)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.writeObjectOverride(IIOPOutputStream.java:176)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:327)
    at java.util.LinkedList.writeObject(LinkedList.java:942)
    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 com.sun.corba.ee.impl.io.IIOPOutputStream.invokeObjectWriter(IIOPOutputStream.java:646)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.outputObject(IIOPOutputStream.java:612)
    at com.sun.corba.ee.impl.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:196)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueInternal(ValueHandlerImpl.java:235)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueWithVersion(ValueHandlerImpl.java:216)
    at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:180)
    at 
4

1 回答 1

1

该代码正在引发异常,因为它正在验证某些字符数据是否有效。并非所有代码单元序列都形成 Unicode 编码中的有效代码点。

字符串不是二进制安全的,因为将byte数据转换为char数据涉及转码操作。输入byte数据必须符合转码器预期的编码或数据丢失结果。

blob 对象表示存储在 oracle db 中的 word 文档。

我检索 blob 并使用 utf8 编码转换为 java 字节,然后传递给一个安静的 web 服务。

Restful webservice 接收 blob 对象并作为 json 传递给另一个客户端。

二进制 Word 文档不能在不丢失数据的情况下翻译成字符数据,至少在不将其编码为Base64之类的形式时不能。如果您将文件编码为 Base64,那么接收器将需要知道如何对其进行解码。

我对所涉及的转换的理解:

BLOB (bytes)
   > String (data is already corrupt here)
          > UTF-8 bytes 
                      > String
                             > JSON
                                  > junk

这种设计是有缺陷的。

这会更好:

BLOB (bytes)
   > Base64 String
                 > UTF-8 bytes
                             > Base64 String
                                           > JSON
                                                > Base64 String
                                                              > BLOB

这可能不是您所需要的,但关键是所有转换都必须是互惠且无损的。

请注意,JSON 始终以 Unicode 转换格式编码,或者根据定义它不是 JSON。默认值为规范定义的 UTF-8。

于 2012-12-20T11:27:35.073 回答