我在java中创建了一个Web服务,如下所示:
@Path("/rest")
public class GetStatus {
@GET
@Produces("application/xml")
@Path("/getMethod")
public String getDetails() {
return "Hello World !!!";
}
对应的web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>MyWebService</display-name>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.xmlws</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/check/*</url-pattern>
</servlet-mapping>
</web-app>
我的消费方式如下:
String wsdl = "http://localhost:8080/MyWebService/check/rest/getMethod/";
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
HttpGet getMethod = new HttpGet(wsdl);
String responseString = null;
try {
response = httpclient.execute(getMethod);
StatusLine statusLine = response.getStatusLine();
System.out.println("getStatusCode = " + statusLine.getStatusCode());
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e..printStackTrace();
}
但目前的 Web 服务是 HTTP。我如何使它成为 HTTPS?这样做有什么要求?
我知道如何从客户端访问 HTTPS Web 服务,但我想先创建一个 HTTPS 服务。
任何帮助都对此表示赞赏。