java中基于SSL TLS1.2的REST Web服务
我需要用java开发一个基于ssl tls1.2的rest Web服务,我已经用java编写了简单的rest Web服务。我需要向代码中添加什么才能使其成为启用SSL TLS1.2的代码java中基于SSL TLS1.2的REST Web服务,java,rest,ssl,tls1.2,Java,Rest,Ssl,Tls1.2,我需要用java开发一个基于ssl tls1.2的rest Web服务,我已经用java编写了简单的rest Web服务。我需要向代码中添加什么才能使其成为启用SSL TLS1.2的代码 package nit.ws; import java.io.File; import java.io.FileInputStream; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import
package nit.ws;
import java.io.File;
import java.io.FileInputStream;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path("/test")
public class Test {
@GET
@Path("/hi")
@Produces(MediaType.TEXT_PLAIN)
public String sayHi()
{
return "Hi, welcome to rest world";
}
@GET
@Path("/pdf")
@Produces("application/pdf")
public javax.ws.rs.core.Response getPdf() throws Exception
{
File file = new File("C:\\Users\\juke\\Desktop\\learning.pdf");
FileInputStream fileInputStream = new FileInputStream(file);
javax.ws.rs.core.Response.ResponseBuilder responseBuilder = javax.ws.rs.core.Response.ok((Object) fileInputStream);
responseBuilder.type("application/pdf");
responseBuilder.header("Content-Disposition", "filename=test.pdf");
return responseBuilder.build();
}
}
您在哪台服务器上部署应用程序?我正在wildfly服务器上部署。对于TLS 1.2支持,请使用最新的wildfly和Java版本(例如Java 11)。他们应该使用现成的TLS 1.2。当然,您仍然必须提供匹配的SSL/TLS证书和私钥。