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;
}
}
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;
}
Aggregations