Example usage for javax.xml.registry RegistryException RegistryException

List of usage examples for javax.xml.registry RegistryException RegistryException

Introduction

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

Prototype

public RegistryException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:it.cnr.icar.eric.server.security.authorization.RegistryPolicyFinderModule.java

private AbstractPolicy loadPolicy(ServerRequestContext requestContext, String id) throws RegistryException {
    if (log.isDebugEnabled()) {
        log.debug("Loading policy for id=" + id);
    }//  www.j a va  2 s .co  m

    AbstractPolicy policy = null;
    RepositoryItem ri = null;

    if (id == null) {
        return policy;
    }

    if ((id.equalsIgnoreCase(idForDefaultACP)) && (defaultPolicy != null)) {
        return defaultPolicy;
    }

    //First check if it is in the repository as a top level Policy
    try {
        ri = rm.getRepositoryItem(id);
    } catch (RegistryException e) {
        log.debug(e, e);
    }

    //Not found as top level repository item
    //See if it is a composed policy within a top level policy in repository 
    if (ri == null) {
        //No policy found. Next find an ACP with specified URI as
        //a value for a Slot named "ComposedPolicies".
        AbstractPolicy rootPolicy = loadRootPolicyFor(requestContext, id);

        try {
            if (rootPolicy != null) {
                PolicyTreeElement policyElement = getDescendantPolicyTreeElement(rootPolicy, new URI(id));

                if (policyElement instanceof AbstractPolicy) {
                    policy = (AbstractPolicy) policyElement;
                }
            }
        } catch (URISyntaxException e) {
            throw new RegistryException(e);
        }
    } else {
        DataHandler dh = ri.getDataHandler();
        policy = loadPolicy(dh, finder);
    }

    return policy;
}

From source file:it.cnr.icar.eric.server.repository.hibernate.HibernateRepositoryManager.java

/**
 * Insert the repository item./*from   w w  w . j  a v a  2 s . co m*/
 * @param item The repository item.
 */
public void insert(ServerRequestContext context, RepositoryItem item) throws RegistryException {
    Transaction tx = null;

    ExtrinsicObjectType eo = (ExtrinsicObjectType) context.getRegistryObject(item.getId(), "ExtrinsicObject");
    String lid = eo.getLid();
    String versionName = null;

    try {
        SessionContext sc = hu.getSessionContext();
        Session s = sc.getSession();
        tx = s.beginTransaction();

        VersionInfoType contentVersionInfo = eo.getContentVersionInfo();
        if (contentVersionInfo == null) {
            contentVersionInfo = bu.rimFac.createVersionInfoType();
            eo.setContentVersionInfo(contentVersionInfo);
        }
        versionName = eo.getContentVersionInfo().getVersionName();

        // if item already exists, error
        String findByID = "from RepositoryItemBean as rib where rib.key.lid = ? AND rib.key.versionName = ? ";
        Object[] params = { lid, versionName };

        Type[] types = { Hibernate.STRING, Hibernate.STRING };

        List<?> results = s.find(findByID, params, types);
        if (!results.isEmpty()) {
            String errmsg = ServerResourceBundle.getInstance().getString(
                    "message.RepositoryItemWithIdAndVersionAlreadyExist", new Object[] { lid, versionName });
            log.error(errmsg);
            throw new RegistryException(errmsg);
        }

        // Writing out the RepositoryItem itself
        byte contentBytes[] = readBytes(item.getDataHandler().getInputStream());

        RepositoryItemBean bean = new RepositoryItemBean();
        RepositoryItemKey key = new RepositoryItemKey(lid, versionName);
        bean.setKey(key);

        if (needsOracleHack) {
            doOracleHackForInsert(s, bean, contentBytes);
            // do not call save after this
        } else {
            if (isBlobSupported) {
                bean.setBlobContent(Hibernate.createBlob(contentBytes));
            } else {
                bean.setBinaryContent(contentBytes);
            }
        }

        if (log.isDebugEnabled()) {
            String message = "Inserting repository item:" + "lid='" + key.getLid() + "', " + "versionName='"
                    + key.getVersionName() + "', ";
            if (isBlobSupported) {
                message += "content size=" + bean.getBlobContent().length();
            } else {
                message += "content size=" + bean.getBinaryContent().length;
            }
            log.debug(message);
        }

        if (!needsOracleHack) {
            s.save(bean);
        }

        tx.commit();
        s.refresh(bean);

    } catch (RegistryException e) {
        tryRollback(tx);
        throw e;
    } catch (Exception e) {
        String msg = ServerResourceBundle.getInstance().getString("message.FailedToInsertRepositoryItem",
                new Object[] { item.getId() });
        log.error(e, e);
        tryRollback(tx);
        throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails",
                new Object[] { msg }));
    } finally {
        tryClose();
    }
}

