karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-3827) Cave rest service doesn't retrieve the repositories
Date Wed, 15 Nov 2017 09:47:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-3827?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253195#comment-16253195
] 

ASF GitHub Bot commented on KARAF-3827:
---------------------------------------

jbonofre closed pull request #6: [KARAF-3827] - Fix Cave rest service doesn't retrieve the
repositories
URL: https://github.com/apache/karaf-cave/pull/6
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/rest/pom.xml b/server/rest/pom.xml
index b78a3d9..414189e 100644
--- a/server/rest/pom.xml
+++ b/server/rest/pom.xml
@@ -47,6 +47,10 @@
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.karaf</groupId>
+            <artifactId>org.apache.karaf.util</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
@@ -61,6 +65,9 @@
                 <configuration>
                     <instructions>
                         <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Private-Package>
+                            org.apache.karaf.util
+                        </Private-Package>
                     </instructions>
                 </configuration>
             </plugin>
diff --git a/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Repository.java b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Repository.java
index 8e1a38a..aca0b5e 100644
--- a/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Repository.java
+++ b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Repository.java
@@ -16,21 +16,145 @@
  */
 package org.apache.karaf.cave.server.rest;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
 
 import org.apache.karaf.cave.server.api.CaveRepository;
+import org.apache.karaf.util.XmlUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 @XmlRootElement(name = "cave-repository")
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlType(name = "Repository", propOrder = {"name", "increment", "location", "resources"})
 public class Repository {
 
-    private final CaveRepository repository;
-
+    @XmlElement(name = "name")
+    private String name;
+    @XmlElement(name = "increment")
+    private long increment;
+    @XmlElement(name = "location")
+    private String location;
+    @XmlElement(name = "resources")
+    private List<Resource> resources;
+    
     public Repository() {
-        repository = null;
+        // require for JABX IllegalAnnotationExceptions
     }
 
     public Repository(CaveRepository repository) {
-        this.repository = repository;
+        this.name = repository.getName();
+        this.increment = repository.getIncrement();
+        this.location = repository.getLocation();
+
+        try {
+            Document doc = XmlUtils.parse(repository.getRepositoryXml().toExternalForm());
+
+            // get all resource elements
+            NodeList resourceList = doc.getElementsByTagName("resource");
+
+            if (resourceList.getLength() > 0) {
+                this.resources = new ArrayList<>();
+            }
+
+            // read resource
+            for (int vI = 0; vI < resourceList.getLength(); vI++) {
+
+                Element nodeResource = (Element) resourceList.item(vI);
+                Resource resource = new Resource();
+
+                NodeList capabilityList = nodeResource.getElementsByTagName("capability");
+
+                // read capability
+                for (int vInt = 0; vInt < capabilityList.getLength(); vInt++) {
+
+                    Element capability = (Element) capabilityList.item(vInt);
+
+                    if (capability.hasAttribute("namespace")) {
+
+                        Element attribute = (Element) capability.getFirstChild();
+
+                        while (attribute != null) {
+
+                            if (capability.getAttribute("namespace").equals("osgi.identity"))
{
+
+                                switch (attribute.getAttribute("name")) {
+                                    case "osgi.identity":
+                                        resource.setIdentity(attribute.getAttribute("value"));
+                                        break;
+                                    case "type":
+                                        resource.setType(attribute.getAttribute("value"));
+                                        break;
+                                    case "version":
+                                        resource.setVersion(attribute.getAttribute("value"));
+                                        break;
+                                    default:
+                                        break;
+                                }
+
+                            } else if (capability.getAttribute("namespace")
+                                    .equals("osgi.content")) {
+                                switch (attribute.getAttribute("name")) {
+                                    case "url":
+                                        // name of the artefact, the baseURI of the HttpServlet
+                                        // for download is not available
+                                        resource.setArtefact(attribute.getAttribute("value"));
+                                        break;
+                                    default:
+                                        break;
+                                }
+                            }
+
+                            attribute = (Element) attribute.getNextSibling();
+                        }
+                    }
+                }
+
+                getResources().add(resource);
+            }
+
+        } catch (Exception exception) {
+            // do nothing
+        }
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setName(String nameIn) {
+        name = nameIn;
+    }
+
+    public long getIncrement() {
+        return increment;
+    }
+
+    public void setIncrement(long incrementIn) {
+        increment = incrementIn;
+    }
+
+    public List<Resource> getResources() {
+        return resources;
+    }
+
+    public void setResources(List<Resource> resourcesIn) {
+        resources = resourcesIn;
+    }
+    
+    public String getLocation() {
+        return location;
+    }
+
+    public void setLocation(String locationIn) {
+        location = locationIn;
     }
 
 }
diff --git a/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Resource.java b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Resource.java
new file mode 100644
index 0000000..a26e193
--- /dev/null
+++ b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Resource.java
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.karaf.cave.server.rest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement(name = "resource")
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlType(name = "Resource", propOrder = {"identity", "type", "version", "artefact"})
+public class Resource {
+
+    @XmlElement(name = "identity")
+    private String identity;
+    @XmlElement(name = "type")
+    private String type;
+    @XmlElement(name = "version")
+    private String version;
+    @XmlElement(name = "artefact")
+    private String artefact;
+
+
+    public String getIdentity() {
+        return identity;
+    }
+
+    public void setIdentity(String pIdentity) {
+        identity = pIdentity;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String pType) {
+        type = pType;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String pVersion) {
+        version = pVersion;
+    }
+
+    public String getArtefact() {
+        return artefact;
+    }
+
+    public void setArtefact(String pArtefact) {
+        artefact = pArtefact;
+    }
+}
diff --git a/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Service.java b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Service.java
index bf190ef..f2b7fd6 100644
--- a/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Service.java
+++ b/server/rest/src/main/java/org/apache/karaf/cave/server/rest/Service.java
@@ -16,12 +16,13 @@
  */
 package org.apache.karaf.cave.server.rest;
 
-import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 
 import org.apache.karaf.cave.server.api.CaveRepository;
 import org.apache.karaf.cave.server.api.CaveRepositoryService;
@@ -47,9 +48,9 @@ public Service(CaveRepositoryService service) {
      * @throws Exception in case of creation failure.
      */
     @POST
-    @Consumes("application/xml")
-    @Produces("application/xml")
-    public Repository create(String name, boolean scan) throws Exception {
+    @Path("/repositories")
+    @Produces("application/json")
+    public Repository create(@QueryParam(value = "name") String name, @QueryParam(value =
"scan") boolean scan) throws Exception {
         return new Repository(service.create(name, scan));
     }
 
@@ -63,9 +64,9 @@ public Repository create(String name, boolean scan) throws Exception {
      * @throws Exception in case of creation failure.
      */
     @POST
-    @Consumes("application/xml")
-    @Produces("application/xml")
-    public Repository create(String name, String location, boolean scan) throws Exception
{
+    @Path("/repositories")
+    @Produces("application/json")
+    public Repository create(@QueryParam(value = "name") String name, @QueryParam(value =
"location") String location, @QueryParam(value = "scan") boolean scan) throws Exception {
         return new Repository(service.create(name, location, scan));
     }
 
@@ -75,7 +76,9 @@ public Repository create(String name, String location, boolean scan) throws
Exce
      * @param name the name of the repository.
      * @throws Exception in case of uninstall failure.
      */
-    public void uninstall(String name) throws Exception {
+    @POST
+    @Path("/uninstall")
+    public void uninstall(@QueryParam(value = "name") String name) throws Exception {
         service.uninstall(name);
     }
 
@@ -85,7 +88,9 @@ public void uninstall(String name) throws Exception {
      * @param name the name of the repository.
      * @throws Exception in case of remove failure.
      */
-    public void remove(String name) throws Exception {
+    @POST
+    @Path("/remove")
+    public void remove(@QueryParam(value = "name") String name) throws Exception {
         service.remove(name);
     }
 
@@ -95,7 +100,9 @@ public void remove(String name) throws Exception {
      * @param name the name of the repository.
      * @throws Exception incase of remove failure.
      */
-    public void destroy(String name) throws Exception {
+    @DELETE
+    @Path("/repositories")
+    public void destroy(@QueryParam(value = "name") String name) throws Exception {
         service.destroy(name);
     }
 
@@ -106,8 +113,8 @@ public void destroy(String name) throws Exception {
      * @throws Exception in case of registration failure.
      */
     @POST
-    @Consumes("text/plain")
-    public void install(String name) throws Exception {
+    @Path("/install")
+    public void install(@QueryParam(value = "name") String name) throws Exception {
         service.install(name);
     }
 
@@ -118,13 +125,14 @@ public void install(String name) throws Exception {
      */
     @GET
     @Path("/repositories")
-    @Produces("application/xml")
+    @Produces("application/json")
     public Repository[] getRepositories() {
         CaveRepository[] repositories = service.getRepositories();
         Repository[] repos = new Repository[repositories.length];
         for (int i = 0; i < repositories.length; i++) {
             repos[i] = new Repository(repositories[i]);
         }
+        
         return repos;
     }
 
@@ -136,7 +144,7 @@ public void install(String name) throws Exception {
      */
     @GET
     @Path("/repositories/{name}")
-    @Produces("application/xml")
+    @Produces("application/json")
     public Repository getRepository(@PathParam("name") String name) {
         CaveRepository repository = service.getRepository(name);
         if (repository != null) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Cave rest service doesn't retrieve the repositories
> ---------------------------------------------------
>
>                 Key: KARAF-3827
>                 URL: https://issues.apache.org/jira/browse/KARAF-3827
>             Project: Karaf
>          Issue Type: Bug
>          Components: cave-rest
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>             Fix For: cave-4.0.1
>
>
> Even if a repository exists:
> {code}
> karaf@root()> cave:repositories 
> Name          | Location
> -----------------------------------------------------------------------------
> my-repository | /home/jbonofre/bin/apache-karaf-4.0.0/data/cave/my-repository
> {code}
> accessing the Cave REST API on:
> {code}
> http://localhost:8181/cave/rest/repositories
> {code}
> just give:
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <cave-repositorys><cave-repository/></cave-repositorys>
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message