Java webservice@POST返回415个不支持的媒体类型
我在jboss-as-7上创建了webservice,它可以与@GET方法一起工作,但是当我尝试添加@POST时,我得到了“415个不支持的媒体类型”。在客户端和服务器端进行了大量代码调整之后,现在我只使用REST客户端进行测试。我是不是错过了什么 网络服务:Java webservice@POST返回415个不支持的媒体类型,java,jboss7.x,resteasy,Java,Jboss7.x,Resteasy,我在jboss-as-7上创建了webservice,它可以与@GET方法一起工作,但是当我尝试添加@POST时,我得到了“415个不支持的媒体类型”。在客户端和服务器端进行了大量代码调整之后,现在我只使用REST客户端进行测试。我是不是错过了什么 网络服务: @Stateless @LocalBean @Path("/RESTService") public class ReservationsResource { @EJB private ReservationsSB re
@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
正文(与getReservation()返回的相同):
1.
2014-01-14 21:00:00.0
23
dqf
6.
30
表4
确保将内容类型
和接受
标题设置为application/xml。同样,这不一定是关键的,但是考虑将你的方法设置为<代码>删除> /代码>以使用适当的REST语义。我很乐意帮忙。祝你的项目好运!
<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>