2011-05-25 87 views
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  

你 「你好」 在屏幕上的字符串調用服務。 爲什麼我不能用指定路徑調用第一個資源?

+0

嘗試用「text/plain」替換@Produces({「application/xml」,「text/html」})並返回「hello」,看看是否是問題所在。 – 2011-05-25 01:02:09

+0

既然你拋出一個NotFoundException,我假設你正在觸發方法體內的某個地方。嘗試刪除throws子句。這應該給你一個堆棧跟蹤,可能會給你更多的信息。 – stand 2011-05-25 01:20:54

回答

1

謝謝您的建議,但問題在別處。我通過客戶端(瀏覽器)訪問Web服務時發生HTTP 404錯誤。使用URI我只是無法連接到服務器。我只需要更新端口。然後我更新了客戶端代碼(Javascript)訪問服務的路徑。服務體系運行良好。謝謝