Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement RESTful web service using HTTPS

I want to know if I can implement a RESTFul web service using HTTPS instead of HTTP I am using Jersey and Spring to implement RESTFUL web service. If yes then what code changes do I need to make? Following is the code snippet I have

@Component
@Path("/payment")
public class PaymentService {

    @Autowired
    TransactionBo transactionBo;

    @GET
    @Path("{year}/{format}")

    public Response savePayment(@PathParam("year") int year,
            @PathParam("format") String format,@PathParam("name") String name) {

        String result = transactionBo.save(year,format,name);

        return Response.status(200).entity(result).build();

    }

}
like image 852
Parag Avatar asked Jun 19 '26 04:06

Parag


1 Answers

You don't need to do anything different in Jersey or Spring MVC for HTTPS. You do need to enable HTTPS in your servlet container (or load balancer), but this is independent of your REST service, and probably any of your java code.

If you are not using a load balancer, but you are using Tomcat for a servlet container, check here for details to enable HTTPS: https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html. If you are using a load balancer, it's better to enable HTTPS in the load balancer so that you don't have to enable SSL in your backend servlet containers.

like image 181
lreeder Avatar answered Jun 21 '26 19:06

lreeder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!