Hi,
I am using Jersey to call the REST API in rails.
I am having two tables as
blogpost(id,title,desc)
comment(id,commentdata)
I am trying to write a method in java to post a comment and my url is
/api/blogs/comment.xml?title=&comment=
THe method i am using is
public BlogBean postComment(String title, String comment) {
System.out.println(title+""+comment);
// Create a multivalued map to store the parameters to be send in
the REST call
MultivaluedMap<String, String> newBlogParam = new
MultivaluedMapImpl();
newBlogParam.add("title", "testingapiblogposttitle");
newBlogParam.add("comment", "aaaaaaaaaaaaaa");
BlogBean blogBean = null;
try {
blogBean =
webResource.path(ConfigurationUtil.POST_COMMENT).header(ConfigurationUtil.AUTHENTICATION_HEADER,
authentication)
.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_XML_TYPE).post(BlogBean.class,
newBlogParam);
} catch (UniformInterfaceException uie) {
if (uie.getResponse().getStatus() == 401) {
System.out.println("Can not authenticate user
"+ConfigurationUtil.userName +
“. Please check your username/password and try
again.” );
} else {
System.out.println("Error when trying to talk to app. "
-
"HTTP status code
"+uie.getResponse().getStatus()+“returned. Finishing.”);
}
return null;
} catch (ClientHandlerException che) {
System.out.println("Error when trying to talk toapp. Network
issues? " +
"Please check the following message and try again later:
"+che.getMessage());
return null;
}
return blogBean;
}
where ConfigurationUtil.POST_COMMENT= “api/blogs/comment.xml”
xmlrootelement i am using is “blogpost”
When i run this one i am getting error as
Exception in thread “main” javax.ws.rs.WebApplicationException:
javax.xml.bind.UnmarshalException: unexpected element (uri:"",
local:“message”). Expected elements are <{}blogpost>
…
…
Caused by: javax.xml.bind.UnmarshalException: unexpected element
(uri:"", local:“message”). Expected elements are <{}blogpost>
…
…
Why i am getting this error . How to avoid this??
Pls give suggestions