我在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 web服务,但我想首先创建一个HTTPS服务。
任何帮助都会受到同样的赞赏。
发布于 2013-06-26 14:40:01
服务器/servlet容器管理要响应的协议。无论您在哪里发布它,web服务都将在某个web服务器中运行。在您的示例中,它将是一个servlet容器(可能是Tomcat),因为您使用的是servlet。
您需要做一些(相对的)小配置,如果您在Tomcat 7上,您可以找到它这里。
https://stackoverflow.com/questions/17322443
复制相似问题