Skip to content

Commit 55ccc62

Browse files
committed
feat: release version 2.7.0 with endpoint integration and enhancements
- Added new endpoint integration for Contentstack API. - Introduced a script to refresh the bundled regions.json from the Contentstack artifact registry. - Enhanced Config class to track if the host has been overridden. - Implemented Endpoint class to resolve Contentstack API endpoints dynamically. - Added integration tests for endpoint resolution and service availability. - Updated Stack class to prioritize explicit host settings over region resolution. - Updated CHANGELOG.md to reflect the new version and changes.
1 parent 14ea923 commit 55ccc62

10 files changed

Lines changed: 1055 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## v2.7.0
4+
5+
### Jun 15, 2026
6+
- Enhancement: Endpoint integration
7+
38
## v2.6.0
49

510
### Feb 23, 2026

pom.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>2.6.0</version>
8+
<version>2.7.0</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>
@@ -462,6 +462,34 @@
462462
<artifactId>maven-jxr-plugin</artifactId>
463463
<version>2.3</version>
464464
</plugin>
465+
466+
<!--
467+
Refresh the bundled regions.json from the Contentstack artifact registry.
468+
Run whenever Contentstack adds new regions or service keys, then commit
469+
the updated src/main/resources/assets/regions.json.
470+
471+
Usage:
472+
mvn exec:exec@refresh-regions
473+
-->
474+
<plugin>
475+
<groupId>org.codehaus.mojo</groupId>
476+
<artifactId>exec-maven-plugin</artifactId>
477+
<version>3.1.0</version>
478+
<executions>
479+
<execution>
480+
<id>refresh-regions</id>
481+
<goals>
482+
<goal>exec</goal>
483+
</goals>
484+
<configuration>
485+
<executable>bash</executable>
486+
<arguments>
487+
<argument>${project.basedir}/scripts/download-regions.sh</argument>
488+
</arguments>
489+
</configuration>
490+
</execution>
491+
</executions>
492+
</plugin>
465493
</plugins>
466494
</build>
467495

scripts/download-regions.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Download the latest regions.json from the Contentstack artifacts registry and
3+
# write it to src/main/resources/assets/regions.json so it gets bundled into
4+
# the SDK jar on the next build.
5+
#
6+
# Usage:
7+
# ./scripts/download-regions.sh
8+
# mvn exec:exec@refresh-regions
9+
#
10+
# Run this whenever Contentstack announces new regions or service keys, then
11+
# commit the updated file:
12+
# git add src/main/resources/assets/regions.json
13+
# git commit -m "chore: refresh regions.json"
14+
15+
set -euo pipefail
16+
17+
REGIONS_URL="https://artifacts.contentstack.com/regions.json"
18+
DEST="$(dirname "$0")/../src/main/resources/assets/regions.json"
19+
DEST="$(cd "$(dirname "$DEST")" && pwd)/$(basename "$DEST")"
20+
21+
echo "Downloading regions.json from ${REGIONS_URL} ..."
22+
23+
if command -v curl &>/dev/null; then
24+
curl --silent --show-error --fail --location \
25+
--retry 3 --retry-delay 2 \
26+
-o "${DEST}" "${REGIONS_URL}"
27+
elif command -v wget &>/dev/null; then
28+
wget --quiet --tries=3 --waitretry=2 -O "${DEST}" "${REGIONS_URL}"
29+
else
30+
echo "Error: neither curl nor wget found. Install one and retry." >&2
31+
exit 1
32+
fi
33+
34+
# Validate the downloaded file contains a "regions" array
35+
if ! python3 -c "import sys, json; d=json.load(open('${DEST}')); assert 'regions' in d and len(d['regions']) > 0" 2>/dev/null &&
36+
! python -c "import sys, json; d=json.load(open('${DEST}')); assert 'regions' in d and len(d['regions']) > 0" 2>/dev/null; then
37+
# Fallback validation without Python — just check the key exists
38+
if ! grep -q '"regions"' "${DEST}"; then
39+
echo "Error: downloaded file does not look like a valid regions.json" >&2
40+
rm -f "${DEST}"
41+
exit 1
42+
fi
43+
fi
44+
45+
REGION_COUNT=$(grep -o '"id"' "${DEST}" | wc -l | tr -d ' ')
46+
echo "contentstack-java: regions.json updated (${REGION_COUNT} regions) → ${DEST}"