From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java

/**
 * Does a bulk delete of a Collection of objects that match the type for this persister.
 *
 *///  www  . j  a v  a 2 s .  c  o m
public void delete(@SuppressWarnings("rawtypes") List objects) throws RegistryException {
    //Return immediatley if no objects to insert
    if (objects.size() == 0) {
        return;
    }

    log.trace(ServerResourceBundle.getInstance().getString("message.DeletingRowsInTable",
            new Object[] { new Integer(objects.size()), getTableName() }));
    action = DAO_ACTION_DELETE;

    Statement stmt = null;

    try {
        stmt = context.getConnection().createStatement();
        @SuppressWarnings("rawtypes")
        Iterator iter = objects.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();

            prepareToDelete(obj);

            String str = getSQLStatementFragment(obj);
            log.trace("stmt = " + str);
            stmt.addBatch(str);
        }

        @SuppressWarnings("unused")
        int[] updateCounts = stmt.executeBatch();

        iter = objects.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();

            onDelete(obj);
        }

    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}

From source file:it.cnr.icar.eric.server.security.authentication.UserRegistrar.java

/**
 * It will try to register the user if the certificate in a signed
 * SubmitObjectsRequest is not yet in the keystore. The SubmitObjectsRequest
 * must contain a single User object and its id must be a valid UUID and
 * equal to the alias parameter, which should be extracted from the KeyInfo
 * of XML signature element.// w  w  w.ja  va2  s. c om
 * 
 * @return the User object of the newly registered user
 * @throws UserRegistrationException
 *             if SubmitObjectsRequest has more than one User object, or its
 *             alias is not equal to the id of the unique User object, or
 *             the id is not a valid UUID.
 */
public UserType registerUser(X509Certificate cert, SubmitObjectsRequest ebSubmitObjectsRequest)
        throws RegistryException {

    UserType ebUserType = null;

    try {
        AuthenticationServiceImpl ac = AuthenticationServiceImpl.getInstance();

        // Get all User objects
        RegistryObjectListType ebRegistryObjectListType = ebSubmitObjectsRequest.getRegistryObjectList();
        List<IdentifiableType> identifiableTypeList = BindingUtility.getInstance()
                .getRegistryObjectTypeFilteredList(ebRegistryObjectListType);

        List<UserType> users = new ArrayList<UserType>();
        Iterator<IdentifiableType> objIter = identifiableTypeList.iterator();

        while (objIter.hasNext()) {
            RegistryObjectType ebRegistryObjectType = (RegistryObjectType) objIter.next();

            if (ebRegistryObjectType instanceof UserType) {
                UserType _user = (UserType) ebRegistryObjectType;

                // check to see if a user ACL file exists, and
                // if it does, check to see if the user is in
                // the list
                boolean isInACLFile = isUserInACLFile(_user);

                if (isInACLFile) {
                    log.info(ServerResourceBundle.getInstance().getString("message.isAuthorized", new Object[] {
                            _user.getPersonName().getFirstName(), _user.getPersonName().getLastName() }));
                } else {
                    String message = ServerResourceBundle.getInstance().getString("message.isNotAuthorized",
                            new Object[] { _user.getPersonName().getFirstName(),
                                    _user.getPersonName().getLastName() });
                    log.warn(message);
                    throw new UserRegistrationException(message);
                }

                @SuppressWarnings("unused")
                String userId = _user.getId();
                users.add(_user);
            }
        }

        if (users.size() == 0) {
            // This Exception seems to be misleading. Should we throw
            // UserRegistrationException with message saying no user was
            // found, instead?
            // Then again I doubt that this can ever happen.
            throw new UnregisteredUserException(cert);
        }

        if (!(users.size() == 1)) {
            throw new UserRegistrationException(
                    ServerResourceBundle.getInstance().getString("message.userRegistrationFailedOneUser"));
        }

        ebUserType = users.get(0);

        String userId = ebUserType.getId();

        // System.err.println("UserId: " + userId);
        if (!(it.cnr.icar.eric.common.Utility.getInstance().isValidRegistryId(userId))) {
            throw new UserRegistrationException(
                    ServerResourceBundle.getInstance().getString("message.userRegistrationFailedUUID"));
        }

        if (log.isInfoEnabled()) {
            log.info(ServerResourceBundle.getInstance().getString("message.registeringNewUser",
                    new Object[] { userId }));
        }

        ac.registerUserCertificate(userId, cert);

        if (log.isInfoEnabled()) {
            log.info(ServerResourceBundle.getInstance().getString("message.userRegistered",
                    new Object[] { userId }));
        }

    } catch (JAXRException e) {
        throw new RegistryException(e);
    }

    return ebUserType;
}

