0
Ich benutze Spring MVC mit Ruhezustand. Ich habe einen RESTful Web-Service, geschrieben Jersey verwenden, die wie folgt aussieht:Etat HTTP 415 - Nicht unterstützter Medientyp: GET nicht erreichen Jersey REST
@GET
@Path("/interets/{idCentre}/annonces")
@Produces(MediaType.APPLICATION_JSON)
public List<Annonce> getAnnonceParCentre(@PathParam(value="idCentre") int idCentre){
return metier.getAnnonceParCentre(idCentre);
}
Diese meine Annonce Klasse ist:
package ma.ensa.model;
import java.util.Date;
public class Annonce implements java.io.Serializable {
private Integer idAnnonce;
private String libelleAnnonce;
private double prixAnnonce;
private Date dateAnnonce;
private double positionX;
private double positionY;
private double positionZ;
private int idCentre;
private String description;
private int idVille;
private int idPersonne;
private CentreInteret centreInteret;
public Annonce() {
}
public Annonce(String libelleAnnonce, double prixAnnonce, Date dateAnnonce, double positionX, double positionY,
double positionZ, int idCentre, String description, int idVille, int idPersonne, CentreInteret centreInteret) {
this.libelleAnnonce = libelleAnnonce;
this.prixAnnonce = prixAnnonce;
this.dateAnnonce = dateAnnonce;
this.positionX = positionX;
this.positionY = positionY;
this.positionZ = positionZ;
this.idCentre = idCentre;
this.description = description;
this.idVille = idVille;
this.idPersonne = idPersonne;
}
public Integer getIdAnnonce() {
return this.idAnnonce;
}
public void setIdAnnonce(Integer idAnnonce) {
this.idAnnonce = idAnnonce;
}
public String getLibelleAnnonce() {
return this.libelleAnnonce;
}
public void setLibelleAnnonce(String libelleAnnonce) {
this.libelleAnnonce = libelleAnnonce;
}
public double getPrixAnnonce() {
return this.prixAnnonce;
}
public void setPrixAnnonce(double prixAnnonce) {
this.prixAnnonce = prixAnnonce;
}
public Date getDateAnnonce() {
return this.dateAnnonce;
}
public void setDateAnnonce(Date dateAnnonce) {
this.dateAnnonce = dateAnnonce;
}
public double getPositionX() {
return this.positionX;
}
public void setPositionX(double positionX) {
this.positionX = positionX;
}
public double getPositionY() {
return this.positionY;
}
public void setPositionY(double positionY) {
this.positionY = positionY;
}
public double getPositionZ() {
return this.positionZ;
}
public void setPositionZ(double positionZ) {
this.positionZ = positionZ;
}
public int getIdCentre() {
return this.idCentre;
}
public void setIdCentre(int idCentre) {
this.idCentre = idCentre;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public int getIdVille() {
return this.idVille;
}
public void setIdVille(int idVille) {
this.idVille = idVille;
}
public int getIdPersonne() {
return this.idPersonne;
}
public void setIdPersonne(int idPersonne) {
this.idPersonne = idPersonne;
}
}
}
Methode in DaoAnnonce Klasse:
@Override
public List<Annonce> getAnnonceParCentre(int id) {
Session session = sessionFactory.openSession();
Query qr = session.createQuery("from Annonce where idCentre=:id").setInteger("id",id);
@SuppressWarnings("unchecked")
List<Annonce> crs = qr.list();
session.close();
return crs;
}
Als ich Ich versuche, ein GET: http://localhost:8080/projet_stage_v1/rs/interets/2/annonces
Ursache :
Grave: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.io.EOFException: No content to map to Object due to end of input
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2766)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2682)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:488)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:183)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
ja sein. Ich füge "Content-Type: application/json" hinzu, arbeite aber nicht. wenn ich versuche mit http: // localhost: 8080/projet_stage_v1/rs/annonces zum beispiel ohne parameter bekomme ich das ergebnis "OK", aber wenn ich versuche mit parameter bekomme ich den fehler.Ich verstehe nicht warum ?? – spoonatte
Akzeptieren ist anders als Inhaltstyp. Probieren Sie es mit "Akzeptieren: application/json". Content-Type ist für GET-Anfragen irrelevant, da sie keinen Anfragetext haben. Accept ist, was Ihrer Annotation "@Produces" zugeordnet ist. Der Inhaltstyp wird "@Consumes" -Anmerkungen zugeordnet. – Randy
Ich bekomme einen weiteren Fehler: ** Grave: Ein Message Body Reader für die Java-Klasse int und Java-Typ int und MIME-Medientyp application/octet-stream wurde nicht gefunden. Die registrierten Nachrichtenkörperlesegeräte, die mit dem MIME-Medientyp kompatibel sind, sind: application/octet-stream ** – spoonatte