简体   繁体   English

webservice @POST返回415不支持的媒体类型

[英]webservice @POST returns 415 Unsupported Media Type

I made webservice on jboss-as-7, which works ok with @GET method, but when I tried to add @POST, I'm getting "415 Unsupported Media Type". 我在jboss-as-7上做了webservice,它可以用@GET方法工作,但是当我尝试添加@POST时,我得到的是“415 Unsupported Media Type”。 After a lot of code tweaking on client & server side, now I'm just using REST client for testing. 经过客户端和服务器端的大量代码调整后,现在我只是使用REST客户端进行测试。 Am I missing here something? 我在这里错过了什么吗?

webservice: 网络服务:

@Stateless
@LocalBean
@Path("/RESTService")
public class ReservationsResource {

    @EJB
    private ReservationsSB reservationsSB;

    @GET
    @Produces("application/xml")
    @Path("/reservation/{id}")
    public Reservations getReservation(@PathParam("id") int id) {
        return reservationsSB.getReservation(id);
    }

    @POST
    @Consumes("application/xml")
    @Path("/reservation/delete")
    public Response deleteReservation(Reservations r){
        edited = null;
        reservationsSB.deleteReservation(r);

        return Response.status(201).entity(r).build();
    }

entity: 实体:

@Entity
@XmlRootElement
@Table(name="reservations")
public class Reservations {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @Column
    private String date;
    private String owner;
    private int active;

    @ManyToOne
    private Tables table;

    public Reservations(String date, String owner, Tables table, int active) {
        super();
        this.date = date;
        this.owner = owner;
        this.table = table;
        this.active = active;
    }
        ...
}

REST client request: url: http://localhost:8080/BarBar/RESTService/reservation/delete body(same as is returned by getReservation()): REST客户端请求:url: http://localhost:8080/BarBar/RESTService/reservation/delete body(与getReservation()返回的相同):

<reservations>
<active>1</active>
<date>2014-01-14 21:00:00.0</date>
<id>23</id>
<owner>dqf</owner>
<table>
<capacity>6</capacity>
<id>30</id>
<name>table 4</name>
</table>
</reservations>

Make sure to set your Content-Type and Accept headers to application/xml . 确保将Content-TypeAccept标头设置为application / xml Also, this isn't necessarily critical, but consider setting your method to @DELETE to use the appropriate REST semantics. 此外,这不一定是关键,但考虑将您的方法设置为@DELETE以使用适当的REST语义。

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

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