blob: 523322a3a5f362be6d61d724333dd1104900ad20 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia
| Rendered using Apache Maven Fluido Skin 1.3.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Olivier Lamy" />
<meta name="Date-Creation-yyyymmdd" content="20111005" />
<meta name="Date-Revision-yyyymmdd" content="20170513" />
<meta http-equiv="Content-Language" content="en" />
<title>Archiva Documentation &#x2013; Using REST Services</title>
<link rel="stylesheet" href="../../css/apache-maven-fluido-1.3.1.min.css" />
<link rel="stylesheet" href="../../css/site.css" />
<link rel="stylesheet" href="../../css/print.css" media="print" />
<script type="text/javascript" src="../../js/apache-maven-fluido-1.3.1.min.js"></script>
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-140879-5']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href="../../../../" id="bannerLeft">
<img src="../../../../images/archiva.png" alt="Apache Archiva"/>
</a>
</div>
<div class="pull-right"> <a href="http://www.apache.org/" id="bannerRight">
<img src="https://www.apache.org/images/asf_logo_wide_2016.png" alt="Apache Software Foundation"/>
</a>
</div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li class="">
<a href="http://www.apache.org/" class="externalLink" title="Apache">
Apache</a>
<span class="divider">/</span>
</li>
<li class="">
<a href="../../" title="Apache Archiva">
Apache Archiva</a>
<span class="divider">/</span>
</li>
<li class="">
<a href="../../../../index.html" title="Apache Archiva">
Apache Archiva</a>
<span class="divider">/</span>
</li>
<li class="active ">Using REST Services</li>
<li id="publishDate" class="pull-right"><span class="divider">|</span> Last Published: 2017-05-13</li>
<li id="projectVersion" class="pull-right">
Version: 2.2.3
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Introduction</li>
<li>
<a href="../../quick-start.html" title="Quick Start">
<i class="none"></i>
Quick Start</a>
</li>
<li>
<a href="../../tour/index.html" title="Feature Tour">
<i class="none"></i>
Feature Tour</a>
</li>
<li>
<a href="../../release-notes.html" title="Release Notes">
<i class="none"></i>
Release Notes</a>
</li>
<li>
<a href="../../../../download.html" title="Downloads">
<i class="none"></i>
Downloads</a>
</li>
<li class="nav-header">Users Guide</li>
<li>
<a href="../../userguide/browsing.html" title="Browsing">
<i class="none"></i>
Browsing</a>
</li>
<li>
<a href="../../userguide/searching.html" title="Searching">
<i class="none"></i>
Searching</a>
</li>
<li>
<a href="../../userguide/delete-artifact.html" title="Deleting an Artifact">
<i class="none"></i>
Deleting an Artifact</a>
</li>
<li>
<a href="../../userguide/using-repository.html" title="Using as a repository">
<i class="none"></i>
Using as a repository</a>
</li>
<li>
<a href="../../userguide/deploy.html" title="Deploying to repository">
<i class="none"></i>
Deploying to repository</a>
</li>
<li>
<a href="../../userguide/virtual-repositories.html" title="Configuring Virtual Repositories">
<i class="none"></i>
Configuring Virtual Repositories</a>
</li>
<li>
<a href="../../userguide/rss.html" title="Rss Feeds in Archiva">
<i class="none"></i>
Rss Feeds in Archiva</a>
</li>
<li>
<a href="../../userguide/querying-artifacts.html" title="Querying Artifacts">
<i class="none"></i>
Querying Artifacts</a>
</li>
<li class="nav-header">Administrators Guide</li>
<li>
<a href="../../adminguide/installing.html" title="Installing Archiva">
<i class="icon-chevron-right"></i>
Installing Archiva</a>
</li>
<li>
<a href="../../adminguide/databases.html" title="Databases">
<i class="none"></i>
Databases</a>
</li>
<li>
<a href="../../adminguide/repositories-content-storage.html" title="Repositories Content Storage">
<i class="none"></i>
Repositories Content Storage</a>
</li>
<li>
<a href="../../adminguide/security.html" title="Security">
<i class="icon-chevron-right"></i>
Security</a>
</li>
<li>
<a href="../../adminguide/configuration.html" title="Archiva Configuration">
<i class="icon-chevron-right"></i>
Archiva Configuration</a>
</li>
<li class="active">
<a href="#"><i class="none"></i>REST Apis</a>
</li>
<li>
<a href="../../adminguide/configuration-files.html" title="Configuration Files">
<i class="none"></i>
Configuration Files</a>
</li>
<li>
<a href="../../adminguide/system-status.html" title="System Status">
<i class="none"></i>
System Status</a>
</li>
<li>
<a href="../../adminguide/logging.html" title="Log Files">
<i class="icon-chevron-right"></i>
Log Files</a>
</li>
<li>
<a href="../../adminguide/reports.html" title="Reports">
<i class="none"></i>
Reports</a>
</li>
<li class="nav-header">Customising Archiva</li>
<li>
<a href="../../customising/writing-consumer.html" title="Writing a Consumer Plugin">
<i class="none"></i>
Writing a Consumer Plugin</a>
</li>
<li class="nav-header">More Information</li>
<li>
<a href="http://cwiki.apache.org/confluence/display/ARCHIVA/Index" class="externalLink" title="Archiva Wiki">
<i class="none"></i>
Archiva Wiki</a>
</li>
<li class="nav-header">ASF</li>
<li>
<a href="http://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How Apache Works">
<i class="none"></i>
How Apache Works</a>
</li>
<li>
<a href="http://www.apache.org/foundation/" class="externalLink" title="Foundation">
<i class="none"></i>
Foundation</a>
</li>
<li>
<a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsoring Apache">
<i class="none"></i>
Sponsoring Apache</a>
</li>
<li>
<a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks">
<i class="none"></i>
Thanks</a>
</li>
<li class="nav-header">Project Documentation</li>
<li>
<a href="../../project-info.html" title="Project Information">
<i class="icon-chevron-right"></i>
Project Information</a>
</li>
</ul>
<form id="search-form" action="http://www.google.com/search" method="get" >
<input value="http://archiva.apache.org/docs/2.2.3/" name="sitesearch" type="hidden"/>
<input class="search-query" name="q" id="query" type="text" />
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=search-form"></script>
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div id="twitter">
<a href="https://twitter.com/archiva" class="twitter-follow-button" data-show-count="false" data-align="left" data-size="medium" data-show-screen-name="true" data-lang="en">Follow archiva</a>
<script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="builtBy" alt="Built by Maven" src="../../images/logos/maven-feather.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span10" >
<!-- Licensed to the Apache Software Foundation (ASF) under one --><!-- or more contributor license agreements. See the NOTICE file --><!-- distributed with this work for additional information --><!-- regarding copyright ownership. The ASF licenses this file --><!-- to you under the Apache License, Version 2.0 (the --><!-- "License"); you may not use this file except in compliance --><!-- with the License. You may obtain a copy of the License at --><!-- --><!-- http://www.apache.org/licenses/LICENSE-2.0 --><!-- --><!-- Unless required by applicable law or agreed to in writing, --><!-- software distributed under the License is distributed on an --><!-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY --><!-- KIND, either express or implied. See the License for the --><!-- specific language governing permissions and limitations --><!-- under the License. --><!-- NOTE: For help with the syntax of this file, see: --><!-- http://maven.apache.org/guides/mini/guide-apt-format.html --><div class="section">
<h2><a name="Using_REST_Services"></a>Using REST Services</h2>
<p>Starting version 1.4, you can use some REST Services to manage your Apache Archiva instance and Search artifacts. All samples here will use Apache CXF REST client API. By the way you can use some others REST client frameworks. NOTE: a wadl is available in your Archiva instance : http(s)://ip:port/../restServices/application.wadl</p>
<ul>
<li>Archiva REST api is available here: <a class="externalLink" href="http://archiva.apache.org/docs/2.2.3/rest-docs-archiva-rest-api/index.html">http://archiva.apache.org/docs/2.2.3/rest-docs-archiva-rest-api/index.html</a></li>
<li>Archiva UI REST api is available here: <a class="externalLink" href="http://archiva.apache.org/docs/2.2.3/rest-docs-archiva-ui/index.html">http://archiva.apache.org/docs/2.2.3/rest-docs-archiva-ui/index.html</a></li>
<li>Redback REST api is available here: <a class="externalLink" href="http://archiva.apache.org/docs/2.2.3/rest-docs-redback-rest-api/index.html">http://archiva.apache.org/docs/2.2.3/rest-docs-redback-rest-api/index.html</a></li></ul>
<div class="section">
<h3><a name="Security_related_information"></a>Security related information</h3>
<p>Starting with version 2.2.2 we added HTTP verification techniques to avoid cross site request forgery attacks. The updating services check Origin and Referer header and use a token provided by the login service. If you use the webservices with a native client that is no browser or want to allow requests from different origin URLs you have to change the configuration. For further information see the <a href="/redback/integration/rest.html">Redback REST documentation</a></p></div>
<div class="section">
<h3><a name="Search_Service"></a>Search Service</h3>
<p>Authentication headers for connect to your Archiva instance :</p>
<div class="source">
<pre> // guest with an empty password
public static String guestAuthzHeader =
&quot;Basic &quot; + org.apache.cxf.common.util.Base64Utility.encode( ( &quot;guest&quot; + &quot;:&quot; ).getBytes() );
// with an other login/password
//public String authzHeader =
// &quot;Basic &quot; + org.apache.cxf.common.util.Base64Utility.encode( ( &quot;login&quot; + &quot;:password&quot; ).getBytes() );
</pre></div>
<p>Get a Search Service Client :</p>
<div class="source">
<pre>SearchService service =
JAXRSClientFactory.create( getBaseUrl() + &quot;/&quot; + getRestServicesPath() + &quot;/archivaServices/&quot;,
SearchService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
// to add authentification
if ( authzHeader != null )
{
WebClient.client( service ).header( &quot;Authorization&quot;, authzHeader );
}
// Set the Referer header to your archiva server url
WebClient.client(service).header(&quot;Referer&quot;,&quot;http://localhost:&quot;+port);
// to configure read timeout
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
// if you want to use json as exchange format xml is supported too
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
return service;
</pre></div>
<p>Quick Search</p>
<div class="source">
<pre>List&lt;Artifact&gt; artifacts = searchService.quickSearch( &quot;commons-logging&quot; );
// return all artifacts with groupId OR artifactId OR version OR packaging OR className
// NOTE : only artifacts with classifier empty are returned
</pre></div>
<p>Search Artifacts Version : to search all availables version with a groupId and artifactId and packaging (if empty jar is used)</p>
<div class="source">
<pre> SearchService searchService = getSearchService( authorizationHeader );
List&lt;Artifact&gt; artifacts = searchService.getArtifactVersions( &quot;commons-logging&quot;, &quot;commons-logging&quot;, &quot;jar&quot; );
</pre></div>
<p>Search Service with a classifier :</p>
<div class="source">
<pre> SearchRequest searchRequest = new SearchRequest();
searchRequest.setGroupId( &quot;commons-logging&quot; );
searchRequest.setArtifactId( &quot;commons-logging&quot; );
searchRequest.setClassifier( &quot;sources&quot; );
List&lt;Artifact&gt; artifacts = searchService.searchArtifacts( searchRequest );
</pre></div>
<p>Search Service with a classifier :</p>
<div class="source">
<pre> SearchRequest searchRequest = new SearchRequest();
searchRequest.setGroupId( &quot;commons-logging&quot; );
searchRequest.setArtifactId( &quot;commons-logging&quot; );
searchRequest.setClassifier( &quot;sources&quot; );
List&lt;Artifact&gt; artifacts = searchService.searchArtifacts( searchRequest );
</pre></div>
<p>Copy Artifact from a repository to an other one :</p>
<p>For some reasons you want to use a test repository before moving your artifacts to a repository used by final users. To achieve this, you can use a service which can copy an artifact from a repository to an other one</p>
<div class="source">
<pre>// configure the artifact you want to copy
// if package ommited default will be jar
ArtifactTransferRequest artifactTransferRequest = new ArtifactTransferRequest();
artifactTransferRequest.setGroupId( &quot;org.apache.karaf.features&quot; );
artifactTransferRequest.setArtifactId( &quot;org.apache.karaf.features.core&quot; );
artifactTransferRequest.setVersion( &quot;2.2.2&quot; );
artifactTransferRequest.setRepositoryId( SOURCE_REPO_ID );
artifactTransferRequest.setTargetRepositoryId( TARGET_REPO_ID );
// retrieve the service
RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
// copy the artifact
Boolean res = repositoriesService.copyArtifact( artifactTransferRequest );
</pre></div>
<p>To know all the possible options, you can refer to the javadoc of SearchRequest class.</p></div>
<div class="section">
<h3><a name="Browse_Service"></a>Browse Service</h3>
<p>Get a Browse Service Client :</p>
<div class="source">
<pre> BrowseService service =
JAXRSClientFactory.create( getBaseUrl() + &quot;/&quot; + getRestServicesPath() + &quot;/archivaServices/&quot;,
BrowseService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
// to add authentification
if ( authzHeader != null )
{
WebClient.client( service ).header( &quot;Authorization&quot;, authzHeader );
}
// Set the Referer header to your archiva server url
WebClient.client(service).header(&quot;Referer&quot;,&quot;http://localhost:&quot;+port);
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
if ( useXml )
{
WebClient.client( service ).accept( MediaType.APPLICATION_XML_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_XML_TYPE );
}
else
{
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
}
return service;
</pre></div>
<p>Get artifacts based on project version metadata, generic metadata added previously in Archiva :</p>
<div class="source">
<pre> BrowseService browseService = getBrowseService( authorizationHeader, true );
browseService.addMetadata( &quot;commons-cli&quot;, &quot;commons-cli&quot;, &quot;1.0&quot;, &quot;wine&quot;, &quot;bordeaux&quot;, TEST_REPO_ID );
List&lt;Artifact&gt; artifactDownloadInfos =
browseService.getArtifactsByProjectVersionMetadata( &quot;wine&quot;, &quot;bordeaux&quot;, TEST_REPO_ID );
assertThat( artifactDownloadInfos ).isNotNull().isNotEmpty().hasSize( 3 );
</pre></div>
<p>Get artifacts based on the artifact properties :</p>
<div class="source">
<pre> BrowseService browseService = getBrowseService( authorizationHeader, true );
List&lt;Artifact&gt; artifactDownloadInfos = browseService.getArtifactsByMetadata( &quot;type&quot;, &quot;pom&quot;, TEST_REPO_ID );
assertThat( artifactDownloadInfos ).isNotNull().isNotEmpty().hasSize( 11 );
</pre></div>
<p>Get artifacts based on the project properties from POM :</p>
<div class="source">
<pre> BrowseService browseService = getBrowseService( authorizationHeader, true );
List&lt;Artifact&gt; artifactDownloadInfos =
browseService.getArtifactsByProperty( &quot;org.name&quot;, &quot;The Apache Software Foundation&quot;, TEST_REPO_ID );
assertThat( artifactDownloadInfos ).isNotNull().isNotEmpty().hasSize( 7 );
</pre></div>
<p>Searching by properties and metadata :</p>
<div class="source">
<pre> BrowseService browseService = getBrowseService( authorizationHeader, true );
List&lt;Artifact&gt; artifactDownloadInfos =
browseService.searchArtifacts( &quot;org.name&quot;, &quot;The Apache Software Foundation&quot;, TEST_REPO_ID, true );
assertThat( artifactDownloadInfos ).isNotNull().isNotEmpty().hasSize( 7 );
</pre></div>
<div class="source">
<pre> BrowseService browseService = getBrowseService( authorizationHeader, true );
List&lt;Artifact&gt; artifactDownloadInfos =
browseService.searchArtifacts( &quot;The Apache Software Foundation&quot;, TEST_REPO_ID, true );
assertThat( artifactDownloadInfos ).isNotNull().isNotEmpty().hasSize( 7 );
</pre></div>
<p>Get Search</p>
<div class="source">
<pre>List&lt;Artifact&gt; artifacts = searchService.quickSearch( &quot;commons-logging&quot; );
// return all artifacts with groupId OR artifactId OR version OR packaging OR className
// NOTE : only artifacts with classifier empty are returned
</pre></div>
<p>Dependencies to add in order to use those REST Services</p>
<div class="source">
<pre> &lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
&lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt;
&lt;version&gt;${jacksonVersion}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
&lt;artifactId&gt;jackson-jaxrs-xml-provider&lt;/artifactId&gt;
&lt;version&gt;${jacksonVersion}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
&lt;version&gt;${jacksonVersion}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-rt-frontend-jaxrs&lt;/artifactId&gt;
&lt;version&gt;${cxf.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-rt-rs-client&lt;/artifactId&gt;
&lt;version&gt;${cxf.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-rt-rs-extension-providers&lt;/artifactId&gt;
&lt;version&gt;${cxf.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.archiva&lt;/groupId&gt;
&lt;artifactId&gt;archiva-rest-api&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
</pre></div>
<p>Current versions use in Apache Archiva:</p>
<ul>
<li><tt>${project.version}</tt>: 2.2.3</li>
<li><tt>${cxfVersion}</tt>: $<a name="cxf.version">cxf.version</a></li>
<li><tt>${jacksonVersion}</tt>: 2.3.0</li></ul></div>
<div class="section">
<h3><a name="Security_Framework_Services:"></a>Security Framework Services:</h3>
<p>You can use Redback Rest Services to control user creation/modification and add/remove roles.</p>
<p>See <a class="externalLink" href="http://archiva.apache.org/redback/integration/rest.html">http://archiva.apache.org/redback/integration/rest.html</a></p></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p >Copyright &copy; 2006&#x2013;2017
<a href="http://www.apache.org/">The Apache Software Foundation</a>.
All rights reserved.
</p>
</div>
<div class="row span12">Apache Archiva :: Documentation, Archiva :: Documentation, Apache, the Apache feather logo, and the Apache Archiva :: Documentation project logos are trademarks of The Apache Software Foundation.</div>
<div class="row span12">
<a href="http://archiva.apache.org/docs/2.2.3/privacy-policy.html">Privacy Policy</a>
</div>
<div id="ohloh" class="pull-right">
<script type="text/javascript" src="http://www.ohloh.net/p/6670/widgets/project_basic_stats.js"></script>
</div>
</div>
</footer>
</body>
</html>