archivingservice:
clientid: ${vcap.services.data-archiving-service.credentials.uaa.clientid}
certificate: ${vcap.services.data-archiving-service.credentials.uaa.certificate}
key: ${vcap.services.data-archiving-service.credentials.uaa.key}
archivingServiceUrl: ${vcap.services.data-archiving-service.credentials.archivingServiceUrl}
uaadomain: ${vcap.services.data-archiving-service.credentials.uaa.uaadomain}
space: ${vcap.application.space_name}
package com.sap.dataarchiving.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties("archivingservice")
public class ArchivingServiceConfigParameters {
/**
* platform archiving service attributes
*/
private String archivingServiceUrl;
private String uaadomain;
private String clientId;
private String certificate;
private String key;
private String space;
public String getArchivingServiceUrl() {
return archivingServiceUrl;
}
public void setArchivingServiceUrl(String archivingServiceUrl) {
this.archivingServiceUrl = archivingServiceUrl;
}
public String getUaadomain() {
return uaadomain;
}
public void setUaadomain(String uaadomain) {
this.uaadomain = uaadomain;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getCertificate() {
return certificate;
}
public void setCertificate(String certificate) {
this.certificate = certificate;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getSpace() {
return space;
}
public void setSpace(String space) {
this.space = space;
}
}
public OAuth2TokenResponse retrieveToken(String certificate, String key, String clientID, String url) {
OAuth2ServiceConfigurationBuilder builder = OAuth2ServiceConfigurationBuilder.forService(Service.XSUAA);
OAuth2ServiceConfiguration config = builder.withClientId(clientID).withCertificate(certificate).withPrivateKey(key)
.withCertUrl(url).build();
XsuaaTokenFlows xs = new XsuaaTokenFlows(
new DefaultOAuth2TokenService(HttpClientFactory.create(config.getClientIdentity())),
new XsuaaDefaultEndpoints(config), config.getClientIdentity());
OAuth2TokenResponse token = null;
try {
token = xs.clientCredentialsTokenFlow().disableCache(true).execute();
} catch (IllegalArgumentException | TokenFlowException e) {
LOGGER.error("Failed to fetch oauth token: {}, {}", e.getMessage(), e.getCause());
throw new CertificateOAuthException(e.getMessage());
}
return token;
}
OAuth2TokenResponse token = certToken.retrieveToken(certificate,key,clientId,tokenURL);
String tokenValue =token.getAccessToken();
WebClient newClient = client.mutate().filter(logResponse()).build();
Mono<String> resource = newClient.put()
.uri(url)
.headers(h -> h.setBearerAuth(tokenValue))
.bodyValue(archiveData)
.retrieve()
.bodyToMono(String.class)
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5)));
String response = resource.block();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 |