英文:
409 response when uploading to artifactory using X-Checksum-Sha1 header with Apache's HTTP client in Java
问题
I am writing a Jenkins plugin in Java that uses the Apache HttpClient (org.apache.http.client.HttpClient) to upload artifacts to JFrog Artifactory. As part of the process, I would like to add a checksum to the artifacts that I upload.
From what I understand, this can be done using the X-Checksum headers and calculating the checksum locally. However, when I try to do this, the Artifactory server gives me the following response:
{
"errors" : [ {
"status" : 409,
"message" : "Checksum policy 'LocalRepoChecksumPolicy: CLIENT' rejected the
artifact 'bluemix-ace-maven-local:test_build/4/log.txt'. Checksums info
ChecksumsInfo{
checksums={
SHA-1=ChecksumInfo{
type=SHA-1,
original='1a5bc1ae3c47e519f8bd69f90802c9fcf9fbddb3',
actual='c4c9da01b9e278d68a4c15bb95e41437799700ed'
},
MD5=ChecksumInfo{
type=MD5,
original='null',
actual='aa4023acbcb095cceb35ac82f9a913a8'
},
SHA-256=ChecksumInfo{
type=SHA-256,
original='null',
actual='5032a081754db0ce3f8b394a5215940e30456a77ea1e82765ceb595c8e0050da'
}
}
}"
} ]
}
The checksum I am calculating locally is 1a5bc1ae3c47e519f8bd69f90802c9fcf9fbddb3
I have verified by going into bash and doing a shasum on that file. It matches the above. So for some reason, Artifactory is calculating a different SHA-1 sum than the one I have locally. Why might this be?
This issue seems to be very similar:
https://www.jfrog.com/jira/browse/RTFACT-8553
But his solution didn't help me. I have also tried MD5 and SHA256.
英文:
I am writing a Jenkins plugin in Java that uses the Apache HttpClient (org.apache.http.client.HttpClient) to upload artifacts to JFrog Artifactory. As part of the process I would like to add a checksum to the artifacts that I upload.
From what I understand, this can be done using the X-Checksum headers and calculating the checksum locally. However, when I try to do this, the artifactory server gives me the following response:
{
"errors" : [ {
"status" : 409,
"message" : "Checksum policy 'LocalRepoChecksumPolicy: CLIENT' rejected the
artifact 'bluemix-ace-maven-local:test_build/4/log.txt'. Checksums info
ChecksumsInfo{
checksums={
SHA-1=ChecksumInfo{
type=SHA-1,
original='1a5bc1ae3c47e519f8bd69f90802c9fcf9fbddb3',
actual='c4c9da01b9e278d68a4c15bb95e41437799700ed'
},
MD5=ChecksumInfo{
type=MD5,
original='null',
actual='aa4023acbcb095cceb35ac82f9a913a8'
},
SHA-256=ChecksumInfo{
type=SHA-256,
original='null',
actual='5032a081754db0ce3f8b394a5215940e30456a77ea1e82765ceb595c8e0050da'
}
}
}"
} ]
}
The checksum I am calculating locally is 1a5bc1ae3c47e519f8bd69f90802c9fcf9fbddb3
I have verified by going into bash and doing a shasum on that file. It matches the above. So for some reason artifactory is calculating a different sha1 sum than the one I have locally. Why might this be?
This issue seems to be very similar:
https://www.jfrog.com/jira/browse/RTFACT-8553
But his solution didn't help me. I have also tried MD5 and SHA256.
答案1
得分: 1
我自己解决了这个问题。问题是我在Java中使用了一个多部分实体,这意味着标题等会被添加到上传的文件中,这会导致校验和不同。我切换到了BufferedHttpEntity,现在它可以工作了。
英文:
I have figured out this problem myself. The problem was that I was using a multipart entity in Java, which means that headers, etc. are added to the uploaded file, which would cause the checksum to be different. I switched to BufferedHttpEntity and now it is working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论