简体   繁体   English

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException解析POST中的XML(Java Servlet)

[英]com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException parsing XML in POST (Java Servlet)

I am developing a Servlet which uses a POST to send the information. 我正在开发一个使用POST发送信息的Servlet。 I am getting an exception depending where the servlet is deployed. 根据servlet的部署位置,我遇到了一个异常。 If I deploy on a local JBoss EAP 7 it works like a charm. 如果我在本地JBoss EAP 7上进行部署,它的工作原理就像一个魅力。 But, if I deploy into a remote server (JBoss EAP 7 too) i am getting the following error: 但是,如果我部署到远程服务器(也是JBoss EAP 7)中,则会出现以下错误:

CODE

final InputStream is = new ByteArrayInputStream(xml);
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);

ERROR 错误

<message>
Failed to load XML: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte no válido 2 de la secuencia UTF-8 de 4 bytes

~ôJ뢺ÞjX³jwh•ªkyø«™§¬‚†Ú~*æiÊ+x„ÅÇ©¶*'ºè­©`zw«j¹Z~*æip(Ú½©Z </message>

For more information the servlet has a jboss-deployment-structure.xml 有关更多信息,servlet具有jboss-deployment-structure.xml

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
  <deployment>
    <dependencies>
      <module name="javax.api"/>
      <module name="org.apache.santuario.xmlsec"/>
      <module name="org.apache.xerces" />
      <system export="true">
        <paths> 
          <path name="com/sun/org/apache/xerces/internal/dom"/>
        </paths>
      </system>
    </dependencies>
  </deployment>
</jboss-deployment-structure>

Where the xerces library is implicated. 涉及xerces库的位置。 I don´t understand if my problem is related to that xml , or I should change some encoding in the server/servlet code. 我不知道我的问题是否与该xml有关,或者我应该更改服务器/ servlet代码中的某些编码。 Thnaks in advance. 提前想一下。

Badulake, Badulake,
What you are hitting looks like a encoding issue. 您遇到的问题似乎是编码问题。 When you don't specify encoding while converting a byte array to Java string, JVM uses the default encoding of the platform. 当您在将字节数组转换为Java字符串时未指定编码时,JVM将使用平台的默认编码。 In most cases the default encoding is utf-8 and that works great. 在大多数情况下,默认编码为utf-8,效果很好。 However I have seen many OS installations where the encoding is simply US-ASCII. 但是,我已经看到许多操作系统安装,其中的编码仅仅是US-ASCII。

If this is your issue, you can either set the default encoding as a JVM option on the Java command line or change the encoding on the platform to utf-8. 如果这是您的问题,则可以在Java命令行上将默认编码设置为JVM选项,也可以将平台上的编码更改为utf-8。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ClassCastException com.sun.org.apache.xerces.internal.dom.ElementNSImpl - ClassCastException com.sun.org.apache.xerces.internal.dom.ElementNSImpl java.lang.ClassCastException:org.jboss.weld.manager.BeanManagerImpl与com.sun.jersey.server.impl.cdi.CDIExtension不兼容 - java.lang.ClassCastException: org.jboss.weld.manager.BeanManagerImpl incompatible with com.sun.jersey.server.impl.cdi.CDIExtension com.sun.jersey.server.impl.application.WebApplicationImpl _handleRequest - com.sun.jersey.server.impl.application.WebApplicationImpl _handleRequest SoapUI无法从Web服务获得响应-ClassCastException:com.sun.xml.messaging.saaj.soap.impl.TextImpl - SoapUI isn't getting response from Web Service - ClassCastException: com.sun.xml.messaging.saaj.soap.impl.TextImpl java.lang.ClassNotFoundException:com.sun.corba.ee.impl.orb.ORBSingleton在Java EE 7应用程序中使用JDK 8时 - java.lang.ClassNotFoundException: com.sun.corba.ee.impl.orb.ORBSingleton while using JDK 8 in Java EE 7 applications 在Jboss 7中部署时间错误(java.lang.NoClassDefFoundError:com / sun / net / ssl / internal / ssl / Provider) - Deploy time error (java.lang.NoClassDefFoundError: com/sun/net/ssl/internal/ssl/Provider ) in Jboss 7 org.apache.axiom.om.impl.llom.OMTextImpl无法转换为java.lang.String - org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to java.lang.String 通过远程EJB返回实体会导致在com.sun.corba.ee.impl.orbutil.ClassInfoCache $ ClassInfo中生成 - java.lang.NullPointerException。<init> - Returning an entity via remote EJB results in - java.lang.NullPointerException at com.sun.corba.ee.impl.orbutil.ClassInfoCache$ClassInfo.<init> JBoss EAP 7 =&gt; ClassCastException:org.apache.jcp.xml.dsig.internal.dom.DOMReference无法强制转换为org.jcp.xml.dsig.internal.dom.DOMReference - JBoss EAP 7 => ClassCastException: org.apache.jcp.xml.dsig.internal.dom.DOMReference cannot be cast to org.jcp.xml.dsig.internal.dom.DOMReference 部署CXF Web服务时出错:无法将org.apache.xerces.parsers.XIncludeAwareParserConfiguration强制转换为…XMLParserConfiguration - Error deploying CXF webservice: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to … XMLParserConfiguration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM