进行s3.listObjects()时出现“转义(%)模式中的非法十六进制字符”

时间:2019-01-28 14:29:55

标签: xml dependencies xerces jaxp tomcat9

我面临一个奇怪的问题。我有一个使用AWS SDK的Java Webapp 我的本地设置是

  • 最新Docker
  • 带有Centos7 + tomcat9.0.13 + JDK 1.8.0_161的容器

我的对象键名之一是 “ .Test%Test%&Name.jpg”,

当我尝试s3.listObject()时会得到

by: java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "TE" at java.net.URLDecoder.decode(URLDecoder.java:194) ~[na:1.8.0_161] at com.amazonaws.util.SdkHttpUtils.urlDecode(SdkHttpUtils.java:114) ~[aws-java-sdk-core-1.11.283.jar:na]

但是。...对于相同的Web应用程序(相同的战争)和相同的设置(EC2 centos 7,jdk 1.8.161,tomcat 9.0.13)以及在S3中具有相同的密钥 s3.listObject()是否通过该异常不是

这绝对与JVM如何加载库有关,但是我不明白如何检查加载的内容。

我想比较在EC2上加载了哪个XML解析器和在本地Docker设置中加载了哪个解析器。

全栈跟踪:

Caused by: java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "TE"
    at java.net.URLDecoder.decode(URLDecoder.java:194) ~[na:1.8.0_161]
    at com.amazonaws.util.SdkHttpUtils.urlDecode(SdkHttpUtils.java:114) ~[aws-java-sdk-core-1.11.283.jar:na]
    at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.decodeIfSpecified(XmlResponsesSaxParser.java:302) ~[aws-java-sdk-s3-1.11.283.jar:na]
    at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.access$200(XmlResponsesSaxParser.java:100) ~[aws-java-sdk-s3-1.11.283.jar:na]
    at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser$ListBucketHandler.doEndElement(XmlResponsesSaxParser.java:699) ~[aws-java-sdk-s3-1.11.283.jar:na]
    at com.amazonaws.services.s3.model.transform.AbstractHandler.endElement(AbstractHandler.java:52) ~[aws-java-sdk-s3-1.11.283.jar:na]
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) ~[na:1.8.0_161]
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) ~[na:1.8.0_161]
    at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.parseXmlInputStream(XmlResponsesSaxParser.java:147) ~[aws-java-sdk-s3-1.11.283.jar:na]
    ... 163 common frames omitted

1 个答案:

答案 0 :(得分:0)

作为错误点,它不是有效的十六进制字符。十六进制字符以'%'开头。您需要将其转义为%25,它等效。

那么您的转义密钥名称将是:

".Test%25Test%25&Name.jpg"

希望有帮助!