Aaron Yang
Aaron Yang

Reputation: 125

How to know if the connection is over HTTPS in a web service call?

Using Jetty 7.0.2. The service listening on both 80 and 443 port. In a one special API, we need connect to another server, which scheme is determined by the incoming call: if the incoming call is HTTP, then we'll reach the other server by HTTP; if the incoming call is HTTPS, then we'll reach the other server by HTTPS.

The web service can injecct a WebServiceContext object in, and we used to use:

MessageContext ctx = (WebServiceContext)wsContext.getMessageContext();
String requestUrl = ctx.get("com.sun.xml.ws.transport.http.servlet.requestURL");

Then we parse the url to know if it's https/http.

However, when we use Jetty, we found requestURL is not injected. Is there another way to workaround?

Upvotes: 1

Views: 209

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

I am not too sure about jetty and kind of web services you are running. But if it uses servlets inside then I believe HttpSerlvetRequest.isSecure() should help you.

boolean isSecure()

Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Upvotes: 1

Related Questions