我面临一个奇怪的问题。我有一个使用AWS sdk My Local设置的Java webapp
我的一个对象键名是“.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]
但是....对于完全相同的webapp(相同的战争)和相同的设置(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
作为错误点,它不是有效的HEX字符。 HEX字符以'%'
开头。你需要将它转移到%25
,这是它的等价物。
然后你的转义密钥名称将是:
".Test%25Test%25&Name.jpg"
希望能帮助到你!