예제 #1
0
  /**
   * Creates an entry in the group. In a case the group does not exist already it will be
   * automatically created.
   *
   * @param entryStream the input stream corresponding to the content of the registry entry
   * @param groupName the relative path to the group
   * @request {code} "entryStream" : the input stream corresponding to the content of the registry
   *     entry {code} Example : {code:xml} <registry
   *     xlinks:href="http://localhost:8080/portal/rest/registry/"> <GroovyScript2RestLoader
   *     xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/GroovyScript2RestLoader"/>
   *     <Audit xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/Audit"/>
   *     </registry> {code} @LevelAPI Experimental
   */
  @POST
  @Path("/{groupName:.+}")
  @Consumes(MediaType.APPLICATION_XML)
  public Response createEntry(
      InputStream entryStream, @PathParam("groupName") String groupName, @Context UriInfo uriInfo) {

    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      RegistryEntry entry = RegistryEntry.parse(entryStream);
      regService.createEntry(sessionProvider, normalizePath(groupName), entry);
      URI location = uriInfo.getRequestUriBuilder().path(entry.getName()).build();
      return Response.created(location).build();
    } catch (IllegalArgumentException e) {
      LOG.error("Create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (IOException e) {
      LOG.error("Create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (SAXException e) {
      LOG.error("Create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (ParserConfigurationException e) {
      LOG.error("Create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (RepositoryException e) {
      LOG.error("Create registry entry failed", e);
      throw new WebApplicationException(e);
    }
  }
예제 #2
0
  /**
   * Removes the entry at the given absolute path (concatenation of group path / entry name)
   *
   * @param entryPath the absolute path of the entry to remove @LevelAPI Experimental
   */
  @DELETE
  @Path("/{entryPath:.+}")
  public Response removeEntry(@PathParam("entryPath") String entryPath) {

    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      regService.removeEntry(sessionProvider, normalizePath(entryPath));
      return null; // minds status 204 'No content'
    } catch (PathNotFoundException e) {
      return Response.status(Response.Status.NOT_FOUND).build();
    } catch (Exception e) {
      LOG.error("Remove registry entry failed", e);
      throw new WebApplicationException(e);
    }
  }
예제 #3
0
  @Override
  public void setUp() throws Exception {

    super.setUp();
    this.sessionProviderService =
        (ThreadLocalSessionProviderService)
            container.getComponentInstanceOfType(ThreadLocalSessionProviderService.class);
    sessionProviderService.setSessionProvider(
        null, new SessionProvider(ConversationState.getCurrent()));
    restRegService =
        (RESTRegistryService) container.getComponentInstanceOfType(RESTRegistryService.class);
    binder = (ResourceBinder) container.getComponentInstanceOfType(ResourceBinder.class);
    handler = (RequestHandler) container.getComponentInstanceOfType(RequestHandler.class);

    baseUri = new URI("http://localhost:8080/rest");
  }
예제 #4
0
  /**
   * Returns the corresponding registry entry which wraps a node of type "exo:registryEntry"
   *
   * @param entryPath The relative path to the registry entry
   * @response {code} "entryStream" : the output stream corresponding registry entry which wraps a
   *     node of type "exo:registryEntry {code} Example : {code:xml} <Audit
   *     jcr:primaryType="exo:registryEntry"> <adminIdentity jcr:primaryType="nt:unstructured"
   *     value="*:/Platform/Administrators"/> </Audit> {code} @LevelAPI Experimental
   */
  @GET
  @Path("/{entryPath:.+}")
  @Produces(MediaType.APPLICATION_XML)
  public Response getEntry(@PathParam("entryPath") String entryPath) {

    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      RegistryEntry entry;
      entry = regService.getEntry(sessionProvider, normalizePath(entryPath));
      return Response.ok(new DOMSource(entry.getDocument())).build();
    } catch (PathNotFoundException e) {
      return Response.status(Response.Status.NOT_FOUND).build();
    } catch (RepositoryException e) {
      LOG.error("Get registry entry failed", e);
      throw new WebApplicationException(e);
    }
  }
예제 #5
0
  /**
   * Returns the registry node which wraps a node of type "exo:registry" (the whole registry tree)
   *
   * @response {code} "entryStream" : the output stream corresponding registry node which wraps a
   *     node of type "exo:registry" (the whole registry tree) {code} Example : {code:xml} <registry
   *     xlinks:href="http://localhost:8080/portal/rest/registry/"> <GroovyScript2RestLoader
   *     xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/GroovyScript2RestLoader"/>
   *     <Audit xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/Audit"/>
   *     </registry> {code} @LevelAPI Experimental
   */
  @GET
  @Produces(MediaType.APPLICATION_XML)
  public Response getRegistry(@Context UriInfo uriInfo) {
    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      RegistryNode registryEntry = regService.getRegistry(sessionProvider);
      if (registryEntry != null) {
        Node registryNode = registryEntry.getNode();
        NodeIterator registryIterator = registryNode.getNodes();
        Document entry =
            SecurityHelper.doPrivilegedExceptionAction(
                new PrivilegedExceptionAction<Document>() {
                  public Document run() throws Exception {
                    return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                  }
                });

        String fullURI = uriInfo.getRequestUri().toString();
        XlinkHref xlinkHref = new XlinkHref(fullURI);
        Element root = entry.createElement(REGISTRY);
        xlinkHref.putToElement(root);
        while (registryIterator.hasNext()) {
          NodeIterator entryIterator = registryIterator.nextNode().getNodes();
          while (entryIterator.hasNext()) {
            Node node = entryIterator.nextNode();
            Element xmlNode = entry.createElement(node.getName());
            xlinkHref.putToElement(xmlNode, node.getPath().substring(EXO_REGISTRY.length()));
            root.appendChild(xmlNode);
          }
        }
        entry.appendChild(root);
        return Response.ok(new DOMSource(entry), "text/xml").build();
      }
      return Response.status(Response.Status.NOT_FOUND).build();
    } catch (Exception e) {
      LOG.error("Get registry failed", e);
      throw new WebApplicationException(e);
    }
  }