I am new to Angular JS and REST services and just trying hello world.
web.xml
<servlet>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.ipocc.service</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
REST SERVICE CLASS
@Path("/UserManager")
public class UserManagerService {
@POST
@Path("/validate")
@Consumes({ MediaType.APPLICATION_JSON } )
public Response responseMsg1(final User user) {
System.out.println("POST :" + user + " " + user.getUserName() + " " + user.getPassword());
return Response.status(200).entity("output").build();
}
}
DTO
@XmlRootElement
public class User {
@XmlElement public String email;
@XmlElement public String name;
@XmlElement public String username;
//GETTER-SETTER
}
ANGULAR JS FILE
var validationApp = angular.module('validationApp', []);
validationApp.controller('mainController', function($scope,$http) {
$scope.submitForm = function() {
var update_path = "http://localhost:8080/IPOCCService/rest/UserManager/validate";
var data1 = angular.toJson($scope.user);
alert(data1);
$http({
url: update_path,
method: "POST",
data: data1,
headers : {
"Content-Type" : "application/json; charset=utf-8",
"Accept" : "application/json"
}
}).
success(function(data, status, headers, config) {
alert("success");
}).
error(function(data, status, headers, config) {
alert("failure");
});
};
});
ERROR I AM FACING
SEVERE: A message body reader for Java class com.ipocc.service.dto.User, and Java type class com.ipocc.service.dto.User, and MIME media type application/json; charset=UTF-8 was not found.
The registered message body readers compatible with the MIME media type are:
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
I want to achieve the when I call http post request from Angular JS, it should get map to user object but I am getting error above. If I keep parameter as String then I am getting data as email:"a@a.com",name: "j",username: "j"