0

I am trying to have a server (written in java) redirect to a HTTPS url (the url will never change) when accessed. If I compile the code with

java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=password ProxyServer

and enter in the address, port, and localport as

https://google.com 443 5000

And try accessing

localhost:5000

on my machine, then I get the error

java.net.UnknownHostException: https://google.com

After debugging, I am pretty sure it breaks in this code block when I try to create the SSLSocket (secureServer).

    SSLSocket secureServer;
    try { 
        SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        secureServer = (SSLSocket) factory.createSocket(host, port);
        from_server = secureServer.getInputStream();
        to_server = secureServer.getOutputStream();
    }

2 Answers 2

1

The argument you pass as the host to factory.createSocket(host,port) must not have the protocol prepended to it. It should simply be google.com.

The reason is that Java is going to take that host parameter and pass it as input to a DNS lookup. If you were to type host https://google.com on the command line, you'd get a similar failure.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! that let it connect the socket and streams but for some reason its not displaying the website and starting a download of an empty file...time for more debugging.
@sko Glad to hear it! If my answer helped you, please consider accepting it...doing so helps motivate people to keep answering questions. :)
more : don't use IP address. see java bug : bugs.openjdk.java.net/browse/JDK-8133196
0

In here, it says this was a bug and resolved after some releases

In jdk 6 server, we get the same exception but in our jdk 8 server, no exception

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.