我使用Artifactory Java客户端,并且无法将文件上传到Artifactory。我的代码非常简单,取自Artifactory Java Client测试文件夹:
artifactoryClient = ArtifactoryClient.create("localhost:8081", "admin", "admin");
InputStream content = new ByteArrayInputStream("I want to test my upload!".getBytes());
UploadableArtifact apAtrifact = artifactoryClient.repository("ext-snapshotlocal").upload("test/content.txt", content);
File res = apAtrifact.doUpload();
我收到了错误:
02:44:26.014 [main] DEBUG org.apache.http.headers - >> Accept-Encoding: gzip,deflate
02:44:26.014 [main] DEBUG org.apache.http.wire - >> "I want to test my upload!"
02:44:26.248 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 403 Forbidden[\r][\n]"
02:44:26.250 [main] DEBUG org.apache.http.wire - << "Server: Apache-Coyote/1.1[\r][\n]"
02:44:26.250 [main] DEBUG org.apache.http.wire - << "Content-Type: text/html;charset=utf-8[\r][\n]"
02:44:26.250 [main] DEBUG org.apache.http.wire - << "Content-Length: 961[\r][\n]"
02:44:26.250 [main] DEBUG org.apache.http.wire - << "Date: Sun, 24 Nov 2013 00:44:25 GMT[\r][\n]"
02:44:26.250 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
02:44:26.250 [main] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 403 Forbidden
02:44:26.250 [main] DEBUG org.apache.http.headers - << HTTP/1.1 403 Forbidden
02:44:26.250 [main] DEBUG org.apache.http.headers - << Server: Apache-Coyote/1.1
02:44:26.250 [main] DEBUG org.apache.http.headers - << Content-Type: text/html;charset=utf-8
02:44:26.250 [main] DEBUG org.apache.http.headers - << Content-Length: 961
02:44:26.250 [main] DEBUG org.apache.http.headers - << Date: Sun, 24 Nov 2013 00:44:25 GMT
02:44:26.253 [main] DEBUG o.a.h.impl.client.DefaultHttpClient - Connection can be kept alive indefinitely
02:44:26.254 [main] DEBUG groovyx.net.http.RESTClient - Response code: 403; found handler: org.codehaus.groovy.runtime.MethodClosure@41feeacb
02:44:26.254 [main] DEBUG groovyx.net.http.RESTClient - Parsing response as: application/json
02:44:26.265 [main] DEBUG org.apache.http.wire - << "<html><head><title>Apache Tomcat/7.0.39 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 403 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.39</h3></body></html>"
02:44:26.272 [main] DEBUG o.a.h.i.c.BasicClientConnectionManager - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@4349f1b6
02:44:26.272 [main] DEBUG o.a.h.i.c.BasicClientConnectionManager - Connection can be kept alive indefinitely
02:44:26.278 [main] WARN groovyx.net.http.RESTClient - Error parsing 'text/html;charset=utf-8' response
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: org.apache.http.conn.EofSensorInputStream@494f0b41; line: 1, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1284) ~[services-0.9-all.jar:na]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:588) ~[services-0.9-all.jar:na]
你能帮我解决这个问题吗?
答案 0 :(得分:1)
我确实发生了这件事。我假设您正在使用this client。事实证明我在URL中不够具体。我需要提供完整的路径,如下所示:
artifactoryClient = ArtifactoryClient.create("http://localhost:8081/artifactory", "admin", "password");
我假设如果您使用单独的容器来运行它而不是bin / artifactory.sh使用的容器,则可能需要调整该URL。
答案 1 :(得分:0)
你有403 Forbidden
,所以你可能应该查看你的凭据。如果是默认的Artifactory安装,它们应该是admin:password
,而不是admin:admin
。
另一个可能的原因是encrypted password policy。如果策略设置为“强制”,则在创建客户端时必须使用加密密码。
顺便说一句,您尝试将非快照文件上载到快照存储库。您应该检查它是否接受发布,否则在获得凭证后您将获得409
。