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.interfaces.rest.URLHandler.java

@SuppressWarnings("unchecked")
List<IdentifiableType> invokeParameterizedQuery(ServerRequestContext context, String queryId,
        Map<String, String> queryParams, UserType user, int startIndex, int maxResults)
        throws RegistryException {

    List<IdentifiableType> ebRegistryObjectTypeList = null;

    try {//from w w w  .  ja  v a  2s.  c  o m
        AdhocQueryRequest req = BindingUtility.getInstance()
                .createAdhocQueryRequest("SELECT * FROM DummyTable");
        req.setStartIndex(BigInteger.valueOf(startIndex));
        req.setMaxResults(BigInteger.valueOf(maxResults));

        Map<String, String> slotsMap = new HashMap<String, String>();
        slotsMap.put(BindingUtility.CANONICAL_SLOT_QUERY_ID, queryId);
        if ((queryParams != null) && (queryParams.size() > 0)) {
            slotsMap.putAll(queryParams);
        }
        BindingUtility.getInstance().addSlotsToRequest(req, slotsMap);

        // Now execute the query
        HashMap<String, Object> idToRepositoryItemMap = new HashMap<String, Object>();
        context.setRepositoryItemsMap(idToRepositoryItemMap);

        boolean doCommit = false;
        try {
            context.pushRegistryRequest(req);
            AdhocQueryResponse ebAdhocQueryResponse = qm.submitAdhocQuery(context);
            bu.checkRegistryResponse(ebAdhocQueryResponse);
            ebRegistryObjectTypeList = (List<IdentifiableType>) bu
                    .getIdentifiableTypeList(ebAdhocQueryResponse.getRegistryObjectList());
            doCommit = true;
        } finally {
            context.popRegistryRequest();
            try {
                closeContext(context, doCommit);
            } catch (Exception ex) {
                log.error(ex, ex);
            }
        }
    } catch (JAXBException e) {
        throw new RegistryException(e);
    } catch (JAXRException e) {
        throw new RegistryException(e);
    }

    return ebRegistryObjectTypeList;
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java

/**
 * Submits one or more RegistryObjects and one or more repository items. <br>
 * <br>/*  w ww  . ja  v  a  2 s .c o m*/
 * Note: One more special feature that is not in the RS spec. version 2. The
 * SubmitObjectsRequest allows updating objects.If a object of a particular
 * id already exist, it is updated instead of trying to be inserted.
 * 
 * @param idToRepositoryItemMap
 *            is a HashMap with key that is id of a RegistryObject and value
 *            that is a RepositoryItem instance.
 */
@SuppressWarnings("unused")
public RegistryResponseType submitObjects(RequestContext context) throws RegistryException {
    context = ServerRequestContext.convert(context);
    SubmitObjectsRequest ebSubmitObjectsRequest = (SubmitObjectsRequest) context.getCurrentRegistryRequest();
    UserType user = context.getUser();
    HashMap<String, Object> idToRepositoryItemMap = context.getRepositoryItemsMap();
    String errorCodeContext = "LifeCycleManagerImpl.submitObjects";
    String errorCode = "unknown";

    RegistryResponseType ebRegistryResponseType = null;
    try {
        calculateEffectiveUser(((ServerRequestContext) context));
        RegistryObjectListType ebRegistryObjectListType = ebSubmitObjectsRequest.getRegistryObjectList();

        // insert member objects of RegistryPackages
        @SuppressWarnings("unchecked")
        List<IdentifiableType> ebIdentifiableTypeList = (List<IdentifiableType>) bu
                .getIdentifiableTypeList(ebRegistryObjectListType);

        int objsSize = ebIdentifiableTypeList.size();
        for (int i = 0; i < objsSize; i++) {
            IdentifiableType identObj = ebIdentifiableTypeList.get(i);

            if (identObj instanceof RegistryPackageType) {
                insertPackageMembers(ebRegistryObjectListType, (RegistryPackageType) identObj);
            }
        }

        // Split Identifiables by RegistryObjects and ObjectRefs
        bu.getObjectRefsAndRegistryObjects(ebRegistryObjectListType,
                ((ServerRequestContext) context).getTopLevelRegistryObjectTypeMap(),
                ((ServerRequestContext) context).getObjectRefTypeMap());

        processConfirmationAssociations(((ServerRequestContext) context));

        ((ServerRequestContext) context).checkObjects();

        // Auth check must be after checkObjects as it needs objectRefsMap
        // etc.
        // for doing Access Control on references

        checkAuthorizedAll(((ServerRequestContext) context));

        if (!bypassCMS) {
            // Now perform any content cataloging and validation for
            // ExtrinsicObjects

            log.trace(ServerResourceBundle.getInstance().getString("message.CallingInvokeServicesAt",
                    new Object[] { new Long(System.currentTimeMillis()) }));
            cmsm.invokeServices(((ServerRequestContext) context));
            log.trace(ServerResourceBundle.getInstance().getString("message.DoneCallingInvokeServicesAt",
                    new Object[] { new Long(System.currentTimeMillis()) }));
        }

        /*
         * For RegistryObjects, the DAO will take care which objects already
         * exist and update them instead
         */
        log.trace(ServerResourceBundle.getInstance().getString("message.CallingPminsertAt",
                new Object[] { new Long(System.currentTimeMillis()) }));
        List<IdentifiableType> list = new ArrayList<IdentifiableType>();
        list.addAll(((ServerRequestContext) context).getTopLevelRegistryObjectTypeMap().values());
        pm.insert(((ServerRequestContext) context), list);

        log.trace(ServerResourceBundle.getInstance().getString("message.DoneCallingPminsertAt",
                new Object[] { new Long(System.currentTimeMillis()) }));

        ebRegistryResponseType = bu.rsFac.createRegistryResponseType();
        ebRegistryResponseType.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);

        if (((ServerRequestContext) context).getErrorList().getRegistryError().size() > 0) {
            // warning exists
            ebRegistryResponseType.setRegistryErrorList(((ServerRequestContext) context).getErrorList());
        }

        // Must be after CMS since CMS could generate more repository items.
        if ((((ServerRequestContext) context).getRepositoryItemsMap() != null)
                && (!(((ServerRequestContext) context).getRepositoryItemsMap().isEmpty()))) {
            submitRepositoryItems(((ServerRequestContext) context));
        }

    } catch (RegistryException e) {
        ((ServerRequestContext) context).rollback();
        throw e;
    } catch (IllegalStateException e) {
        // ?? This is a JAXR spec bug that we do not send an
        // UnauthorizedRequestException
        ((ServerRequestContext) context).rollback();
        throw e;
    } catch (Exception e) {
        ((ServerRequestContext) context).rollback();
        throw new RegistryException(e);
    }

    ((ServerRequestContext) context).commit();
    return ebRegistryResponseType;
}

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

