4
4
5
5
package com .sap .cloud .sdk .cloudplatform .connectivity ;
6
6
7
+ import static com .sap .cloud .sdk .cloudplatform .connectivity .DestinationKeyStoreComparator .resolveCertificatesOnly ;
8
+ import static com .sap .cloud .sdk .cloudplatform .connectivity .DestinationKeyStoreComparator .resolveKeyStoreHashCode ;
9
+
7
10
import java .net .URI ;
8
11
import java .security .KeyStore ;
9
12
import java .util .ArrayList ;
20
23
import javax .annotation .Nullable ;
21
24
import javax .net .ssl .SSLContext ;
22
25
26
+ import org .apache .commons .lang3 .builder .EqualsBuilder ;
27
+ import org .apache .commons .lang3 .builder .HashCodeBuilder ;
28
+
23
29
import com .google .common .collect .ImmutableList ;
24
30
import com .google .common .collect .Lists ;
25
31
import com .google .common .net .HttpHeaders ;
36
42
import io .vavr .control .Option ;
37
43
import io .vavr .control .Try ;
38
44
import lombok .AccessLevel ;
39
- import lombok .EqualsAndHashCode ;
40
45
import lombok .Getter ;
41
46
import lombok .experimental .Delegate ;
42
47
import lombok .extern .slf4j .Slf4j ;
43
48
44
49
/**
45
50
* Immutable default implementation of the {@link HttpDestination} interface.
46
51
*/
47
- @ EqualsAndHashCode
48
52
@ Slf4j
49
53
public final class DefaultHttpDestination implements HttpDestination
50
54
{
51
55
@ Delegate
52
56
private final DestinationProperties baseProperties ;
53
57
54
- @ EqualsAndHashCode .Exclude
55
58
private final KeyStore keyStore ;
56
- @ EqualsAndHashCode .Exclude
57
59
private final KeyStore trustStore ;
58
60
59
61
@ Nonnull
60
62
final ImmutableList <Header > customHeaders ;
61
63
62
64
@ Nonnull
63
65
@ Getter ( AccessLevel .PACKAGE )
64
- @ EqualsAndHashCode .Exclude
65
66
private final ImmutableList <DestinationHeaderProvider > customHeaderProviders ;
66
67
67
68
@ Nonnull
68
- @ EqualsAndHashCode .Exclude
69
69
private final ImmutableList <DestinationHeaderProvider > headerProvidersFromClassLoading ;
70
70
71
71
// the following 'cached' fields are ALWAYS derived from the baseProperties and stored in the corresponding fields
@@ -77,27 +77,21 @@ public final class DefaultHttpDestination implements HttpDestination
77
77
// furthermore, it is safe to exclude these fields from the equals and hashCode methods because their values are
78
78
// purely derived from the baseProperties, which are included in the equals and hashCode methods.
79
79
@ Nonnull
80
- @ EqualsAndHashCode .Exclude
81
80
private final Option <ProxyConfiguration > cachedProxyConfiguration ;
82
81
83
82
@ Nonnull
84
- @ EqualsAndHashCode .Exclude
85
83
private final Option <ProxyType > cachedProxyType ;
86
84
87
85
@ Nonnull
88
- @ EqualsAndHashCode .Exclude
89
86
private final Option <BasicCredentials > cachedBasicCredentials ;
90
87
91
88
@ Nonnull
92
- @ EqualsAndHashCode .Exclude
93
89
private final AuthenticationType cachedAuthenticationType ;
94
90
95
91
@ Nonnull
96
- @ EqualsAndHashCode .Exclude
97
92
private final ImmutableList <Header > cachedHeadersFromProperties ;
98
93
99
94
@ Nonnull
100
- @ EqualsAndHashCode .Exclude
101
95
private final ImmutableList <Header > cachedProxyAuthorizationHeaders ;
102
96
103
97
private DefaultHttpDestination (
@@ -511,6 +505,37 @@ public static Builder fromDestination( @Nonnull final Destination destination )
511
505
return builder ;
512
506
}
513
507
508
+ @ Override
509
+ public boolean equals ( @ Nullable final Object o )
510
+ {
511
+ if ( this == o ) {
512
+ return true ;
513
+ }
514
+
515
+ if ( o == null || getClass () != o .getClass () ) {
516
+ return false ;
517
+ }
518
+
519
+ final DefaultHttpDestination that = (DefaultHttpDestination ) o ;
520
+ return new EqualsBuilder ()
521
+ .append (baseProperties , that .baseProperties )
522
+ .append (customHeaders , that .customHeaders )
523
+ .append (resolveCertificatesOnly (keyStore ), resolveCertificatesOnly (that .keyStore ))
524
+ .append (resolveCertificatesOnly (trustStore ), resolveCertificatesOnly (that .trustStore ))
525
+ .isEquals ();
526
+ }
527
+
528
+ @ Override
529
+ public int hashCode ()
530
+ {
531
+ return new HashCodeBuilder (17 , 37 )
532
+ .append (baseProperties )
533
+ .append (customHeaders )
534
+ .append (resolveKeyStoreHashCode (keyStore ))
535
+ .append (resolveKeyStoreHashCode (trustStore ))
536
+ .toHashCode ();
537
+ }
538
+
514
539
/**
515
540
* Builder class to allow for easy creation of an immutable {@code DefaultHttpDestination} instance.
516
541
*/
0 commit comments