Ejemplo n.º 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);
    }
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 3
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);
    }
  }
Ejemplo n.º 4
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);
    }
  }
  /**
   * Creates an organization, its classification, and its services, and saves it to the registry.
   */
  public String executePublish(String username, String password, String endpoint) {

    String id = null;
    RegistryService rs = null;
    BusinessLifeCycleManager blcm = null;
    BusinessQueryManager bqm = null;

    try {
      rs = connection.getRegistryService();
      blcm = rs.getBusinessLifeCycleManager();
      bqm = rs.getBusinessQueryManager();
      System.out.println("Got registry service, query " + "manager, and life cycle manager");

      // Get authorization from the registry
      PasswordAuthentication passwdAuth =
          new PasswordAuthentication(username, password.toCharArray());

      Set creds = new HashSet();
      creds.add(passwdAuth);
      connection.setCredentials(creds);
      System.out.println("Established security credentials");

      // Get hardcoded strings from a ResourceBundle
      ResourceBundle bundle = ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");

      // Create organization name and description
      Organization org = blcm.createOrganization(bundle.getString("org.name"));
      InternationalString s = blcm.createInternationalString(bundle.getString("org.description"));
      org.setDescription(s);

      // Create primary contact, set name
      User primaryContact = blcm.createUser();
      PersonName pName = blcm.createPersonName(bundle.getString("person.name"));
      primaryContact.setPersonName(pName);

      // Set primary contact phone number
      TelephoneNumber tNum = blcm.createTelephoneNumber();
      tNum.setNumber(bundle.getString("phone.number"));
      Collection phoneNums = new ArrayList();
      phoneNums.add(tNum);
      primaryContact.setTelephoneNumbers(phoneNums);

      // Set primary contact email address
      EmailAddress emailAddress = blcm.createEmailAddress(bundle.getString("email.address"));
      Collection emailAddresses = new ArrayList();
      emailAddresses.add(emailAddress);
      primaryContact.setEmailAddresses(emailAddresses);

      // Set primary contact for organization
      org.setPrimaryContact(primaryContact);

      // Set classification scheme to NAICS
      ClassificationScheme cScheme =
          bqm.findClassificationSchemeByName(null, bundle.getString("classification.scheme"));

      // Create and add classification
      Classification classification =
          (Classification)
              blcm.createClassification(
                  cScheme,
                  bundle.getString("classification.name"),
                  bundle.getString("classification.value"));
      Collection classifications = new ArrayList();
      classifications.add(classification);
      org.addClassifications(classifications);

      // Create services and service
      Collection services = new ArrayList();
      Service service = blcm.createService(bundle.getString("service.name"));
      InternationalString is =
          blcm.createInternationalString(bundle.getString("service.description"));
      service.setDescription(is);

      // Create service bindings
      Collection serviceBindings = new ArrayList();
      ServiceBinding binding = blcm.createServiceBinding();
      is = blcm.createInternationalString(bundle.getString("service.binding"));
      binding.setDescription(is);
      binding.setValidateURI(false);
      binding.setAccessURI(endpoint);
      serviceBindings.add(binding);

      // Add service bindings to service
      service.addServiceBindings(serviceBindings);

      // Add service to services, then add services to organization
      services.add(service);
      org.addServices(services);

      // Add organization and submit to registry
      // Retrieve key if successful
      Collection orgs = new ArrayList();
      orgs.add(org);
      BulkResponse response = blcm.saveOrganizations(orgs);
      Collection exceptions = response.getExceptions();
      if (exceptions == null) {
        System.out.println("Organization saved");

        Collection keys = response.getCollection();
        Iterator keyIter = keys.iterator();
        if (keyIter.hasNext()) {
          javax.xml.registry.infomodel.Key orgKey =
              (javax.xml.registry.infomodel.Key) keyIter.next();
          id = orgKey.getId();
          System.out.println("Organization key is " + id);
        }
      } else {
        Iterator excIter = exceptions.iterator();
        Exception exception = null;
        while (excIter.hasNext()) {
          exception = (Exception) excIter.next();
          System.err.println("Exception on save: " + exception.toString());
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      if (connection != null) {
        try {
          connection.close();
        } catch (JAXRException je) {
          System.err.println("Connection close failed");
        }
      }
    }
    return id;
  }