簡體   English   中英

webservice @POST返回415不支持的媒體類型

[英]webservice @POST returns 415 Unsupported Media Type

我在jboss-as-7上做了webservice,它可以用@GET方法工作,但是當我嘗試添加@POST時,我得到的是“415 Unsupported Media Type”。 經過客戶端和服務器端的大量代碼調整后,現在我只是使用REST客戶端進行測試。 我在這里錯過了什么嗎?

網絡服務:

@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
@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客戶端請求: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>

確保將Content-TypeAccept標頭設置為application / xml 此外,這不一定是關鍵,但考慮將您的方法設置為@DELETE以使用適當的REST語義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM