Kev*_*n R 14 java ssl certificate apple-push-notifications
我正在使用生成的证书来解决问题,我用它来连接苹果推送服务.当生成的p12文件位于我的src/main/java文件夹中时,一切正常,但我将其移动到src/main/resources,并决定停止处理以下错误:
DerInputStream.getLength(): lengthTag=111, too big.
Run Code Online (Sandbox Code Playgroud)
要了解更多细节:我正在使用notnoop推送通知库,并按照Ray Wenderlich的教程生成证书.之后,我习惯按照命令生成一个p12文件,以便在java中使用:
openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM
openssl pkcs12 -nocerts -in single.p12 -out single.pem
openssl pkcs12 -export -inkey single.pem -in aps_development.pem -out dual.p12
Run Code Online (Sandbox Code Playgroud)
之后我将dual.p12移动到我的java项目中.首先,文件位于我的/ src/main/java文件夹中,让我们说com.company.push.certificates(当请求文件的代码处于时com.company.push).我通过使用请求输入流
InputStream stream = this.getClass().getResourceAsStream("certificates/dual.p12");
Run Code Online (Sandbox Code Playgroud)
这在开发中工作正常,但在构建项目时没有(使用maven),这就是为什么我使用完全相同的包将资源移动到资源文件夹.资源仍然被发现,但现在我得到了上述java.io.IOException
有谁知道这可能导致什么?
Ps:当我将文件移回src/main/java中的包时,一切正常,因此证书似乎是有效的.
chr*_*ris 26
发生这种情况是因为maven的资源过滤破坏了您的p12文件.
我们通过在pom.xml中用maven资源过滤排除p12文件来解决这个问题:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.p12</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.p12</include>
</includes>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
Kei*_*ith 25
在构建之后检查证书文件的内容,当maven复制到target/classes /时...可能是maven资源过滤,或者构建中的其他东西正在修改文件.验证classes文件夹中的最终内容与resources文件夹中的内容完全相同.
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
joe*_*son 14
我个人不喜欢复制maven构建中的excludes/includes部分,并且有两个必须保持同步的资源部分 - 所以我更喜欢使用maven资源插件来配置nonFilteredFileExtensions.
然后,构建部分中的资源部分就是(加上您可能需要的任何特定包含):
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
告诉maven-resources-plugin包含哪些文件不要过滤:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
<nonFilteredFileExtension>pem</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
请参阅:http://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html
| 归档时间: |
|
| 查看次数: |
9496 次 |
| 最近记录: |