Skip to content

Commit 822492c

Browse files
Transparent proxy: TP Loader Cloud SDK native integration
1 parent 9d44dd4 commit 822492c

File tree

3 files changed

+911
-0
lines changed

3 files changed

+911
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.sap.cloud.sdk.cloudplatform.connectivity;
2+
3+
import java.io.IOException;
4+
import java.net.InetSocketAddress;
5+
import java.net.Socket;
6+
import java.net.UnknownHostException;
7+
8+
import javax.annotation.Nonnull;
9+
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
14+
15+
/**
16+
* NetworkVerifier that performs TCP socket-based connectivity verification.
17+
*
18+
* <p>
19+
* This implementation uses standard Java socket connections to verify that a remote host and port combination is
20+
* reachable and accepting connections. It establishes a temporary TCP connection to the target endpoint and immediately
21+
* closes it upon successful establishment.
22+
*
23+
* <p>
24+
* <strong>Verification Process:</strong>
25+
* <ol>
26+
* <li>Creates a new TCP socket</li>
27+
* <li>Attempts to connect to the specified host and port with a timeout</li>
28+
* <li>Immediately closes the connection if successful</li>
29+
* <li>Throws appropriate exceptions for failures</li>
30+
* </ol>
31+
*
32+
* <p>
33+
* <strong>Timeout Configuration:</strong> The verification uses a fixed timeout of {@value #HOST_REACH_TIMEOUT}
34+
* milliseconds to prevent indefinite blocking on unreachable endpoints.
35+
*
36+
* <p>
37+
* <strong>Error Handling:</strong>
38+
* <ul>
39+
* <li>{@link UnknownHostException} - Host cannot be resolved to an IP address</li>
40+
* <li>{@link IOException} - Network connectivity issues or connection refused</li>
41+
* </ul>
42+
*
43+
* @see TransparentProxy
44+
* @since 5.24.0
45+
*/
46+
class NetworkVerifier
47+
{
48+
private static final int HOST_REACH_TIMEOUT = 5000;
49+
private static final Logger log = LoggerFactory.getLogger(NetworkVerifier.class);
50+
51+
/**
52+
* {@inheritDoc}
53+
*
54+
* <p>
55+
* This implementation creates a TCP socket connection to the specified host and port to verify connectivity. The
56+
* connection is immediately closed after successful establishment.
57+
*
58+
* @param host
59+
* {@inheritDoc}
60+
* @param port
61+
* {@inheritDoc}
62+
* @throws DestinationAccessException
63+
* {@inheritDoc}
64+
* <p>
65+
* Specific error conditions:
66+
* <ul>
67+
* <li>Host resolution failure - when DNS lookup fails</li>
68+
* <li>Connection failure - when host is unreachable or port is closed</li>
69+
* <li>Network timeouts - when connection attempt exceeds timeout</li>
70+
* </ul>
71+
*/
72+
void verifyHostConnectivity( @Nonnull final String host, final int port )
73+
throws DestinationAccessException
74+
{
75+
log.info("Verifying that transparent proxy host is reachable on {}:{}", host, port);
76+
try( Socket socket = new Socket() ) {
77+
socket.connect(new InetSocketAddress(host, port), HOST_REACH_TIMEOUT);
78+
log.info("Successfully verified that transparent proxy host is reachable on {}:{}", host, port);
79+
}
80+
catch( final UnknownHostException e ) {
81+
throw new DestinationAccessException(
82+
String.format("Host [%s] could not be resolved. Caused by: %s", host, e.getMessage()),
83+
e);
84+
}
85+
catch( final IOException e ) {
86+
throw new DestinationAccessException(
87+
String.format("Host [%s] on port [%d] is not reachable. Caused by: %s", host, port, e.getMessage()),
88+
e);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)