简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM