繁体   English   中英

Etat HTTP 415-不支持的媒体类型:GET未达到Jersey REST

[英]Etat HTTP 415 - Unsupported Media Type : GET not reaching Jersey REST

我正在使用Spring MVC和Hibernate。 我有一个使用Jersey编写的RESTful Web服务,看起来像这样:

 @GET  
  @Path("/interets/{idCentre}/annonces") 
  @Produces(MediaType.APPLICATION_JSON)
  public List<Annonce> getAnnonceParCentre(@PathParam(value="idCentre") int idCentre){
      return metier.getAnnonceParCentre(idCentre);
   }

这是我的Annonce课:

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;
}
}
}

DaoAnnonce类中的方法:

@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;
}

当我尝试执行GET时: http:// localhost:8080 / projet_stage_v1 / rs / interets / 2 / annonces

根本原因:

    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)

您是否在发送带有GET请求的Accept标头? 它的值应该是application / json

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM