MCPcopy Create free account
hub / github.com/GDATASoftwareAG/vaas / Vaas

Class Vaas

java/src/main/java/de/gdata/vaas/Vaas.java:42–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40import static de.gdata.vaas.CompletableFutureExceptionHandler.handleException;
41
42public class Vaas implements IVaas {
43 private static final String userAgent = "Java/9.0.0";
44
45 @Getter
46 @NonNull
47 private final VaasConfig config;
48
49 private final IAuthenticator authenticator;
50 private final HttpClient httpClient;
51
52 public Vaas(@NonNull VaasConfig config, @NonNull IAuthenticator authenticator) {
53 this.config = config;
54 this.authenticator = authenticator;
55 this.httpClient = HttpClient.newBuilder()
56 .version(HttpClient.Version.HTTP_1_1)
57 .connectTimeout(Duration.ofMillis(config.getDefaultTimeoutInMs()))
58 .build();
59 }
60
61 public Vaas(@NotNull VaasConfig config, IAuthenticator authenticator, HttpClient httpClient) {
62 this.config = config;
63 this.authenticator = authenticator;
64 this.httpClient = httpClient;
65 }
66
67 public Vaas(IAuthenticator authenticator) {
68 this(new VaasConfig(), authenticator);
69 }
70
71 private static void throwParsedVaasError(HttpResponse<String> response) throws VaasAuthenticationException, VaasClientException, VaasServerException {
72 try {
73 var problemDetails = ProblemDetails.fromJson(response.body());
74 if(problemDetails == null) {
75 throw new JsonSyntaxException("no JSON in server response");
76 }
77 var type = problemDetails.type;
78 var detail = problemDetails.detail;
79 if (type.equals("VaasClientException")) {
80 throw new VaasClientException(detail);
81 } else if (type.equals("VaasAuthenticationException")) {
82 throw new VaasAuthenticationException(detail);
83 }
84 throw new VaasServerException(detail);
85 } catch(JsonSyntaxException e) {
86 if (response.statusCode() == 401) {
87 throw new VaasAuthenticationException(
88 "Server did not accept token from identity provider. Check if you are using the correct identity provider and credentials.");
89 } else if (response.statusCode() >= 400 && response.statusCode() < 500) {
90 throw new VaasClientException("HTTP Error: " + response.statusCode() + " for request " + response.uri());
91 } else {
92 throw new VaasServerException("HTTP Error: " + response.statusCode() + " for request " + response.uri());
93 }
94 }
95 }
96
97 private static String encodeParams(Map<String, String> params) {
98 StringBuilder encodedParams = new StringBuilder();
99 for (Map.Entry<String, String> entry : params.entrySet()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected