2014-01-11 79 views
0

我在JBoss-AS-7,該工程確定與@GET方法制成的web服務,但是當我試圖添加@POST,我得到「415不支持的媒體類型」。在客戶端&服務器端調整了很多代碼之後,現在我只是使用REST客戶端進行測試。我在這裏想念什麼嗎?web服務@POST返回415不支持的媒體類型

web服務:

@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> 

回答

2

請務必設置您的Content-TypeAccept標題到application/xml。此外,這不一定非常重要,但考慮將您的方法設置爲@DELETE以使用適當的REST語義。

+0

非常感謝! Accept header is missing –

+0

很高興爲您提供幫助。祝你的項目好運! – Vidya

相關問題