org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LDCmisService.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Session validateSession() {
	if (getSid() == null)
		return null;

	try {
		Session session = SessionManager.get().get(getSid());
		if (session == null)
			throw new CmisPermissionDeniedException("Unexisting session " + getSid());
		if (SessionManager.get().getStatus(getSid()) != Session.STATUS_OPEN)
			throw new CmisPermissionDeniedException("Invalid or Expired Session " + getSid());
		SessionManager.get().renew(getSid());
		return session;
	} catch (Throwable t) {
		log.error(t.getMessage(), t);
		if (t instanceof CmisBaseException)
			throw (CmisBaseException) t;
		else
			throw new CmisPermissionDeniedException("Invalid session!");
	}
}
 
Example #2
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts the given exception into a CMIS exception.
 */
protected CmisBaseException createCmisException(Exception e) {
    if (e == null) {
        // should never happen
        // if it happens its the fault of the framework...

        return new CmisRuntimeException("Unknown exception!");
    } else if (e instanceof CmisBaseException) {
        return (CmisBaseException) e;
    } else {
        // should not happen if the connector works correctly
        // it's alarming enough to log the exception
        LOG.warn(e.toString(), e);

        return new CmisRuntimeException(e.getMessage(), e);
    }
}
 
Example #3
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Object catchError(Throwable t) {
	if (t instanceof CmisObjectNotFoundException)
		log.debug(t.getMessage());
	else if (t instanceof IllegalArgumentException)
		log.warn(t.getMessage());
	else
		log.error(t.getMessage(), t);

	if (t instanceof CmisBaseException)
		throw (CmisBaseException) t;
	else
		throw new CmisStorageException("CMIS Error!", t);
}
 
Example #4
Source File: AlfrescoCmisExceptionInterceptor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Object invoke(MethodInvocation mi) throws Throwable
{
    try
    {
        return mi.proceed();
    }
    catch (Exception e)
    {
        // We dig into the exception to see if there is anything of interest to CMIS
        Throwable cmisAffecting = ExceptionStackUtil.getCause(e, EXCEPTIONS_OF_INTEREST);
        
        if (cmisAffecting == null)
        {
            // The exception is not something that CMIS needs to handle in any special way
            if (e instanceof CmisBaseException)
            {
                throw (CmisBaseException) e;
            }
            else
            {
                throw new CmisRuntimeException(e.getMessage(), e);
            }
        }
        // All other exceptions are carried through with full stacks but treated as the exception of interest
        else if (cmisAffecting instanceof AuthenticationException)
        {
            throw new CmisPermissionDeniedException(cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof CheckOutCheckInServiceException)
        {
            throw new CmisVersioningException("Check out failed: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof FileExistsException)
        {
            throw new CmisContentAlreadyExistsException("An object with this name already exists: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof IntegrityException)
        {
            throw new CmisConstraintException("Constraint violation: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof AccessDeniedException)
        {
            throw new CmisPermissionDeniedException("Permission denied: " + cmisAffecting.getMessage(), e);
        }
        else if (cmisAffecting instanceof NodeLockedException)
        {
            throw new CmisUpdateConflictException("Update conflict: " + cmisAffecting.getMessage(), e);
        }
        else
        {
            // We should not get here, so log an error but rethrow to have CMIS handle the original cause
            logger.error("Exception type not handled correctly: " + e.getClass().getName());
            throw new CmisRuntimeException(e.getMessage(), e);
        }
    }
}
 
Example #5
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the content from the repository.
 */
public ContentStream getContentStream(CMISNodeInfo info, String streamId, BigInteger offset, BigInteger length)
{
    // get the type and check if the object can have content
    TypeDefinitionWrapper type = info.getType();
    checkDocumentTypeForContent(type);

    // looks like a document, now get the content
    ContentStreamImpl result = new ContentStreamImpl();
    result.setFileName(info.getName());

    // if streamId is set, fetch other content
    NodeRef streamNodeRef = info.getNodeRef();
    if ((streamId != null) && (streamId.length() > 0))
    {
        CMISNodeInfo streamInfo = createNodeInfo(streamId);
        if (!streamInfo.isVariant(CMISObjectVariant.CURRENT_VERSION))
        {
            throw new CmisInvalidArgumentException("Stream id is invalid: " + streamId + ", expected variant " + CMISObjectVariant.CURRENT_VERSION + ", got variant " + streamInfo.getObjectVariant());
        }

        streamNodeRef = streamInfo.getNodeRef();
        type = streamInfo.getType();
        checkDocumentTypeForContent(type);
    }

    // get the stream now
    try
    {
        ContentReader contentReader = contentService.getReader(streamNodeRef, ContentModel.PROP_CONTENT);
        if (contentReader == null)
        {
            throw new CmisConstraintException("Document has no content!");
        }

        result.setMimeType(contentReader.getMimetype());
        long contentSize = contentReader.getSize();

        if ((offset == null) && (length == null))
        {
            result.setStream(contentReader.getContentInputStream());
            result.setLength(BigInteger.valueOf(contentSize));
            publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), null);
        }
        else
        {
            long off = (offset == null ? 0 : offset.longValue());
            long len = (length == null ? contentSize : length.longValue());
            if (off + len > contentSize)
            {
                len = contentReader.getSize() - off;
            }

            result.setStream(new RangeInputStream(contentReader.getContentInputStream(), off, len));
            result.setLength(BigInteger.valueOf(len));
            publishReadEvent(streamNodeRef, info.getName(), result.getMimeType(), contentSize, contentReader.getEncoding(), off+" - "+len);
        }
    }
    catch (Exception e)
    {
        if (e instanceof CmisBaseException)
        {
            throw (CmisBaseException) e;
        }
        else
        {
            StringBuilder msg = new StringBuilder("Failed to retrieve content: " + e.getMessage());
            Throwable cause = e.getCause();
            if(cause != null)
            {
                // add the cause to the CMIS exception
                msg.append(", ");
                msg.append(cause.getMessage());
            }
            throw new CmisRuntimeException(msg.toString(), e);
        }
    }

    return result;
}