【发布时间】:2014-01-11 22:51:02
【问题描述】:
我在 jboss-as-7 上创建了 web 服务,可以使用 @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 客户端请求:
网址:http://localhost:8080/BarBar/RESTService/reservation/delete
正文(与 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>
【问题讨论】: