我是RestEasy webservice的新手。我正在尝试使用RestEasy实现Helloworld示例。我做了所有必要的配置(比如web.xml条目,应用注释等)来公开资源方法。每件事看起来都不错,但是一旦我从Restclient调用Web服务,我就得到了404 Not found response。
我为此示例提供了以下代码:
TestApplication.java
package com.cole.wc.test.webservice;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class TestApplication extends Application{
private Set<Object> singletons = new HashSet<Object>();
/**
* @param args
*/
public TestApplication() {
// TODO Auto-generated constructor stub
System.out.println("RestEasy $$$$$$$$$$$$$$$$$$$$$$$$");
singletons.add(new TestImpl());
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
TestImpl.java
package com.cole.wc.test.webservice;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/webservice")
public class TestImpl{
@GET
@Path("/{param}/add")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response printPathMessage(@PathParam("param") String param) {
String result = "Simple webservice test success : " + param;
System.out.println("1 result --- "+result);
return Response.status(200).entity("RestEasy Response").build();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"
metadata-complete="true">
<servlet>
<description>RESTEasy Servlet</description>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.cole.wc.test.webservice.TestApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/servlet/resteasy/*</url-pattern>
</servlet-mapping>
</web-app>
以下是我项目中包含的jar文件
“javax.ws.rs.jar”
“RestEasy的客户端 - 3.0.13.Final.jar”
以下是我尝试从RestClient调用的URL 的 http://localhost/MyApp/servlet/rest/webservice/ {12} /添加
我在控制台中看到输出“RestEasy $$$$$$$$$$$$$$$$$$$$$$”,从中我们可以看出控制权已达到TestApplication构造函数
如果我遗漏了要包含的任何罐子,或者URI不正确,请告诉我。您是否愿意指出我正确的方向来成功调用此服务。
感谢您的时间