Example usage for javax.xml.registry BulkResponse getStatus

List of usage examples for javax.xml.registry BulkResponse getStatus

Introduction

In this page you can find the example usage for javax.xml.registry BulkResponse getStatus.

Prototype

public int getStatus() throws JAXRException;

Source Link

Document

Returns the status for this response.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.SecureSessionPerformanceTest.java

public void testImlicitSave() throws Exception {
    //Create the pkg that is the main object to save explicitly
    String createSecureSession = ProviderProperties.getInstance()
            .getProperty("jaxr-ebxml.security.createSecureSession");
    log.info("jaxr-ebxml.security.createSecureSession: " + createSecureSession);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < 3; i++) {

        //Create RegistryPackage
        ArrayList<RegistryPackage> saveObjects = new ArrayList<RegistryPackage>();
        RegistryPackage pkg = lcm.createRegistryPackage("SecureSessionPerformanceTest.pkg" + i);
        saveObjects.add(pkg);// w  w w . j a v  a 2 s  . c o  m

        //Save RegistryPackage
        BulkResponse br = lcm.saveObjects(saveObjects);
        assertTrue("Package creation failed.", br.getStatus() == BulkResponse.STATUS_SUCCESS);

        //Delete RegistryPackage
        ArrayList<Key> deleteObjects = new ArrayList<Key>();
        deleteObjects.add(pkg.getKey());
        br = lcm.deleteObjects(deleteObjects);
        assertTrue("Package deletion failed.", br.getStatus() == BulkResponse.STATUS_SUCCESS);
    }
    long endTime = System.currentTimeMillis();
    log.info("Time to create and delete 10 objects (millisecs): " + (endTime - startTime));
}

From source file:it.cnr.icar.eric.client.ui.swing.JAXRClient.java

/**
 * DOCUMENT ME!// w w w.  ja  va 2s .c o  m
 *
 * @param resp DOCUMENT ME!
 */
