Skip to content

feat: Add Cross-Space Reference Resolution Support#332

Merged
Rafal Niski (rafalniski) merged 6 commits into
masterfrom
feat/JAVA-306-cross-space-resulution
Nov 14, 2025
Merged

feat: Add Cross-Space Reference Resolution Support#332
Rafal Niski (rafalniski) merged 6 commits into
masterfrom
feat/JAVA-306-cross-space-resulution

Conversation

@rafalniski
Copy link
Copy Markdown
Contributor

Implements support for cross-space references via the x-contentful-resource-resolution header, enabling automatic resolution of entries/assets from other spaces.

Changes:

  • Added setCrossSpaceTokens() method to CDAClient.Builder with validation (max 20 spaces)
  • Automatically adds x-contentful-resource-resolution header when tokens are configured
  • Cross-space resources are included in response includes and resolved by existing link resolution

Copy link
Copy Markdown
Contributor

@elylucasctfl Ely Lucas (elylucasctfl) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions with the version one being the main, if you think its good let me know and I'll reapprove

Comment thread pom.xml Outdated
<groupId>com.contentful.java</groupId>
<artifactId>java-sdk</artifactId>
<version>10.5.26</version>
<version>10.5.27</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be a minor bump since its a new feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread README.md Outdated
Cross-Space References
----------------------

The SDK supports resolving cross-space references, which allows you to link content across multiple spaces. When cross-space tokens are configured, entries and assets from other spaces will be automatically included in the response's `includes` section and resolved by the SDK's link resolution.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should add the version new features are available in, maybe "In version 10.6.0 and later, the sdk supports..."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +837 to +842
// Add cross-space resolution header if tokens are configured
if (crossSpaceTokens != null && !crossSpaceTokens.isEmpty()) {
String encodedHeader = encodeCrossSpaceTokens(crossSpaceTokens);
okBuilder.addInterceptor(new HeaderInterceptor(
"x-contentful-resource-resolution", encodedHeader));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have actual cross-space requests been tested using this new interceptor? I had been able to add an interceptor by creating my own OkHttpClient, but when I would run the code, I'd get errors like:

com.contentful.java.cda.CDAContentTypeNotFoundException: Could not find content type 'myContentType' for resource with id '...entryId...' of type 'CDAEntry’.
…
Caused by: com.contentful.java.cda.CDAResourceNotFoundException: Could not find id 'myContentType' of type 'CDAContentType’.

noting that myContentType exists in the remote space but not in the one directly being queried

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an issue with the resource factory, thanks for catching it!

Copy link
Copy Markdown
Contributor

@elylucasctfl Ely Lucas (elylucasctfl) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines +104 to +106
if (client.hasCrossSpaceTokens) {
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what's going on here. if the client isn't able to cache the type, it's likely it's because that type is in a different space. OTOH, it could be a race and the type was removed, which would be a valid error. dunno if you have a good way to sort between the two. thanks!

@rafalniski Rafal Niski (rafalniski) merged commit 634bbe0 into master Nov 14, 2025
5 checks passed
@rafalniski Rafal Niski (rafalniski) deleted the feat/JAVA-306-cross-space-resulution branch November 14, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants