简体   繁体   中英

Failed to load resource: the server responded with a status of 415

I have a error when call the POST. I am using AngularJS, Tomee, restful

Error: Failed to load resource: the server responded with a status of 415

POST:

$http({method: 'POST', url:'http://localhost:8080/WSGestionCobros/webresources/atenciones/',data: {"atenciones" : $scope.atencion}}).success(function(data, status, headers, config) {

...                                          

}

My class

@Stateless
@Path("atenciones")
public class AtencionesFacadeREST extends AbstractFacade<Atenciones> {
    @PersistenceContext(unitName = "WSCobrosPU")
    private EntityManager em;

    public AtencionesFacadeREST() {
        super(Atenciones.class);
    }

    @POST
    @Override
    @Consumes({"application/json"})
    public void create(Atenciones entity) {
        super.create(entity);
    }
...
...
...

The entity class:

@Entity
@Table(name = "atenciones")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Atenciones.findAll", query = "SELECT a FROM Atenciones a"),
    @NamedQuery(name = "Atenciones.findByCasoid", query = "SELECT a FROM Atenciones a WHERE a.casoid = :casoid"),
    @NamedQuery(name = "Atenciones.findByCedula", query = "SELECT a FROM Atenciones a WHERE a.cedula = :cedula"),
    @NamedQuery(name = "Atenciones.findByUsuario", query = "SELECT a FROM Atenciones a WHERE a.usuario = :usuario"),
    @NamedQuery(name = "Atenciones.findByEstado", query = "SELECT a FROM Atenciones a WHERE a.estado = :estado"),
    @NamedQuery(name = "Atenciones.findByFechaCreacion", query = "SELECT a FROM Atenciones a WHERE a.fechaCreacion = :fechaCreacion")})
public class Atenciones implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "casoid")
    private Integer casoid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "cedula")
    private String cedula;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "usuario")
    private String usuario;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 3)
    @Column(name = "estado")
    private String estado;
    @Basic(optional = false)
    @NotNull
    @Column(name = "fecha_creacion")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fechaCreacion;

   ...

I tried put header Content-Type: application/json but nothing

也许在方法或类上添加@Produces(“ application / json”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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