public void checkBulkResponse(BulkResponse resp) {
    try {
        if ((resp != null) && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) {
            Collection<?> exceptions = resp.getExceptions();

            if (exceptions != null) {
                Iterator<?> iter = exceptions.iterator();

                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    RegistryBrowser.displayError(e);
                }
            }
        }
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeTest.java

public void testRemoveRegisteredUser() throws Exception {
    facade.logoff();//from   w  w w .  j  av  a  2s. c  o m

    String alias = user.getKey().getId();
    String keypass = alias;
    facade.logon(alias, keypass);

    //Remove the test user
    //Specify user for deletion using query
    it.cnr.icar.eric.client.xml.registry.infomodel.AdhocQueryImpl ahq = (it.cnr.icar.eric.client.xml.registry.infomodel.AdhocQueryImpl) facade
            .getLifeCycleManager().createObject("AdhocQuery");
    ahq.setString("SELECT u.* FROM User_ u WHERE u.id = '" + user.getKey().getId() + "'");

    //Now do the delete
    BulkResponse br = facade.getLifeCycleManager().deleteObjects(new ArrayList<Object>(), ahq,
            forceRemoveRequestSlotsMap, null);
    assertTrue("User removal failed.", br.getStatus() == BulkResponse.STATUS_SUCCESS);

    //Now make sure that user is indeed removed
    User u = (User) facade.getDeclarativeQueryManager().getRegistryObject(user.getKey().getId(),
            LifeCycleManager.USER);
    assertNull("USer removal failed.", u);

    //A bit of a hack that only works in localCall=true mode. Otherwise the following sub-test is skipped safely.
    //If in localCall mode then make sure that deleting the user aslo deleted the alias/cert in keystore
    //Tests Bug: http://sourceforge.net/tracker/index.php?func=detail&aid=1010978&group_id=37074&atid=418900
    if (((ConnectionImpl) facade.getConnection()).isLocalCallMode()) {
        AuthenticationServiceImpl auth = AuthenticationServiceImpl.getInstance();

        try {
            Certificate serverCert = auth.getCertificate(alias);
            assertTrue("Cert was not deleted from keystore when user was deleted from server.",
                    (null == serverCert));
        } catch (RegistryException e) {
            //Good. Expected.
            //Should really throw a new CertificateNotFoundException.
        }
    }
}

From source file:JAXRSaveClassificationScheme.java

/**
     * Creates a classification scheme and saves it to the
     * registry.//from w  w w  .ja v  a  2  s  .  c  o  m
     *
     * @param username  the username for the registry
     * @param password  the password for the registry
     */
    public void executePublish(String username, String password) {
        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());

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

            ResourceBundle bundle = ResourceBundle.getBundle("JAXRExamples");

            // Create classification scheme
            InternationalString sn = blcm.createInternationalString(bundle.getString("postal.scheme.name"));
            InternationalString sd = blcm.createInternationalString(bundle.getString("postal.scheme.description"));
            ClassificationScheme postalScheme = blcm.createClassificationScheme(sn, sd);

            /*
             * Find the uddi-org:types classification scheme defined
             * by the UDDI specification, using well-known key id.
             */
            String uuid_types = "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4";
            ClassificationScheme uddiOrgTypes = (ClassificationScheme) bqm.getRegistryObject(uuid_types,
                    LifeCycleManager.CLASSIFICATION_SCHEME);

            if (uddiOrgTypes != null) {
                InternationalString cn = blcm
                        .createInternationalString(bundle.getString("postal.classification.name"));
                Classification classification = blcm.createClassification(uddiOrgTypes, cn,
                        bundle.getString("postal.classification.value"));

                postalScheme.addClassification(classification);

                /*
                 * Set link to location of postal scheme (fictitious)
                 * so others can look it up. If the URI were valid, we
                 * could use the createExternalLink method.
                 */
                ExternalLink externalLink = (ExternalLink) blcm.createObject(LifeCycleManager.EXTERNAL_LINK);
                externalLink.setValidateURI(false);
                externalLink.setExternalURI(bundle.getString("postal.scheme.link"));

                InternationalString is = blcm.createInternationalString(bundle.getString("postal.scheme.linkdesc"));
                externalLink.setDescription(is);
                postalScheme.addExternalLink(externalLink);

                // Add scheme and save it to registry
                // Retrieve key if successful
                Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
                schemes.add(postalScheme);

                BulkResponse br = blcm.saveClassificationSchemes(schemes);

                if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
                    System.out.println("Saved PostalAddress " + "ClassificationScheme");

                    Collection schemeKeys = br.getCollection();

                    for (Object k : schemeKeys) {
                        Key key = (Key) k;
                        System.out.println("The postalScheme key is " + key.getId());
                        System.out.println(
                                "Use this key as the scheme uuid " + "in the postalconcepts.xml file\n  and as the "
                                        + "argument to JAXRPublishPostal and " + "JAXRQueryPostal");
                    }
                } else {
                    Collection exceptions = br.getExceptions();

                    for (Object e : exceptions) {
                        Exception exception = (Exception) e;
                        System.err.println("Exception on save: " + exception.toString());
                    }
                }
            } else {
                System.out.println("uddi-org:types not found. Unable to " + "save PostalAddress scheme.");
            }
        } catch (JAXRException jaxe) {
            jaxe.printStackTrace();
        } finally {
            // At end, close connection to registry
            if (connection != null) {
                try {
                    connection.close();
                } catch (JAXRException je) {
                }
            }
        }
    }

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.ExtrinsicObjectImpl.java

