0
我正在编写REST Web服务。这是Web服务的一个片段:调用REST Web服务的资源
@Path("/first")
public class InitialResource
{
@GET
@Path(value="/{input}/{location}/{category}/{session}")
@Produces({"application/xml", "text/html"})
public List<Message> getMessage(@PathParam("input") String input, @PathParam("location") String location, @PathParam("category") String category, @PathParam("session") String session) throws NotFoundException
{
if(date.recentUpdate(location) == false)// if false, the checking of category update was run later than 1 hour ago
{
user.dropTable(); // invokes method which checks if you need to drop any user's intermediate results table
if(version.getVersion(location)== true) // if version of category did not change
{
}
else
{// version of category old; updates list of category for a specific country
updateCategory.getCategoryList(id.getSiteId(location));
}
}
return search.runSearch(input, location, category, session.split("\\.")[1]);
}
}
如果你调用它通过这个URI
http://localhost:8080/Project/resources/first/cat/EBAY-IE/1/0.123
你得到404 HTTP错误。
下面还有一个资源。
@GET
@Produces("text/html")
public String getMess() {
return "hello";
}
如果这个URI
http://localhost:8080/Project/resources/first
你 “你好” 在屏幕上的字符串调用服务。 为什么我不能用指定路径调用第一个资源?
尝试用“text/plain”替换@Produces({“application/xml”,“text/html”})并返回“hello”,看看是否是问题所在。 – 2011-05-25 01:02:09
既然你抛出一个NotFoundException,我假设你正在触发方法体内的某个地方。尝试删除throws子句。这应该给你一个堆栈跟踪,可能会给你更多的信息。 – stand 2011-05-25 01:20:54