[英]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-Type
和Accept
标头设置为application / xml 。 此外,这不一定是关键,但考虑将您的方法设置为@DELETE
以使用适当的REST语义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.