You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/08/20 08:56:57 UTC

svn commit: r1159854 - in /karaf/sandbox/jbonofre/cave/trunk: assembly/src/main/resources/ server/ server/backend/api/ server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/ server/backend/filesystem/ server/backend/filesystem/src/m...

Author: jbonofre
Date: Sat Aug 20 06:56:56 2011
New Revision: 1159854

URL: http://svn.apache.org/viewvc?rev=1159854&view=rev
Log:
Refactoring of the backend to include REST services as a core part.

Removed:
    karaf/sandbox/jbonofre/cave/trunk/server/rest/pom.xml
    karaf/sandbox/jbonofre/cave/trunk/server/rest/src/main/java/org/apache/karaf/cave/server/rest/CaveService.java
    karaf/sandbox/jbonofre/cave/trunk/server/rest/src/main/resources/OSGI-INF/blueprint/rest.xml
Modified:
    karaf/sandbox/jbonofre/cave/trunk/assembly/src/main/resources/features.xml
    karaf/sandbox/jbonofre/cave/trunk/server/backend/api/pom.xml
    karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/pom.xml
    karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java
    karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/resources/OSGI-INF/blueprint/cave-filesystem-backend.xml
    karaf/sandbox/jbonofre/cave/trunk/server/pom.xml

Modified: karaf/sandbox/jbonofre/cave/trunk/assembly/src/main/resources/features.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/assembly/src/main/resources/features.xml?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/assembly/src/main/resources/features.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/assembly/src/main/resources/features.xml Sat Aug 20 06:56:56 2011
@@ -19,6 +19,10 @@
 <features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
 
     <feature name="cave-server" version="${project.version}">
+        <configfile finalname="/etc/org.apache.cxf.osgi.cfg">
+            mvn:org.apache.karaf.cave/apache-karaf-cave/${project.version}/cfg/cxf
+        </configfile>
+        <feature version="[2.4.2,3)">cxf</feature>
         <feature>obr</feature>
         <configfile finalname="/etc/org.apache.karaf.cave.server.backend.filesystem.cfg">
             mvn:org.apache.karaf.cave/apache-karaf-cave/${project.version}/cfg/filesystem
@@ -32,13 +36,4 @@
         <bundle>mvn:org.apache.karaf.cave.server/org.apache.karaf.cave.server.command/${project.version}</bundle>
     </feature>
 
-    <feature name="cave-server-rest" version="${project.version}">
-        <configfile finalname="/etc/org.apache.cxf.osgi.cfg">
-            mvn:org.apache.karaf.cave/apache-karaf-cave/${project.version}/cfg/cxf
-        </configfile>
-        <feature version="[2.4.2,3)">cxf</feature>
-        <feature version="${project.version}">cave-server</feature>
-        <bundle>mvn:org.apache.karaf.cave.server/org.apache.karaf.cave.server.rest/${project.version}</bundle>
-    </feature>
-
 </features>
\ No newline at end of file

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/api/pom.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/api/pom.xml?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/api/pom.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/api/pom.xml Sat Aug 20 06:56:56 2011
@@ -33,6 +33,13 @@
     <name>Apache Karaf :: Cave :: Server :: Backend :: API</name>
     <packaging>bundle</packaging>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        </dependency>
+    </dependencies>
+
     <build>
         <plugins>
             <plugin>

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepository.java Sat Aug 20 06:56:56 2011
@@ -16,41 +16,54 @@
  */
 package org.apache.karaf.cave.server.backend.api;
 
+import javax.xml.bind.annotation.XmlRootElement;
 import java.net.URL;
 
 /**
  * Cave repository is a storage area where to upload artifacts.
  * It's already the basement of the OBR repository.xml metadata.
  */
