tags:

views:

19

answers:

1

Hi ,

I have writing Java code Using Jersey library to call Rest APIs. For my first method to display all blogs i have written the code like

  return webResource.path(ConfigurationUtil.LIST_BLOGS).header(ConfigurationUtil.AUTHENTICATION_HEADER, authentication)
        .accept(MediaType.APPLICATION_XML_TYPE).get(new GenericType<List<CommunityBean>>() {
    });

which lists all the blogs.. As my LIST_BLOGS string is like

public static final String LIST_BLOGS = "api/blogs.xml";

Its works fine..

Now I'm trying to write a code for a method where I want to extract only 2 blogs and not all

so my url will be like

public static final String LIST_BLOGS = "api/blogs.xml?limit=2";

As I am not able to send the parameter from the wrapper file to ConfigurationUtil file and I used the way as

public List<BlogBean> searchBlogsXml(String limit) {

     final String SEARCH_BLOGS="api/blogs.xml?limit="+limit;

 return webResource.path(SEARCH_BLOGS).header(ConfigurationUtil.AUTHENTICATION_HEADER, authentication)
    .accept(MediaType.APPLICATION_XML_TYPE).get(new GenericType<List<BlogBean>>() {
     });
}

When i used like above i am getting 406 error..

Why so how to avoid this ? Please give suggestions..

+1  A: 

You can attach a query param like this;

resource.queryParam("limit", 2).get(MyObject.class);
Qwerky
where should i have to give the above line...
Aruna
@Aruna queryParam is a method on `WebResource`, see the javadocs https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/WebResource.html#queryParam(java.lang.String,%20java.lang.String)
Qwerky
Thanks .. DOne it..
Aruna