/**
 * Gets the alias within the KeyStore for a User
 */// w w w .  j  a v a 2  s. c o  m
public X509Certificate getCertificateFromUser(UserType user) throws RegistryException {
    X509Certificate cert = null;

    try {
        String alias = getAliasFromUser(user);

        cert = (X509Certificate) (getKeyStore().getCertificate(alias));
    } catch (KeyStoreException e) {
        throw new RegistryException(e);
    }

    return cert;
}

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

protected String getSQLStatementFragment(Object object) throws RegistryException {
    throw new RegistryException(ServerResourceBundle.getInstance()
            .getString("message.getSQLStatementFragmentMissing", new Object[] { getTableName() }));
}

From source file:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java

/** Write the result set as a RegistryObjectList */
private void writeRegistryObjectList(List<? extends IdentifiableType> ebRegistryObjectTypeList)
        throws IOException, RegistryException {
    ServletOutputStream sout = null;/*w ww  . ja v  a  2  s .  c  o  m*/
    try {
        sout = response.getOutputStream();

        @SuppressWarnings("unchecked")
        RegistryObjectListType ebRegistryObjectListType = bu
                .getRegistryObjectListType((List<RegistryObjectType>) ebRegistryObjectTypeList);

        //            javax.xml.bind.Marshaller marshaller = bu.rimFac.createMarshaller();
        javax.xml.bind.Marshaller marshaller = bu.getJAXBContext().createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(ebRegistryObjectListType, sout);

    } catch (JAXBException e) {
        throw new RegistryException(e);
    } finally {
        if (sout != null) {
            sout.close();
        }
    }
}

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

