Hi,
I am creating a plug-in for staging and promoting artifacts. My problem is that when I promote, I need to use the upload artifact. I just cant seem to get some java code to work to call the api for uploading a file. The mounting point is /service/local/artifact/maven/content. I tried things like : String url = "http://localhost:8085/nexus/service/local/artifact/maven/content"; HttpClient client = new HttpClient(); PostMethod method = new PostMethod( url ); method.addParameter( "r", "releases" ); method.addParameter( "g", "com.ericsson.test" ); method.addParameter( "a", "Epackage-jar1" ); method.addParameter( "v", "1.1" ); method.addParameter( "p", "jar" ); method.addParameter( "c", "" ); method.addParameter( "extension", "jar" ); File artifact = new File ("aFilePath"); method.setFileData(artifact ); client.executeMethod( method ); But I keep getting errors. I know how to call the api from the command line the the --data and sending some json, but with Java, I cant find a way to send a payload to the api. If anyone has something that might help me, it would be very appreciated. Thanks |
You need multipart upload.
Look into this IT helper class: https://github.com/sonatype/nexus/blob/master/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/DeployUtils.java Hint: deployUsingGavWithRest method is what you are looking for. Thanks, ~t~ On Fri, Oct 28, 2011 at 3:08 PM, Scalpa01 <[hidden email]> wrote: > Hi, > > I am creating a plug-in for staging and promoting artifacts. My problem is > that when I promote, I need to use the upload artifact. I just cant seem > to get some java code to work to call the api for uploading a file. > > The mounting point is /service/local/artifact/maven/content. I tried things > like : > > String url = > "http://localhost:8085/nexus/service/local/artifact/maven/content"; > HttpClient client = new HttpClient(); > PostMethod method = new PostMethod( url ); > > method.addParameter( "r", "releases" ); > method.addParameter( "g", "com.ericsson.test" ); > method.addParameter( "a", "Epackage-jar1" ); > method.addParameter( "v", "1.1" ); > method.addParameter( "p", "jar" ); > method.addParameter( "c", "" ); > method.addParameter( "extension", "jar" ); > > File artifact = new File ("aFilePath"); > method.setFileData(artifact ); > > client.executeMethod( method ); > > > But I keep getting errors. I know how to call the api from the command line > the the --data and sending some json, but with Java, I cant find a way to > send a payload to the api. > > If anyone has something that might help me, it would be very appreciated. > > Thanks > > > -- > View this message in context: http://maven.40175.n5.nabble.com/Uploading-artifacts-with-api-tp4945862p4945862.html > Sent from the Nexus Maven Repository Manager Users List mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
In reply to this post by Scalpa01
Sorry, just gonna specify some things. Trying to use a POST and the line
method.addParameter( "extension", "jar" ); should be method.addParameter( "e", "jar" ); |
In reply to this post by Tamás Cservenák
Thanks. Modified a little bit of the code and got it to work perfectly. Would have never found out by myself how to do this.
|
Is there a wiki page detailing using the rest api for uploads?
We're thinking of using nexus OSS in a unique way... On Mon, Oct 31, 2011 at 1:50 PM, Scalpa01 <[hidden email]> wrote: Thanks. Modified a little bit of the code and got it to work perfectly. |
Try:
http://your-host/nexus/nexus-core-documentation-plugin/core/docs/index.html
On Wed, Nov 9, 2011 at 9:40 AM, Maven User <[hidden email]> wrote: Is there a wiki page detailing using the rest api for uploads? |
Free forum by Nabble | Edit this page |