简体   繁体   中英

Get Jersey protocol from restlet

Is there a way to get the protocol which was used to access a restlet? I would to implement like a slightly different behavior when accessing a servlet via HTTPS for example. How can I check this?

Apparently, you can just inject your HttpServletRequest request like this:

@PUT
@Path("{storage}/{repository}/{path:.*}")
public void upload(@PathParam("storage") String storage,
                   @PathParam("repository") String repository,
                   @PathParam("path") String path,
                   @Context HttpServletRequest request)
        throws IOException,
               AuthenticationException
{
    System.out.println("Using protocol " + request.getRequestURL().toString().split(":")[0]);
}

And this will do the trick.

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