-public interface CaveRepository {
+@XmlRootElement(name = "cave-repository")
+public abstract class CaveRepository {
+
+    private String name;
+    private String location;
 
     /**
      * Get the name of the repository.
      *
      * @return the name of the repository
      */
-    String getName();
+    public String getName() {
+        return this.name;
+    }
 
     /**
      * Set the name of the repository.
      *
      * @param name the name of the repository
      */
-    void setName(String name);
+    public void setName(String name) {
+        this.name = name;
+    }
 
     /**
      * Get the location (filesystem) of this repository.
      *
      * @return the location of this repository.
      */
-    String getLocation();
+    public String getLocation() {
+        return this.location;
+    }
 
     /**
      * Set the location (filesystem) of this repository.
      *
      * @param location the location of this repository
      */
-    void setLocation(String location);
+    public void setLocation(String location) {
+        this.location = location;
+    }
 
     /**
      * Upload an artifact from the given URL into the repository.
@@ -58,7 +71,7 @@ public interface CaveRepository {
      * @param url the URL of the artifact.
      * @throws Exception in case of upload failure.
      */
-    void upload(URL url) throws Exception;
+    public abstract void upload(URL url) throws Exception;
 
     /**
      * Scan the whole repository, reading bundle MANIFEST, etc to update
@@ -66,7 +79,7 @@ public interface CaveRepository {
      *
      * @throws Exception in case of scan failure.
      */
-    void scan() throws Exception;
+    public abstract void scan() throws Exception;
 
     /**
      * Proxy an URL (for instance a Maven repository) and add OBR information.
@@ -74,7 +87,7 @@ public interface CaveRepository {
      * @param url the URL to proxy.
      * @throws Exception
      */
-    void proxy(URL url) throws Exception;
+    public abstract void proxy(URL url) throws Exception;
 
     /**
      * Populate from a remote URL (for instance a Maven repository), and eventually update the OBR information.
@@ -83,7 +96,7 @@ public interface CaveRepository {
      * @param update if true the OBR information is updated, false else.
      * @throws Exception in case of copy failure.
      */
-    void populate(URL url, boolean update) throws Exception;
+    public abstract void populate(URL url, boolean update) throws Exception;
 
     /**
      * Return the repository URL of the OBR repository.xml.
@@ -91,13 +104,13 @@ public interface CaveRepository {
      * @return the URL of the OBR repository.xml.
      * @throws Exception in case of failure to get repository.xml URL.
      */
-    URL getRepositoryXml() throws Exception;
+    public abstract URL getRepositoryXml() throws Exception;
 
     /**
      * Cleanup the repository storage.
      *
      * @throws Exception in case of cleanup failure.
      */
-    void cleanup() throws Exception;
+    public abstract void cleanup() throws Exception;
 
 }

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/api/src/main/java/org/apache/karaf/cave/server/backend/api/CaveRepositoryService.java Sat Aug 20 06:56:56 2011
@@ -16,9 +16,12 @@
  */
 package org.apache.karaf.cave.server.backend.api;
 
+import javax.ws.rs.*;
+
 /**
  * Service to manipulate Cave repository.
  */
+@Path("/")
 public interface CaveRepositoryService {
 
     /**
@@ -29,6 +32,9 @@ public interface CaveRepositoryService {
      * @return the Karaf Cave repository.
      * @throws Exception in case of creation failure.
      */
+    @POST
+    @Consumes("application/xml")
+    @Produces("application/xml")
     CaveRepository createRepository(String name, boolean scan) throws Exception;
 
     /**
@@ -40,6 +46,9 @@ public interface CaveRepositoryService {
      * @return the Karaf Cave repository.
      * @throws Exception in case of creation failure.
      */
+    @POST
+    @Consumes("application/xml")
+    @Produces("application/xml")
     CaveRepository createRepository(String name, String location, boolean scan) throws Exception;
 
     /**
@@ -48,6 +57,8 @@ public interface CaveRepositoryService {
      * @param name the name of Karaf Cave repository to destroy.
      * @throws Exception in case of destroy failure.
      */
+    @POST
+    @Consumes("text/plain")
     void destroy(String name) throws Exception;
 
     /**
@@ -56,6 +67,8 @@ public interface CaveRepositoryService {
      * @param name the name of the Karaf Cave repository.
      * @throws Exception in case of registration failure.
      */
+    @POST
+    @Consumes("text/plain")
     void register(String name) throws Exception;
 
     /**
@@ -63,6 +76,9 @@ public interface CaveRepositoryService {
      *
      * @return the Karaf Cave repositories.
      */
+    @GET
+    @Path("/repositories")
+    @Produces("application/xml")
     CaveRepository[] getRepositories();
 
     /**
@@ -71,6 +87,9 @@ public interface CaveRepositoryService {
      * @param name the name of the Karaf Cave repository to look for.
      * @return the Karaf Cave repository
      */
-    CaveRepository getRepository(String name);
+    @GET
+    @Path("/repositories/{name}")
+    @Produces("application/xml")
+    CaveRepository getRepository(@PathParam("name") String name);
 
 }

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/pom.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/pom.xml?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/pom.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/pom.xml Sat Aug 20 06:56:56 2011
@@ -55,6 +55,10 @@
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient-osgi</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/java/org/apache/karaf/cave/server/backend/impl/CaveRepositoryImpl.java Sat Aug 20 06:56:56 2011
@@ -40,18 +40,17 @@ import java.net.URL;
 /**
  * Default implementation of a Karaf Cave repository.
  */
-public class CaveRepositoryImpl implements CaveRepository {
+public class CaveRepositoryImpl extends CaveRepository {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(CaveRepositoryImpl.class);
 
-    private String name;
-    private String location;
-
     private RepositoryImpl obrRepository;
 
     public CaveRepositoryImpl(String name, String location, boolean scan) throws Exception {
-        this.name = name;
-        this.location = location;
+        super();
+
+        this.setName(name);
+        this.setLocation(location);
 
         this.createRepositoryDirectory();
         if (scan) {
@@ -63,11 +62,11 @@ public class CaveRepositoryImpl implemen
      * Check if the repository folder exists and create it if not.
      */
     private void createRepositoryDirectory() throws Exception {
-        LOGGER.debug("Create Karaf Cave repository {} folder.", name);
-        File locationFile = new File(location);
+        LOGGER.debug("Create Karaf Cave repository {} folder.", this.getName());
+        File locationFile = new File(this.getLocation());
         if (!locationFile.exists()) {
             locationFile.mkdirs();
-            LOGGER.debug("Karaf Cave repository {} location has been created.", name);
+            LOGGER.debug("Karaf Cave repository {} location has been created.", this.getName());
             LOGGER.debug(locationFile.getAbsolutePath());
         }
         File repositoryXml = new File(locationFile, "repository.xml");
@@ -75,26 +74,10 @@ public class CaveRepositoryImpl implemen
             obrRepository = (RepositoryImpl) new DataModelHelperImpl().repository(repositoryXml.toURI().toURL());
         } else {
             obrRepository = new RepositoryImpl();
-            obrRepository.setName(name);
+            obrRepository.setName(this.getName());
         }
     }
 
-    public String getName() {
-        return this.name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getLocation() {
-        return this.location;
-    }
-
-    public void setLocation(String location) {
-        this.location = location;
-    }
-
     /**
      * Generate the repository.xml with the artifact at the given URL.
      *
@@ -131,7 +114,7 @@ public class CaveRepositoryImpl implemen
     public void upload(URL url) throws Exception {
         LOGGER.debug("Upload new artifact from {}", url);
         String artifactName = "artifact-" + System.currentTimeMillis();
-        File temp = new File(new File(location), artifactName);
+        File temp = new File(new File(this.getLocation()), artifactName);
         FileUtils.copyURLToFile(url, temp);
         // update the repository.xml
         ResourceImpl resource = (ResourceImpl) new DataModelHelperImpl().createResource(temp.toURI().toURL());
@@ -140,7 +123,7 @@ public class CaveRepositoryImpl implemen
             LOGGER.warn("The {} artifact source is not a valid OSGi bundle", url);
             return;
         }
-        File destination = new File(new File(location), resource.getSymbolicName() + "-" + resource.getVersion() + ".jar");
+        File destination = new File(new File(this.getLocation()), resource.getSymbolicName() + "-" + resource.getVersion() + ".jar");
         FileUtils.moveFile(temp, destination);
         resource = (ResourceImpl) new DataModelHelperImpl().createResource(destination.toURI().toURL());
         this.addResource(resource);
@@ -153,7 +136,7 @@ public class CaveRepositoryImpl implemen
      * @throws Exception in case of scan failure.
      */
     public void scan() throws Exception {
-        this.scan(new File(location));
+        this.scan(new File(this.getLocation()));
         this.generateRepositoryXml();
     }
 
@@ -308,7 +291,7 @@ public class CaveRepositoryImpl implemen
                 ResourceImpl resource = (ResourceImpl) new DataModelHelperImpl().createResource(filesystem.toURI().toURL());
                 if (resource != null) {
                     // copy the resource
-                    File destination = new File(new File(location), filesystem.getName());
+                    File destination = new File(new File(this.getLocation()), filesystem.getName());
                     LOGGER.debug("Copy from {} to {}", filesystem.getAbsolutePath(), destination.getAbsolutePath());
                     FileUtils.copyFile(filesystem, destination);
                     if (update) {
@@ -350,7 +333,7 @@ public class CaveRepositoryImpl implemen
                         if (index > 0) {
                             url = url.substring(index);
                         }
-                        File destination = new File(new File(location), url);
+                        File destination = new File(new File(this.getLocation()), url);
                         FileOutputStream outputStream = new FileOutputStream(destination);
                         entity.writeTo(outputStream);
                         outputStream.flush();
@@ -388,9 +371,9 @@ public class CaveRepositoryImpl implemen
      */
     private void useResourceRelativeUri(ResourceImpl resource) throws Exception {
         String resourceURI = resource.getURI();
-        LOGGER.debug("Converting resource URI " + resourceURI + " relatively to repository URI " + location);
-        if (resourceURI.startsWith(location)) {
-            resourceURI = resourceURI.substring(location.length());
+        LOGGER.debug("Converting resource URI {} relatively to repository URI {}", resourceURI, this.getLocation());
+        if (resourceURI.startsWith(this.getLocation())) {
+            resourceURI = resourceURI.substring(this.getLocation().length());
             LOGGER.debug("Resource URI converted to " + resourceURI);
             resource.put(Resource.URI, resourceURI);
         }
@@ -404,7 +387,7 @@ public class CaveRepositoryImpl implemen
      * @throws Exception
      */
     private File getRepositoryXmlFile() throws Exception {
-        return new File(new File(location), "repository.xml");
+        return new File(new File(this.getLocation()), "repository.xml");
     }
 
     /**
@@ -424,7 +407,7 @@ public class CaveRepositoryImpl implemen
      * @throws Exception in case of destroy failure.
      */
     public void cleanup() throws Exception {
-        FileUtils.deleteDirectory(new File(location));
+        FileUtils.deleteDirectory(new File(this.getLocation()));
     }
 
 }

Modified: karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/resources/OSGI-INF/blueprint/cave-filesystem-backend.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/resources/OSGI-INF/blueprint/cave-filesystem-backend.xml?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/resources/OSGI-INF/blueprint/cave-filesystem-backend.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/backend/filesystem/src/main/resources/OSGI-INF/blueprint/cave-filesystem-backend.xml Sat Aug 20 06:56:56 2011
@@ -18,7 +18,15 @@
 
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+           xmlns:cxf="http://cxf.apache.org/blueprint/core"
+           xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+           xsi:schemaLocation="
+            http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+            http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
+            http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
+           "
            default-activation="lazy">
 
     <bean id="caveRepositoryService" class="org.apache.karaf.cave.server.backend.impl.CaveRepositoryServiceImpl">
@@ -37,4 +45,11 @@
         </cm:default-properties>
     </cm:property-placeholder>
 
+    <!-- start the JAX-RS server -->
+    <jaxrs:server id="caveRepositoryJaxRsServer" address="/cave">
+        <jaxrs:serviceBeans>
+            <ref component-id="caveRepositoryService"/>
+        </jaxrs:serviceBeans>
+    </jaxrs:server>
+
 </blueprint>
\ No newline at end of file

Modified: karaf/sandbox/jbonofre/cave/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/karaf/sandbox/jbonofre/cave/trunk/server/pom.xml?rev=1159854&r1=1159853&r2=1159854&view=diff
==============================================================================
--- karaf/sandbox/jbonofre/cave/trunk/server/pom.xml (original)
+++ karaf/sandbox/jbonofre/cave/trunk/server/pom.xml Sat Aug 20 06:56:56 2011
@@ -35,7 +35,6 @@
 
     <modules>
         <module>backend</module>
-        <module>rest</module>
         <module>command</module>
     </modules>