public void removeRepositoryItem() throws javax.xml.registry.JAXRException {
    //TODO: mark object as dirty and remove RepositoryItem only on save
    // For now, removin repositoryItem from server immediatelly!
    BulkResponse resp = lcm.deleteObjects(Collections.singletonList(getKey()), null,
            BindingUtility.CANONICAL_DELETION_SCOPE_TYPE_ID_DeleteRepositoryItemOnly);
    if (BulkResponse.STATUS_SUCCESS == resp.getStatus()) {
        // This should be defined in JAXR 2.0 spec
        this.mimeType = null;
        this.repositoryItem = null;
    } else {//w ww  .j a v  a  2  s  .  co m
        Exception e = (Exception) resp.getExceptions().iterator().next();
        throw new JAXRException(i18nUtil.getString("repositoryitem.removefailed", new String[] { getId() }), e);
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeImpl.java

/**
 * Publishes a repositoryItem and the metadata that describes it.    
 *
 * @param repositoryItem the URL to the repositoryItem being published.
 * @param metadata describing the repositoryItem
 *
 * @return the ExtrinsicObject published as metadata.
 * @see it.cnr.icar.eric.common.CanonicalConstants for constants that may be used to identify keys in metadaat HashMap 
 *///ww  w.  ja  v  a  2 s  .  c o m
@SuppressWarnings("static-access")
public ExtrinsicObject publish(URL repositoryItem, Map<?, ?> metadata) throws JAXRException {
    ExtrinsicObjectImpl eo = null;

    if (lcm == null) {
        throw new JAXRException("setEndpoint MUST be called before setCredentials is called.");
    }

    javax.activation.DataSource ds = new javax.activation.URLDataSource(repositoryItem);
    javax.activation.DataHandler dh = new javax.activation.DataHandler(ds);

    eo = (ExtrinsicObjectImpl) lcm.createExtrinsicObject(dh);

    String id = (String) metadata.remove(bu.CANONICAL_SLOT_IDENTIFIABLE_ID);
    String name = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_NAME);
    String description = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_DESCRIPTION);
    String objectType = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE);
    String mimeType = (String) metadata.remove(bu.CANONICAL_SLOT_EXTRINSIC_OBJECT_MIMETYPE);

    //If id is specified then use it.
    if (id != null) {
        eo.setKey(lcm.createKey(id));
        eo.setLid(id);
    }

    @SuppressWarnings("unused")
    String eoId = eo.getKey().getId();

    //If name is specified then use it.
    if (name != null) {
        eo.setName(lcm.createInternationalString(name));
    }

    //If description is specified then use it.
    if (description != null) {
        eo.setDescription(lcm.createInternationalString(description));
    }

    if (objectType == null) {
        throw new InvalidRequestException(
                JAXRResourceBundle.getInstance().getString("message.error.missingMetadata",
                        new Object[] { bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE }));
    }

    if (mimeType == null) {
        throw new InvalidRequestException(JAXRResourceBundle.getInstance().getString(
                "message.error.missingMetadata", new Object[] { bu.CANONICAL_SLOT_EXTRINSIC_OBJECT_MIMETYPE }));
    }

    eo.setMimeType(mimeType);
    eo.setObjectTypeRef(new RegistryObjectRef(lcm, objectType));

    //Set any remaining metadata properties as Slots
    JAXRUtility.addSlotsToRegistryObject(eo, metadata);

    ArrayList<RegistryObject> objects = new ArrayList<RegistryObject>();
    objects.add(eo);

    BulkResponse br = lcm.saveObjects(objects, dontVersionSlotsMap);
    if (br.getExceptions() != null) {
        throw new JAXRException("Error publishing to registry", (Exception) (br.getExceptions().toArray()[0]));
    }

    if (br.getStatus() != BulkResponse.STATUS_SUCCESS) {
        throw new JAXRException("Error publishing to registry. See server logs for detils.");
    }

    return eo;
}

From source file:it.cnr.icar.eric.client.xml.registry.RegistryFacadeImpl.java

