on 02-20-2018 10:14 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Morten,
You are right. Somehow I missed this. Thank you for catching this.
Regards,
Saurabh Agarwal
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Regards,
Saurabh Agarwal
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
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
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.