views:

86

answers:

6

Hi, I have a web-service endpoint and a http connector on port X. At some point this endpoint needs to switch to https, but on the same port! (I know this is not the normal way of doing things, but this is what my clients expect from an old server they are using...)

Is there a way to do it in tomcat?

+3  A: 

There is no way to run both HTTP and HTTPS on the same port.

Emil Vikström
A: 

You could eventually use a proxy.

thelost
A: 

You don't need to run the HTTP & HTTPS on same port, Configure the Tomcat to redirect requests to HTTPS in server.xml file.

Phani
+1  A: 

This is not possible with Tomcat.The HTTPS connector will accept SSL connection only.

We have such a proxy developed in house. It's not that hard to do. You just need to check the first incoming packet. Looking for the pattern of SSL handshake. We only look for CLIENT_HELLO. Once you figure out the protocol, you can forward the request accordingly.

This is really ugly. You shouldn't do it if all possible. We have to do it because the legacy clients do this and it's impossible to upgrade them all.

ZZ Coder
A: 

well I wonder why they are NOT usually on the same port! wouldn't that be easier?

the reason is probably that related Java APIS (javax.net.ssl) don't allow that; you must have different server sockets. are there any alternative SSL impls for Java? I'm not aware of any.

irreputable
A: 

There is such a thing as HTTPS upgrade, whereby a plaintext HTTP connection is upgraded to HTTP by mutual agreement after it has been formed. Is that what you mean? If so, Tomcat doesn't seem to support it out of the box, and neither does Java out of the box either. You can probably write yourself a Tomcat Connector that will do it; on the client end you have a more interesting problem ;-)

But I would ask why? Ports aren't so expensive that you can't use two.

EJP