How to get real getAttachmentData with new API approach (Content object)

Hi Community, I’m kindly asking you for advice on the issue that I’m currently facing.
In code, that was working recently we have:

Page page = pageManager.getPage(space.getKey(), title);
String pageBody = page.getBodyAsString();

As you can see, we were able to obtain the page body as a string. This approach is currently still working. however, method getPage on PageManager is deprecated, so I have rewritten the code to this:

Optional<Content> pagex = contentService.find().withType(ContentType.PAGE).withSpace(space).withTitle(title).fetch();
Map<ContentRepresentation, ContentBody> bodyx = pagex.get().getBody(); //This however returns an empty Map. 

In general, I have 2 questions:

  1. The Page returned thru the page manager is com.atlassian.confluence.pages.Page but Page returned with ContentService is Content. Is there any way how to convert content to that Page object? Similar problem I have with Space & SpaceService.
  2. How to get the page body described above? Content was returned correctly, page is found, so why content.getBody() is returning an empty map where pageManger.getPage().getBodyAsString() is returning expected string.

Thanks in the advance.

Hi @Adam3

In my opinion, you can use PageDao (Atlassian Confluence 7.12.0 API) to get Page (Atlassian Confluence 7.12.0 API) object.


I moved on with my problem since that find() was required a new Expansion which I was not able to find in documentation with any reasonable explanation what properties I could pass in and what is the format since you can pass also Expansions. Nevertheless I’m facing similar problem with attachementService which also returns Content.
I can’t use AttachmentDao becuase the spring is failing for finding that bean.
What I’m currently failing on, is how to get real content of the attached file. Originally, the code was:

  Attachment storedData = attachmentManager.getAttachment(space.getHomePage(), ATTACHMENT_NAME);
        if (storedData != null) {
            InputStream is = attachmentManager.getAttachmentData(storedData);

but now with content I don’t know how to achieve that. If I use:

                        new Expansion("body",
                                new Expansions(
                                        new Expansion("storage"))

and then try to get the body, it always return value of the body as “”. The original code was able to read the content of the attachment (which is JSON btw).

And If there is any real documentation how to work with Content Object which is returned with that new API then please please point me there.

Any help is wellcome.