/**
* Returns the RepositoryItem associated with the ExtrinsicObject specified by id.
*
* @param id Unique id for ExtrinsicObject whose repository item is desired.
* @return RepositoryItem instance//from   www .  j a va 2s  . c o  m
* @exception RegistryException
*/
@SuppressWarnings("unused")
public RepositoryItem getRepositoryItem(String id) throws RegistryException {
    RepositoryItem repositoryItem = null;

    /*
    ** Following code must duplicate that in getRepositoryItemKey()
    ** because we need the eo variable later.  Keep the two in sync
    ** manually.
    */
    ServerRequestContext context = null;
    try {

        context = new ServerRequestContext("HibernateRepositoryManager:getRepositoryItem", null);

        //Access control is check in qm.getRepositoryItem using actual request context
        //This internal request context has total access.
        context.setUser(AuthenticationServiceImpl.getInstance().registryOperator);
        RegistryObjectType ro = qm.getRegistryObject(context, id, "ExtrinsicObject");

        if (!(ro instanceof ExtrinsicObjectType)) {
            throw new ObjectNotFoundException(id);
        }

        ExtrinsicObjectType ebExtrinsicObjectType = (ExtrinsicObjectType) ro;
        if (ebExtrinsicObjectType == null) {
            throw new ObjectNotFoundException(id);
        }

        VersionInfoType ebVersionInfoType = ebExtrinsicObjectType.getContentVersionInfo();

        if (ebVersionInfoType == null) {
            // no Repository Item to find for this EO
            throw new RepositoryItemNotFoundException(id,
                    ebExtrinsicObjectType.getVersionInfo().getVersionName());
        }

        RepositoryItemKey key = new RepositoryItemKey(ebExtrinsicObjectType.getLid(),
                ebVersionInfoType.getVersionName());

        Transaction tx = null;
        String lid = key.getLid();
        String versionName = key.getVersionName();

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

            //Need to call clear otherwise we get a cached ReposiytoryItemBean where the txn has committed 
            //and Blob cannot be read any more. This will be better fixed when we pass ServerRequestContext
            //to each rm interface method and leverage leave txn management to ServerRequestContext.
            //See patch submitted for Sun Bug 6444810 on 6/28/2006
            s.clear();
            tx = s.beginTransaction();

            // if item does not exist, 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.RepositoryItemWithIdAndVersionDoesNotExist",
                        new Object[] { lid, versionName });
                log.error(errmsg);
                throw new RepositoryItemNotFoundException(lid, versionName);
            }

            RepositoryItemBean bean = (RepositoryItemBean) results.get(0);

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

            String contentType = ebExtrinsicObjectType.getMimeType();

            DataHandler contentDataHandler;
            if (isBlobSupported) {
                contentDataHandler = new DataHandler(new ByteArrayDataSource(
                        readBytes(bean.getBlobContent().getBinaryStream()), contentType));
            } else {
                contentDataHandler = new DataHandler(
                        new ByteArrayDataSource(bean.getBinaryContent(), contentType));
            }

            repositoryItem = new RepositoryItemImpl(id, contentDataHandler);

            tx.commit();
        } catch (RegistryException e) {
            tryRollback(tx);
            throw e;
        } catch (Exception e) {
            String msg = ServerResourceBundle.getInstance().getString("message.FailedToGetRepositoryItem",
                    new Object[] { lid, versionName });
            log.error(e, e);
            tryRollback(tx);
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.seeLogsForDetails", new Object[] { msg }));
        } finally {
            tryClose();
        }
    } finally {
        context.rollback();
    }

    return repositoryItem;
}

From source file:it.cnr.icar.eric.server.lcm.versioning.VersionProcessor.java

@SuppressWarnings("static-access")
public boolean needToVersionRepositoryItem(ExtrinsicObjectType eo, RepositoryItem riNew)
        throws RegistryException {
    boolean needToVersion = true;

    try {/*from   ww w  .  j a v a 2  s.c om*/
        //dontVersion eo imples dontVersion ro
        needToVersion = needToVersionRegistryObject(eo);

        if (needToVersion) {
            //This is an existing object not a newly submitted object
            //See if repository item has changed or not.
            HashMap<?, ?> slotsMap;

            //Honour dontVersion flag if specified on request
            if (!context.getRegistryRequestStack().empty()) {
                slotsMap = bu.getSlotsFromRequest(context.getCurrentRegistryRequest());
                if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT)) {
                    String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT);
                    if (val.trim().equalsIgnoreCase("true")) {
                        needToVersion = false;
                    }
                }
            }

            //Honour dontVersion flag if specified on ro
            slotsMap = bu.getSlotsFromRegistryObject(eo);
            if (slotsMap.containsKey(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT)) {
                String val = (String) slotsMap.get(bu.CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT);
                if (val.trim().equalsIgnoreCase("true")) {
                    needToVersion = false;
                }
            }
        }

        if (needToVersion) {
            if (riNew == null) {
                needToVersion = false;
                return needToVersion;
            } else {
                RepositoryItem riOld = null;

                try {
                    riOld = rm.getRepositoryItem(eo.getId());
                } catch (RepositoryItemNotFoundException e) {
                    //It is possible that there is no RepositoryItem yet.
                    //Ignore the exception.
                    riOld = null;
                } catch (ObjectNotFoundException e) {
                    //It is possible that there is no RepositoryItem yet.
                    //Ignore the exception.
                    riOld = null;
                }

                if (riOld == null) {
                    needToVersion = false;
                } else {
                    if (repositoryItemsAreIdentical(riOld, riNew)) {
                        needToVersion = false;
                    }
                }
            }
        }

        //Must set contentVersionName to match latest versionName if existing object
        //or set to version 1.1 if new object.
        if (!needToVersion) {
            ExtrinsicObjectType lastVersion = (ExtrinsicObjectType) getLatestVersionOfRegistryObject(eo);

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

            if (lastVersion == null) {
                //This is the first ExtrinsicObject version.
                if (riNew != null) {
                    //This is the first RepositoryItem version. Make sure versionName is "1.1"
                    contentVersionInfo.setVersionName("1.1");
                } else {
                    //No repository item means that the contentVersionInfo MUST be set to null
                    contentVersionInfo = null;
                }
            } else {
                //This is not the first ExtrinsicObject version.
                //Note that contentversionName is set even if no RI is submitted since
                //it is OK to update just the EO and have new version use last version of RO

                VersionInfoType lastContentVersionInfo = lastVersion.getContentVersionInfo();

                if (lastContentVersionInfo == null) {
                    //Previous version had no repository item
                    String lastContentVersionName = rm.getLatestVersionName(context, eo.getLid());
                    if (lastContentVersionName != null) {
                        contentVersionInfo.setVersionName(lastContentVersionName);
                    } else {
                        contentVersionInfo.setVersionName("1.1");
                    }
                } else {
                    //Previous version had a repository item
                    //Use the last contentVersionName
                    contentVersionInfo.setVersionName(lastContentVersionInfo.getVersionName());
                }
            }
            eo.setContentVersionInfo(contentVersionInfo);
        }

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

    return needToVersion;
}

