Skip to Content
0

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

Feb 20 at 10:14 AM

53

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Morten Wittrock
Feb 20 at 10:24 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Morten,

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

Regards,

Saurabh Agarwal

1
Morten Wittrock
Feb 20 at 10:22 AM
0

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

Show 5 Share
10 |10000 characters needed characters left characters exceeded

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

excerpt.txt (1.4 kB)
0

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

0

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

0

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

0

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

0
Ivan Mirisola
Feb 20 at 02:09 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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

1