/** * Parses an array from an input stream. */ @SuppressWarnings("unchecked") protected List<Object> parseArray(InputStream stream, String charset) { Object obj = parse(stream, charset, SIMPLE_CONTAINER_FACTORY); if (obj instanceof List) { return (List<Object>) obj; } throw new CmisConnectionException("Unexpected object!"); }
/** * Constructor. * * @param url * failing URL * @param respCode * HTTP response code (0 if unknown) * @param cause * the cause */ public CmisConnectionException(String url, int respCode, Throwable cause) { super("Cannot access \"" + url + "\"" + (respCode > 0 ? " (HTTP status code " + respCode + ")" : "") + ": " + formatMessage(cause), BigInteger.ZERO, cause); }
/** * Parses an object from an input stream. */ @SuppressWarnings("unchecked") protected Map<String, Object> parseObject(InputStream stream, String charset) { Object obj = parse(stream, charset, SIMPLE_CONTAINER_FACTORY); if (obj instanceof Map) { return (Map<String, Object>) obj; } throw new CmisConnectionException("Unexpected object!"); }
/** * Constructor. * * @param url * failing URL * @param respCode * HTTP response code (0 if unknown) * @param cause * the cause */ public CmisConnectionException(String url, int respCode, Throwable cause) { super("Cannot access \"" + url + "\"" + (respCode > 0 ? " (HTTP status code " + respCode + ")" : "") + ": " + formatMessage(cause), BigInteger.ZERO, cause); }
/** * Parses an array from an input stream. */ @SuppressWarnings("unchecked") protected List<Object> parseArray(InputStream stream, String charset) { Object obj = parse(stream, charset, SIMPLE_CONTAINER_FACTORY); if (obj instanceof List) { return (List<Object>) obj; } throw new CmisConnectionException("Unexpected object!"); }
/** * Parses an object from an input stream. */ @SuppressWarnings("unchecked") protected Map<String, Object> parseObject(InputStream stream, String charset) { Object obj = parse(stream, charset, SIMPLE_CONTAINER_FACTORY); if (obj instanceof Map) { return (Map<String, Object>) obj; } throw new CmisConnectionException("Unexpected object!"); }
public Session getSession() { if (session == null) { logger.info("Not connected, creating new connection"); // default factory implementation SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // user credentials parameter.put(SessionParameter.USER, "admin"); parameter.put(SessionParameter.PASSWORD, "admin"); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom"); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); List<Repository> repositories = factory.getRepositories(parameter); if (repositories != null && repositories.size() > 0) { logger.info("Found (" + repositories.size() + ") Alfresco repositories"); this.session = repositories.get(0).createSession(); } else { throw new CmisConnectionException("Could not connect to the Alfresco Server," + " no repository found!"); } } return this.session; }
/** * Parses an input stream. */ @SuppressWarnings("unchecked") protected <T extends AtomBase> T parse(InputStream stream, Class<T> clazz) { AtomPubParser parser = new AtomPubParser(stream); try { parser.parse(); } catch (Exception e) { throw new CmisConnectionException("Parsing exception!", e); } AtomBase parseResult = parser.getResults(); if (!clazz.isInstance(parseResult)) { throw new CmisConnectionException("Unexpected document! Received: " + (parseResult == null ? "something unknown" : parseResult.getType())); } return (T) parseResult; }
/** * Gets the repository for a given repository id.<p> * * @param repositoryId the repository id * * @return the repository with the given id */ protected I_CmsCmisRepository getRepository(String repositoryId) { I_CmsCmisRepository result = OpenCms.getRepositoryManager().getRepository( repositoryId, I_CmsCmisRepository.class); if (result == null) { throw new CmisConnectionException("missing repository: " + repositoryId); } return result; }
/** * Parses an input stream. */ @SuppressWarnings("unchecked") protected <T extends AtomBase> T parse(InputStream stream, Class<T> clazz) { AtomPubParser parser = new AtomPubParser(stream); try { parser.parse(); } catch (Exception e) { throw new CmisConnectionException("Parsing exception!", e); } AtomBase parseResult = parser.getResults(); if (!clazz.isInstance(parseResult)) { throw new CmisConnectionException("Unexpected document! Received: " + (parseResult == null ? "something unknown" : parseResult.getType())); } return (T) parseResult; }
uri = new URI(url); } catch (URISyntaxException e) { throw new CmisConnectionException(e.getMessage(), e);
uri = new URI(url); } catch (URISyntaxException e) { throw new CmisConnectionException(e.getMessage(), e);
/** * Parses an input stream. */ protected Object parse(InputStream stream, String charset, ContainerFactory containerFactory) { InputStreamReader reader = null; Object obj = null; try { reader = new InputStreamReader(stream, charset); JSONParser parser = new JSONParser(); obj = parser.parse(reader, containerFactory); } catch (JSONParseException e) { throw new CmisConnectionException("Parsing exception: " + e.getMessage(), e); } catch (Exception e) { throw new CmisConnectionException("Parsing exception!", e); } finally { IOUtils.consumeAndClose(reader); if (reader == null) { IOUtils.closeQuietly(stream); } } return obj; }
/** * Parses an input stream. */ protected Object parse(InputStream stream, String charset, ContainerFactory containerFactory) { InputStreamReader reader = null; Object obj = null; try { reader = new InputStreamReader(stream, charset); JSONParser parser = new JSONParser(); obj = parser.parse(reader, containerFactory); } catch (JSONParseException e) { throw new CmisConnectionException("Parsing exception: " + e.getMessage(), e); } catch (Exception e) { throw new CmisConnectionException("Parsing exception!", e); } finally { IOUtils.consumeAndClose(reader); if (reader == null) { IOUtils.closeQuietly(stream); } } return obj; }
uri = new URI(url); } catch (URISyntaxException e) { throw new CmisConnectionException(e.getMessage(), e);
uri = new URI(url); } catch (URISyntaxException e) { throw new CmisConnectionException(e.getMessage(), e);
hasResponseStream = IOUtils.checkForBytes(stream); } catch (IOException ioe) { throw new CmisConnectionException("IO exception!", ioe);
hasResponseStream = IOUtils.checkForBytes(stream); } catch (IOException ioe) { throw new CmisConnectionException("IO exception!", ioe);
/** * Gets the access token. If no access token is present or the access token * is expired, a new token is requested. * * @return the access token */ protected String getAccessToken() { lock.writeLock().lock(); try { if (token.getAccessToken() == null) { if (token.getRefreshToken() == null) { requestToken(); } else { refreshToken(); } } else if (token.isExpired()) { refreshToken(); } return token.getAccessToken(); } catch (CmisConnectionException ce) { throw ce; } catch (Exception e) { throw new CmisConnectionException("Cannot get OAuth access token: " + e.getMessage(), e); } finally { lock.writeLock().unlock(); } }
/** * Gets the access token. If no access token is present or the access token * is expired, a new token is requested. * * @return the access token */ protected String getAccessToken() { lock.writeLock().lock(); try { if (token.getAccessToken() == null) { if (token.getRefreshToken() == null) { requestToken(); } else { refreshToken(); } } else if (token.isExpired()) { refreshToken(); } return token.getAccessToken(); } catch (CmisConnectionException ce) { throw ce; } catch (Exception e) { throw new CmisConnectionException("Cannot get OAuth access token: " + e.getMessage(), e); } finally { lock.writeLock().unlock(); } }