2011-06-17 52 views
1

我是澤西島和REST的新手,請原諒,如果我的問題太愚蠢。我有一個簡單的資源稱爲地方,它應該支持GET操作,它返回基於輸入變量的興趣點。以下是輸入字符串和類:新澤西州 - 在資源中獲取不受支持的媒體類型

錯誤:

HTTP 415 - Unsupported Media Type 

輸入網址:

http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food 

類:

@Path("/places") 
public class Places { 

    @GET 
    @Produces(MediaType.APPLICATION_JSON) 
    public JSONObject getPlaces(@QueryParam("latitude") double latitude, 
      @QueryParam("longitude") double longitude, 
      @QueryParam("radius") int radius, 
      @QueryParam("types") String types, 
      @DefaultValue("true") boolean sensor) { 
     GooglePlacesClient google = new GooglePlacesClient(); 
     JSONObject json = null; 

     try { 
      String response = google.performPlacesSearch(latitude, longitude, radius, types, sensor); 
      json = new JSONObject(response); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return json; 
    } 
} 
+0

你接受'應用/ json'機構?設置一個http-header到application/json(頭部名稱:'Accept',value ='application/json') – chahuistle 2011-06-17 08:16:59

回答

5

@DefaultValue不無@QueryParam工作。嘗試添加@QueryParam註釋到sensor -argument(見DefaultValue javadoc

0

請務必休息[網址]映射在web.xml

http://localhost:8080/RESTGO/**`*rest*`**/places 
相關問題