@SuppressWarnings({ "unused", "static-access" })
public ExtrinsicObject publishFilesAsZip(String baseDirectory, String[] relativeFilePaths, Map<?, ?> metadata)
        throws JAXRException {

    ExtrinsicObjectImpl eo = null;//from  ww  w .ja v a 2  s  .  co m
    if (getLifeCycleManager() == null) {
        throw new JAXRException("setEndpoint MUST be called before setCredentials is called.");
    }

    try {
        //Create the zip file
        File zipFile = File.createTempFile("eric-RegistryFacadeImpl", ".zip");
        zipFile.deleteOnExit();
        FileOutputStream fos = new FileOutputStream(zipFile);
        ZipOutputStream zos = Utility.createZipOutputStream(baseDirectory, relativeFilePaths, fos);
        zos.close();

        javax.activation.DataSource ds = new javax.activation.FileDataSource(zipFile);
        javax.activation.DataHandler dh = new javax.activation.DataHandler(ds);

        if (dh == null) {
            throw new JAXRException("Error processing zip file" + zipFile.getAbsolutePath());
        }

        eo = (ExtrinsicObjectImpl) getLifeCycleManager().createExtrinsicObject(dh);

        String id = (String) metadata.remove(bu.CANONICAL_SLOT_IDENTIFIABLE_ID);
        String name = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_NAME);
        String description = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_DESCRIPTION);
        String objectType = (String) metadata.remove(bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE);

        //If id is specified then use it.
        if (id != null) {
            eo.setKey(lcm.createKey(id));
            eo.setLid(id);
        }

        String eoId = eo.getKey().getId();

        //If name is specified then use it.
        if (name != null) {
            eo.setName(lcm.createInternationalString(name));
        }

        //If description is specified then use it.
        if (description != null) {
            eo.setDescription(lcm.createInternationalString(description));
        }

        if (objectType == null) {
            throw new InvalidRequestException(
                    JAXRResourceBundle.getInstance().getString("message.error.missingMetadata",
                            new Object[] { bu.CANONICAL_SLOT_REGISTRY_OBJECT_OBJECTTYPE }));
        }

        eo.setMimeType("application/zip");
        eo.setObjectTypeRef(new RegistryObjectRef(getLifeCycleManager(), objectType));

        ArrayList<RegistryObject> objects = new ArrayList<RegistryObject>();
        objects.add(eo);

        //??Turn of versioning on save as it creates problems

        BulkResponse br = getLifeCycleManager().saveObjects(objects, dontVersionSlotsMap);
        if (br.getExceptions() != null) {
            throw new JAXRException("Error publishing to registry",
                    (Exception) (br.getExceptions().toArray()[0]));
        }

        if (br.getStatus() != BulkResponse.STATUS_SUCCESS) {
            throw new JAXRException("Error publishing to registry. See server logs for detils.");
        }
    } catch (IOException e) {
        throw new JAXRException(e);
    }

    return eo;
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistrationInfoBean.java

public String doRegister() {
    log.trace("doRegister started");
    String result = "unknown";
    FacesContext context = FacesContext.getCurrentInstance();

    if (!doCheckAuthDetails()) {
        return result;
    }/* ww  w  . jav a  2  s .  c om*/

    try {
        User user = (User) RegistryObjectCollectionBean.getInstance().getCurrentRegistryObjectBean()
                .getRegistryObject();
        Collection<?> emails = user.getEmailAddresses();
        ArrayList<EmailAddress> newList = new ArrayList<EmailAddress>();

        Iterator<?> iters = emails.iterator();
        while (iters.hasNext()) {
            EmailAddress email = (EmailAddress) iters.next();
            if (null != email.getAddress() && email.getAddress().length() > 0) {
                newList.add(email);
            }
        }
        user.setEmailAddresses(newList);

        List<User> users = new ArrayList<User>();
        users.add(user);
        BusinessLifeCycleManagerImpl blcm = RegistryBrowser.getBLCM();
        handleAuth();
        log.trace("calling saveObjects()");
        BulkResponse resp = blcm.saveObjects(users);
        log.trace("saveObjects() returned");
        if ((resp != null) && (resp.getStatus() != JAXRResponse.STATUS_SUCCESS)) {
            Collection<?> exceptions = resp.getExceptions();
            if (exceptions != null && !exceptions.isEmpty()) {
                String msg = WebUIResourceBundle.getInstance().getString("errorRegistrationNeeded");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                log.error(msg);

                Iterator<?> iter = exceptions.iterator();
                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    OutputExceptions.error(log, e);
                }
            } else {
                String msg = WebUIResourceBundle.getInstance().getString("registrationFailed");
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
                log.error(WebUIResourceBundle.getInstance().getString("message.RegistrationFailed"));
            }
            result = "error";
        } else {
            // ??? Is (null == resp) really success?
            result = "registered";
            doNext();
        }
    } catch (Throwable t) {
        OutputExceptions.error(log, WebUIResourceBundle.getInstance().getString("message.RegistrationFailed"),
                WebUIResourceBundle.getInstance().getString("registrationFailed"), t);
        result = "error";
    } finally {
        try {
            RegistryBrowser.getInstance().clearCredentials();
        } catch (Throwable t) {
            // User doesn't need to hear about a cleanup problem
            OutputExceptions.logWarning(log,
                    WebUIResourceBundle.getInstance().getString("message.couldNotClearCredentials"), t);
        }
    }

    return result;
}