From source file:it.cnr.icar.eric.server.interfaces.rest.URLHandler.java

/**
 * Get the User object that is associated with a Slot named
 * 'urn:oasis:names:tc:ebxml-regrep:3.0:rim:User:principalName' whose value
 * matches the principal name specified. If the principal is
 * <code>null</code>, use the value of the
 * <code>eric.security.anonymousUserPrincipalName</code> property as the
 * principal name. If the property is not set, or no User is found, return
 * the RegistryGuest user.//from  w w w .j a v a  2  s. c o m
 * 
 * @param principal
 * @throws JAXRException
 * @return
 */
protected UserType findUserByPrincipal(Principal principal) throws RegistryException {
    try {
        UserType user = null;
        if (principal == null) {
            String principalName = CommonProperties.getInstance()
                    .getProperty("eric.security.anonymousUserPrincipalName");
            if (principalName != null) {
                user = findUserByPrincipalName(principalName);
            }
        } else {
            user = findUserByPrincipalName(principal.getName());
        }
        if (user == null) {
            user = AuthenticationServiceImpl.getInstance().registryGuest;
        }
        return user;
    } catch (RegistryException re) {
        throw re;
    } catch (Exception e) {
        throw new RegistryException(e);
    }
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImplTest.java

public List<JAXBElement<? extends IdentifiableType>> getAuditTrailForRegistryObject(RequestContext context,
        RegistryObjectType ro) throws RegistryException {
    List<JAXBElement<? extends IdentifiableType>> auditTrail = null;

    try {/*from   w w  w . jav a2s  . c o m*/
        HashMap<String, String> queryParams = new HashMap<String, String>();
        queryParams.put("$lid", ro.getLid());
        AdhocQueryRequest req = bu.createAdhocQueryRequest(
                "urn:oasis:names:tc:ebxml-regrep:query:GetAuditTrailForRegistryObject", queryParams);
        context.pushRegistryRequest(req);
        AdhocQueryResponse resp = qm.submitAdhocQuery(context);

        auditTrail = resp.getRegistryObjectList().getIdentifiable();

    } catch (JAXBException e) {
        throw new RegistryException(e);
    }
    return auditTrail;
}

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

/**
 * Gets the User that is associated with the given alias.
 * /*  w  w  w.jav a2s.co m*/
 * @throws UserNotFoundException
 *             when no matching User is found
 */
public UserType getUserFromAlias(String alias) throws RegistryException {
    UserType user = null;

    ServerRequestContext context = null;
    try {
        context = new ServerRequestContext("AuthenticationServiceImpl.getUserFromAlias", null);
        context.setUser(this.registryOperator);
        String userId = alias;
        user = (UserType) ServerCache.getInstance().getRegistryObject(context, userId, "User");
        if (user == null) {
            throw new UserNotFoundException(userId);
        }

        // See if User need to be auto-classified as RegistryAdministrator
        boolean isAdmin = isRegistryAdministratorInPropFile(user);

        if (isAdmin) {
            // Make sure that the user is classified with the
            // RegistryAdministrator role
            makeRegistryAdministrator(context, user);
        }

        context.commit();
        context = null;
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            // Oh no, it's still here...
            context.rollback();
        }
    }

    return user;
}