Search in sources :

Example 1 with MutablePage

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage in project manifoldcf by apache.

the class ConfluenceClient method getPage.

/**
 * <p>
 * Get a Confluence page identified by its id
 * </p>
 *
 * @param pageId
 *          the page id
 * @return the Confluence page
 * @throws Exception
 */
public Page getPage(final String pageId) throws Exception {
    String url = String.format(Locale.ROOT, "%s://%s:%s%s%s/%s?%s", protocol, host, port, path, CONTENT_PATH, pageId, EXPANDABLE_PARAMETERS);
    url = sanitizeUrl(url);
    logger.debug("[Processing] Hitting url for getting document content : {}", url);
    final HttpGet httpGet = createGetRequest(url);
    try (CloseableHttpResponse response = executeRequest(httpGet)) {
        final HttpEntity entity = response.getEntity();
        final MutablePage page = pageFromHttpEntity(entity);
        EntityUtils.consume(entity);
        final List<Label> labels = getLabels(pageId);
        page.setLabels(labels);
        return page;
    } catch (final Exception e) {
        logger.error("[Processing] Failed to get page {}. Error: {}", url, e.getMessage());
        throw e;
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) MutablePage(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Label(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Label) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ConfluenceException(org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException) IOException(java.io.IOException)

Example 2 with MutablePage

use of org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage in project manifoldcf by apache.

the class ConfluenceClient method pageFromHttpEntity.

/**
 * <p>
 * Creates a Confluence page object from the given entity returned by the server
 * </p>
 *
 * @param entity
 *          the {@code HttpEntity} to create the {@code MutablePage} from
 * @return the Confluence page instance
 * @throws Exception
 */
private MutablePage pageFromHttpEntity(final HttpEntity entity) throws Exception {
    final String stringEntity = EntityUtils.toString(entity, "UTF-8");
    final JSONParser parser = new JSONParser();
    final JSONObject responseObject = (JSONObject) parser.parse(new StringReader(stringEntity));
    @SuppressWarnings("unchecked") final MutablePage response = ((ConfluenceResourceBuilder<MutablePage>) MutablePage.builder()).fromJson(responseObject, new MutablePage());
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) MutablePage(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage) StringReader(java.io.StringReader) ConfluenceResourceBuilder(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder) JSONParser(org.json.simple.parser.JSONParser)

Aggregations

MutablePage (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 ManifoldCFException (org.apache.manifoldcf.core.interfaces.ManifoldCFException)1 ConfluenceException (org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException)1 Label (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Label)1 ConfluenceResourceBuilder (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.builder.ConfluenceResourceBuilder)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1