From source file:it.cnr.icar.eric.client.ui.thin.RelationshipBean.java

/**
 * This method return String if Relation between two RegistryObjects 
 * happend sucessfully/*from w w  w  .j  a  v  a  2s .  co m*/
 * @return String
 */
public String doApplyReference() {
    String status = "failure";
    ArrayList<RegistryObject> roList = new ArrayList<RegistryObject>();
    BulkResponse br = null;
    try {
        @SuppressWarnings("static-access")
        BusinessLifeCycleManagerImpl blcm = RegistryBrowser.getInstance().getBLCM();
        this.setSourceTargetObject(sourceType);
        if (refAss == null) {
            this.createReferenceAssociation();
        }
        if (refAttribute == null) {
            refAss.setReferenceAttribute(this.objectType);
        } else {
            refAss.setReferenceAttribute(this.refAttribute);
        }
        refAss.setReferenceAttributeOnSourceObject();
        roList.add(sourceRegistryObject);
        roList.add(targetRegistryObject);
        br = blcm.saveObjects(roList);
        if (br.getStatus() == 0) {
            status = "relationSuccessful";
        }
    } catch (Exception ex) {
        log.error(WebUIResourceBundle.getInstance()
                .getString("message.errorOccuredWhileDoingDoSaveRefrenceOperation"), ex);
    }
    return status;
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

/**
 * DOCUMENT ME!// ww  w. j  a  v a  2  s .c  o  m
 */
@SuppressWarnings("unchecked")
protected void removeAction() {
    RegistryBrowser.setWaitCursor();

    int[] selectedIndices = getSelectedRows();

    if (selectedIndices.length >= 1) {
        try {
            ArrayList<?> selectedObjects = getSelectedRegistryObjects();
            ArrayList<Key> removeKeys = new ArrayList<Key>();

            int size = selectedObjects.size();

            for (int i = size - 1; i >= 0; i--) {
                RegistryObject obj = (RegistryObject) selectedObjects.get(i);
                Key key = obj.getKey();
                removeKeys.add(key);
            }

            // Confirm the remove
            boolean confirmRemoves = true;
            // I18N: Do not localize next statement.
            String confirmRemovesStr = ProviderProperties.getInstance()
                    .getProperty("jaxr-ebxml.registryBrowser.confirmRemoves", "true");

            if (confirmRemovesStr.equalsIgnoreCase("false") || confirmRemovesStr.toLowerCase().equals("off")) {
                confirmRemoves = false;
            }

            if (confirmRemoves) {
                int option = JOptionPane.showConfirmDialog(null,
                        resourceBundle.getString("dialog.confirmRemove.text"),
                        resourceBundle.getString("dialog.confirmRemove.title"), JOptionPane.YES_NO_OPTION);

                if (option == JOptionPane.NO_OPTION) {
                    RegistryBrowser.setDefaultCursor();

                    return;
                }
            }

            // cancels the cell editor, if any
            removeEditor();

            JAXRClient client = RegistryBrowser.getInstance().getClient();
            BusinessLifeCycleManager lcm = client.getBusinessLifeCycleManager();
            BulkResponse resp = lcm.deleteObjects(removeKeys);
            client.checkBulkResponse(resp);

            if (resp.getStatus() == JAXRResponse.STATUS_SUCCESS) {
                //Remove from UI model
                @SuppressWarnings("rawtypes")
                ArrayList objects = (ArrayList) ((tableModel.getRegistryObjects()).clone());
                size = selectedIndices.length;

                for (int i = size - 1; i >= 0; i--) {
                    RegistryObject ro = (RegistryObject) dataModel.getValueAt(selectedIndices[i], -1);
                    objects.remove(ro);
                }

                tableModel.setRegistryObjects(objects);
            }
        } catch (JAXRException e) {
            RegistryBrowser.displayError(e);
        }
    } else {
        RegistryBrowser.displayError(resourceBundle.getString("error.removeAction"));
    }

    RegistryBrowser.setDefaultCursor();
}