cancel
Showing results for 
Search instead for 
Did you mean: 

UnknownHostException when connecting to an on-prem system through Cloud Connector from SCP

saurabh_agarwal1
Explorer
0 Kudos

Hi,

I am trying to connect to an on-prem TCP server from my trial SCP account using Java. I have installed and configured Cloud Connector (version 2.10.2) on my local machine.

From CC I can successfully connect to the TCP server. From my trial account also connectivity test for the destination created for this TCP server through CC is getting passed.

I have followed the steps given in documentation here. Java runtime is Java EE 6 Web Profile.

Though I am able to connect to another on-prem HTTP server through CC without any issue. The connection to the TCP server is failing throwing an UnknownHostException.

To use the socket proxy I also looked into Java documentation here.

Tried using both virtual host and port as well as the actual host and port in the Java code but to no avail. Every time I see the UnknownHostException in the default trace.

I am not sure what is it that I am doing wrong. Any tips / hints will be very helpful.

Regards,

Saurabh Agarwal

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
Active Contributor
0 Kudos

Hi Saurabh

Reading your code more closely, I see what is probably the problem: Here you create a socket which uses the SOCKS5 proxy:

Socket proxySocket = new Socket(proxy);

However, you then proceed to create a new socket, which does not use the proxy:

Socket client = new Socket("virtual.host", 8765);

To actually use the socket with the proxy, do this instead:

Socket proxySocket = new Socket(proxy);
proxySocket.connect(new InetSocketAddress("virtual.host", 8765));

Regards,

Morten

saurabh_agarwal1
Explorer

Hi Morten,

You are right. Somehow I missed this. Thank you for catching this.

Regards,

Saurabh Agarwal

Answers (3)

Answers (3)

jalf1991
Explorer
0 Kudos

Ivan Mirisola

hi again. In my case i have a spring Boot app and i want to config my connection DB string (MSQL). When i do that and deploy my app i get a exception (TCP/IP) reource fail, time out. I have my server SQL SERVER config with SCC. I have configuring all connection properties in my spring boot application.properties (JPA) generation DB. Please help me in this scenario.

, if you need more information tell me.

thands and apreciate

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Saurabh,

SOCKS proxy is running on every SCP account. Thus, you must connect to this SOCKS5 proxy and perform authentication against it first. Here you will always use localhost and port 20004. Once this is done all request to your virtual address and port (TCP config stored on Cloud Connector's access control) will be done via TCP SOCKS proxy, just as if you were connecting to a local resource. Check the java source code here as refference. Chekc this blog on "How to set up a JDBC Connection using the Cloud Connector". This blog shows you how to connect to a database via JDBC, but you could adapt it perfectly to any TCP service as well.

Regards,
Ivan

saurabh_agarwal1
Explorer

Hi Ivan,

Thank you for your help. I followed the JDBC code and found MySQL connector is also using the same approach to connect to TCP sockets via proxy. It was very helpful.

Regards,

Saurabh Agarwal

MortenWittrock
Active Contributor
0 Kudos

Hi Saurabh

You always need to use the virtual host and port. It would be helpful of you could post the relevant parts of your Java code, i.e. the parts where you create the Proxy object and use that object to actually make a connection.

Regards,

Morten

saurabh_agarwal1
Explorer
0 Kudos

Hi Morten,

Please see the attached file. I first tried to use virtual host but tried the actual one also once I got the exception

excerpt.txt

Regards,

Saurabh Agarwal

MortenWittrock
Active Contributor
0 Kudos

Hello again

The proxy needs the name of the subaccount, but that is not what HC_ACCOUNT contains. Use the Account API, or just add it manually while testing. Also, is your location ID actually abcde12345? If you don't have a location ID, use an empty string.

Regards,

Morten

saurabh_agarwal1
Explorer
0 Kudos

Hi Morten,

Thank you for your suggestion. Tried with TenantContext as well.

tenantContext.getTenant().getAccount().getId()

This is giving the same id which I get from HC_ACCOUNT environment variable.

LocationID I assigned manually for testing as abcde12345 to cloud connector. Although I had tried first without any location id. Got the same issue.

Regards,

Saurabh Agarwal

saurabh_agarwal1
Explorer
0 Kudos

Hi Morten,

I also tried with the Tenant.getId(). It gives me an ID in the format xxxxxxxx-aaaa-yyyy-bbbb-zzzzzzzzzzzz. But this attempt also failed with UnknownHostException.

Regards,

Saurabh Agarwal

MortenWittrock
Active Contributor
0 Kudos

Hello again. Solve one problem at a time: Hardcode the subaccount name and location ID until the code works, then work on retrieving the subaccount name dynamically.

Regards,

Morten