001/* 002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012package org.nuxeo.ecm.core.opencmis.bindings; 013 014import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException; 015import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; 016import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; 017import org.apache.chemistry.opencmis.commons.server.CmisService; 018import org.apache.chemistry.opencmis.server.support.wrapper.ConformanceCmisServiceWrapper; 019import org.nuxeo.ecm.core.api.RecoverableClientException; 020import org.nuxeo.ecm.core.query.QueryParseException; 021import org.slf4j.Logger; 022import org.slf4j.LoggerFactory; 023 024/** 025 * CMIS Conformance Service Wrapper that has better exception handling than the default. 026 */ 027public class NuxeoCmisServiceWrapper extends ConformanceCmisServiceWrapper { 028 029 private static final Logger LOG = LoggerFactory.getLogger(NuxeoCmisServiceWrapper.class); 030 031 public NuxeoCmisServiceWrapper(CmisService service) { 032 super(service); 033 } 034 035 /** 036 * Converts the given exception into a CMIS exception. 037 */ 038 protected CmisBaseException createCmisException(Exception e) { 039 if (e == null) { 040 return new CmisRuntimeException("Unknown exception!"); 041 } else if (e instanceof CmisBaseException) { 042 return (CmisBaseException) e; 043 } else if (e instanceof RecoverableClientException) { 044 throw new CmisRuntimeException("error", e); 045 } else if (e instanceof QueryParseException) { 046 throw new CmisInvalidArgumentException(e.getMessage(), e); 047 } else { 048 // should not happen if the connector works correctly 049 // it's alarming enough to log the exception 050 LOG.warn(e.toString(), e); 051 return new CmisRuntimeException(e.getMessage(), e); 052 } 053 } 054 055}