From source file:it.cnr.icar.eric.server.persistence.rdb.ServiceBindingDAO.java

protected String checkServiceBindingReferences(String serviceBindingId) throws RegistryException {
    String referencingServiceBindingId = null;
    PreparedStatement stmt = null;

    try {/*from   w ww.  j av a 2s  .  c om*/
        String sql = "SELECT id FROM ServiceBinding WHERE targetBinding=? AND targetBinding IS NOT NULL";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, serviceBindingId);

        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            referencingServiceBindingId = rs.getString(1);
        }

        return referencingServiceBindingId;
    } catch (SQLException e) {
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}

From source file:it.cnr.icar.eric.server.repository.filesystem.FileSystemRepositoryManager.java

/**
* Returns the RepositoryItem with the given unique ID.
*
* @param id Unique id for repository item
* @return RepositoryItem instance/*from w ww.  ja va  2s  .c o  m*/
* @exception RegistryException
*/
@SuppressWarnings({ "unused", "deprecation" })
public RepositoryItem getRepositoryItem(String id) throws RegistryException {
    RepositoryItem repositoryItem = null;
    String origId = id;

    // Strip off the "urn:uuid:"
    id = Utility.getInstance().stripId(id);

    try {
        String path = getRepositoryItemPath(id);
        File riFile = new File(path);

        if (!riFile.exists()) {
            String errmsg = ServerResourceBundle.getInstance().getString("message.RepositoryItemDoesNotExist",
                    new Object[] { id });
            log.error(errmsg);
            throw new RegistryException(errmsg);
        }

        DataHandler contentDataHandler = new DataHandler(new FileDataSource(riFile));

        Element sigElement = null;
        path += ".sig";

        File sigFile = new File(path);

        if (!sigFile.exists()) {
            String errmsg = "Payload signature for repository item id=\"" + id + "\" does not exist!";
            //log.error(errmsg);

            throw new RegistryException(errmsg);
        } else {

            javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
                    .newInstance();
            dbf.setNamespaceAware(true);
            javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
            org.w3c.dom.Document sigDoc = db.parse(new FileInputStream(sigFile));

            repositoryItem = new RepositoryItemImpl(id, sigDoc.getDocumentElement(), contentDataHandler);
        }

    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return repositoryItem;
}

From source file:it.cnr.icar.eric.server.persistence.rdb.RegistryObjectDAO.java

/**
 * Get the objectType for specified object. If it is an ExtrinsicObject or
 * ExternalLink then get it from the object. Otherwise ignore the value in
 * the object and get from the DAO the hardwired value.
 *///ww  w  .j a  v  a2  s  . c  om
protected String getObjectType(RegistryObjectType ro) throws RegistryException {
    String objectType = null;
    String rimName = null;

    try {
        String roClassName = ro.getClass().getName();

        if (roClassName.endsWith("Type")) {
            // length 4
            rimName = roClassName.substring(roClassName.lastIndexOf('.') + 1, roClassName.length() - 4);
        } else if (roClassName.endsWith("Type1")) {
            // length 5
            rimName = roClassName.substring(roClassName.lastIndexOf('.') + 1, roClassName.length() - 5);
        }

        Field field = CanonicalSchemes.class.getDeclaredField("CANONICAL_OBJECT_TYPE_ID_" + rimName);
        objectType = field.get(null).toString();
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    // TODO Get object type from leaf DAO if not ExtrinsicObject
    if ((ro instanceof ExtrinsicObjectType) || (ro instanceof ExternalLinkType)) {
        String _objectType = ro.getObjectType();
        if (_objectType != null) {
            objectType = _objectType;
        }

        // Make sure that objectType is a ref to a ObjectType
        // ClassificationNode
        //context.checkClassificationNodeRefConstraint(objectType, bu.CANONICAL_CLASSIFICATION_SCHEME_ID_ObjectType, "objectType");
    }

    return objectType;
}

From source file:it.cnr.icar.eric.server.plugin.RequestInterceptorManager.java

@SuppressWarnings("unchecked")
public List<RequestInterceptor> getInterceptors() throws RegistryException {
    ServerRequestContext context = null;
    try {//from www .  j a va 2 s  .  c o  m
        if (interceptors == null) {
            ArrayList<RequestInterceptor> _interceptors = new ArrayList<RequestInterceptor>();
            context = new ServerRequestContext("RequestInterceptorManager:RequestInterceptorManager", null);
            RegistryType registry = null;
            try {
                registry = ServerCache.getInstance().getRegistry(context);
            } catch (ObjectNotFoundException e) {
                //Registry instance not loaded yet
                //Must be in db build sequence.
                //Return empty list but dont set the interceptors var until registry instance is read
                return new ArrayList<RequestInterceptor>();
            }

            HashMap<String, Serializable> slotsMap = bu.getSlotsFromRegistryObject(registry);
            //??Need to fix getSlotsFromRegistryObject and getSlotsFromRegistryRequest to always return slot values as List
            //Otherwise a List slot with single value gets returned as String and we get ClassCastException.
            @SuppressWarnings("static-access")
            Object o = slotsMap.get(bu.FREEBXML_REGISTRY_REGISTRY_INTERCEPTORS);
            List<String> interceptorClasses = null;
            if (o != null) {
                if (o instanceof List) {
                    interceptorClasses = (List<String>) o;
                } else {
                    interceptorClasses = new ArrayList<String>();
                    interceptorClasses.add((String) o);
                }

                //Instantiate and cache Interceptor classes
                if (interceptorClasses != null) {
                    Iterator<String> iter = interceptorClasses.iterator();
                    while (iter.hasNext()) {
                        String className = iter.next();
                        RequestInterceptor interceptor = (RequestInterceptor) createPluginInstance(className);
                        _interceptors.add(interceptor);
                    }
                }
                interceptors = _interceptors;
            } else {
                //NO interceptors configured.
                interceptors = new ArrayList<RequestInterceptor>();
            }
        }
    } catch (Throwable e) {
        log.error(e);
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            context.rollback();
        }
    }
    return interceptors;
}

From source file:it.cnr.icar.eric.server.persistence.rdb.SlotDAO.java

public void insert(@SuppressWarnings("rawtypes") List slots) throws RegistryException {
    throw new RegistryException(ServerResourceBundle.getInstance().getString("message.methodNotSupported"));
}

From source file:it.cnr.icar.eric.server.cache.AbstractCache.java

/**
 * Check if object exists in cache./*from w  ww . j a v  a2 s . c  o m*/
 */
public boolean contains(String objectId) throws RegistryException {
    boolean found = false;

    try {
        found = (internalCache.get(objectId) != null);
    } catch (CacheException e) {
        throw new RegistryException(e);
    }
    return found;
}