Skip to content

Commit ff6bc86

Browse files
committed
impl
1 parent 1a03446 commit ff6bc86

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Destination loadAndParseDestination( final String destName, final DestinationOpt
130130
{
131131
final String servicePath = PATH_DEFAULT + destName;
132132
final Function<DestinationRetrievalStrategy, DestinationServiceV1Response> destinationRetriever =
133-
strategy -> resilientCall(() -> retrieveDestination(strategy, servicePath), singleDestResilience);
133+
strategy -> resilientCall(() -> retrieveDestination(strategy, servicePath, options), singleDestResilience);
134134

135135
final DestinationRetrievalStrategyResolver destinationRetrievalStrategyResolver =
136136
DestinationRetrievalStrategyResolver
@@ -145,7 +145,16 @@ Destination loadAndParseDestination( final String destName, final DestinationOpt
145145
DestinationServiceV1Response
146146
retrieveDestination( final DestinationRetrievalStrategy strategy, final String servicePath )
147147
{
148-
final String response = adapter.getConfigurationAsJson(servicePath, strategy);
148+
return retrieveDestination(strategy, servicePath, DestinationOptions.builder().build());
149+
}
150+
151+
@Nonnull
152+
DestinationServiceV1Response retrieveDestination(
153+
final DestinationRetrievalStrategy strategy,
154+
final String servicePath,
155+
final DestinationOptions options )
156+
{
157+
final String response = adapter.getConfigurationAsJson(servicePath, strategy, options);
149158

150159
return deserializeDestinationResponse(response);
151160
}

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceAdapter.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,25 @@ String getConfigurationAsJson(
119119
@Nonnull final DestinationRetrievalStrategy strategy )
120120
throws DestinationAccessException,
121121
DestinationNotFoundException
122+
{
123+
return getConfigurationAsJson(servicePath, strategy, DestinationOptions.builder().build());
124+
}
125+
126+
@Nonnull
127+
String getConfigurationAsJson(
128+
@Nonnull final String servicePath,
129+
@Nonnull final DestinationRetrievalStrategy strategy,
130+
@Nonnull final DestinationOptions options )
131+
throws DestinationAccessException,
132+
DestinationNotFoundException
122133
{
123134
final HttpDestination serviceDestination =
124135
Objects
125136
.requireNonNull(
126137
serviceDestinationLoader.apply(strategy.behalf()),
127138
() -> "Destination for Destination Service on behalf of " + strategy.behalf() + " not found.");
128139

129-
final HttpUriRequest request = prepareRequest(servicePath, strategy);
140+
final HttpUriRequest request = prepareRequest(servicePath, strategy, options);
130141

131142
final HttpResponse response;
132143
try {
@@ -174,9 +185,20 @@ private static String handleResponse( final HttpUriRequest request, final HttpRe
174185

175186
private HttpUriRequest prepareRequest( final String servicePath, final DestinationRetrievalStrategy strategy )
176187
{
188+
return prepareRequest(servicePath, strategy, DestinationOptions.builder().build());
189+
}
190+
191+
private HttpUriRequest prepareRequest(
192+
final String servicePath,
193+
final DestinationRetrievalStrategy strategy,
194+
final DestinationOptions options )
195+
{
196+
final String apiVersion = DestinationServiceOptionsAugmenter.getApiVersion(options).getOrElse("v1");
197+
final String basePath = "destination-configuration/" + apiVersion;
198+
177199
final URI requestUri;
178200
try {
179-
requestUri = new URI(SERVICE_PATH + servicePath);
201+
requestUri = new URI(basePath + servicePath);
180202
}
181203
catch( final URISyntaxException e ) {
182204
throw new DestinationAccessException(e);

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationServiceOptionsAugmenter.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class DestinationServiceOptionsAugmenter implements DestinationOptionsAug
2020
static final String DESTINATION_TOKEN_EXCHANGE_STRATEGY_KEY = "scp.cf.destinationTokenExchangeStrategy";
2121
static final String X_REFRESH_TOKEN_KEY = "x-refresh-token";
2222
static final String X_FRAGMENT_KEY = "X-fragment-name";
23+
static final String DESTINATION_SERVICE_API_VERSION_KEY = "scp.cf.destinationServiceApiVersion";
2324

2425
private final Map<String, Object> parameters = new HashMap<>();
2526

@@ -105,6 +106,22 @@ public DestinationServiceOptionsAugmenter fragmentName( @Nonnull final String fr
105106
return this;
106107
}
107108

109+
/**
110+
* Sets the API version to use when calling the destination service. This allows opting into newer API versions. If
111+
* not set, the default API version (v1) will be used.
112+
*
113+
* @param apiVersion
114+
* The API version to use (e.g., "v1", "v2").
115+
* @return The same augmenter that called this method.
116+
* @since 5.22.0
117+
*/
118+
@Nonnull
119+
public DestinationServiceOptionsAugmenter apiVersion( @Nonnull final String apiVersion )
120+
{
121+
parameters.put(DESTINATION_SERVICE_API_VERSION_KEY, apiVersion);
122+
return this;
123+
}
124+
108125
@Override
109126
public void augmentBuilder( @Nonnull final DestinationOptions.Builder builder )
110127
{
@@ -170,4 +187,22 @@ static Option<String> getFragmentName( @Nonnull final DestinationOptions options
170187
{
171188
return options.get(X_FRAGMENT_KEY).filter(String.class::isInstance).map(String.class::cast);
172189
}
190+
191+
/**
192+
* Retrieves the configured API version to use when calling the destination service.
193+
*
194+
* @param options
195+
* The destination options instance that stores the key/value pair.
196+
* @return An {@link Option} wrapping the API version if the parameter is present, otherwise a
197+
* {@link io.vavr.control.Option.None}.
198+
* @since 5.22.0
199+
*/
200+
@Nonnull
201+
static Option<String> getApiVersion( @Nonnull final DestinationOptions options )
202+
{
203+
return options
204+
.get(DESTINATION_SERVICE_API_VERSION_KEY)
205+
.filter(String.class::isInstance)
206+
.map(String.class::cast);
207+
}
173208
}

release_notes.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212

1313
### ✨ New Functionality
1414

15-
-
15+
- **Destination Service API Version Support**: Added support for specifying the API version when calling the destination service. Users can now opt into newer API versions (e.g., v2) by using the new `apiVersion()` method on `DestinationServiceOptionsAugmenter`. If not specified, the default API version (v1) is used, ensuring backward compatibility.
16+
17+
Example usage:
18+
```java
19+
// Use the new v2 API
20+
DestinationOptions options = DestinationOptions.builder()
21+
.augmentBuilder(DestinationServiceOptionsAugmenter.augmenter().apiVersion("v2"))
22+
.build();
23+
24+
Destination destination = DestinationAccessor.getDestination("my-destination", options);
25+
```
1626

1727
### 📈 Improvements
1828

1929
-
2030

2131
### 🐛 Fixed Issues
2232

23-
-
33+
-

0 commit comments

Comments
 (0)