src/main/java/com/contentstack/sdk/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class Config {
1818
protected String livePreviewContentType = null;
1919
protected String livePreviewEntryUid = null;
2020
protected String host = "cdn.contentstack.io";
21+
protected boolean hostOverridden = false;
2122
protected String version = "v3";
2223
protected String scheme = "https://";
2324
protected String endpoint;
@@ -167,6 +168,7 @@ public String getHost() {
167168
public void setHost(String hostName) {
168169
if (hostName != null && !hostName.isEmpty()) {
169170
host = hostName;
171+
hostOverridden = true;
170172
}
171173
}
172174

src/main/java/com/contentstack/sdk/Contentstack.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.contentstack.sdk;
22

3+
import java.util.Map;
34
import java.util.Objects;
45

56
/**
@@ -98,6 +99,60 @@ private static void validateCredentials(String stackApiKey, String deliveryToken
9899
}
99100
}
100101

102+
/**
103+
* Returns the Contentstack API URL for the given region and service.
104+
*
105+
* <p>Delegates to {@link Endpoint#getContentstackEndpoint(String, String)} — provided as a
106+
* convenience so callers can reach endpoint resolution through the same top-level class they
107+
* use to create stacks.
108+
*
109+
* @param region region ID or alias (e.g. {@code "na"}, {@code "eu"}, {@code "azure-na"})
110+
* @param service service key (e.g. {@code "contentDelivery"}, {@code "contentManagement"})
111+
* @return full URL including {@code https://} scheme
112+
* @throws IllegalArgumentException if the region or service is not recognised
113+
*/
114+
public static String getContentstackEndpoint(String region, String service) {
115+
return Endpoint.getContentstackEndpoint(region, service);
116+
}
117+
118+
/**
119+
* Returns the Contentstack API URL for the given region and service, optionally stripping
120+
* the {@code https://} scheme.
121+
*
122+
* @param region region ID or alias
123+
* @param service service key
124+
* @param omitHttps when {@code true}, returns the bare host without {@code https://}
125+
* @return URL or bare host
126+
* @throws IllegalArgumentException if the region or service is not recognised
127+
*/
128+
public static String getContentstackEndpoint(String region, String service, boolean omitHttps) {
129+
return Endpoint.getContentstackEndpoint(region, service, omitHttps);
130+
}
131+
132+
/**
133+
* Returns all service endpoints for the given region as an ordered map of service key to URL.
134+
*
135+
* @param region region ID or alias
136+
* @return map of service key → full URL
137+
* @throws IllegalArgumentException if the region is not recognised
138+
*/
139+
public static Map<String, String> getContentstackEndpoints(String region) {
140+
return Endpoint.getAllEndpoints(region);
141+
}
142+
143+
/**
144+
* Returns all service endpoints for the given region, optionally stripping the
145+
* {@code https://} scheme from every URL.
146+
*
147+
* @param region region ID or alias
148+
* @param omitHttps when {@code true}, returns bare hosts without {@code https://}
149+
* @return map of service key → URL or bare host
150+
* @throws IllegalArgumentException if the region is not recognised
151+
*/
152+
public static Map<String, String> getContentstackEndpoints(String region, boolean omitHttps) {
153+
return Endpoint.getAllEndpoints(region, omitHttps);
154+
}
155+
101156
private static Stack initializeStack(String stackApiKey, String deliveryToken, String environment, Config config) {
102157
Stack stack = new Stack(stackApiKey.trim());
103158
stack.setHeader("api_key", stackApiKey);

0 commit comments

Comments
 (0)