2014-01-11 2 views
0

jboss-as-7에서 @GET 메서드로 작동하는 webservice를 만들었지 만 @POST를 추가하려고하면 "415 Unsupported Media Type"이 표시됩니다. 클라이언트 & 서버 측에서 많은 코드를 수정 한 후에 테스트 용으로 REST 클라이언트를 사용하고 있습니다. 내가 뭔가를 놓친거야?webservice @POST가 415를 반환합니다. 지원되지 않는 미디어 유형

웹 서비스 :

@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 의해 반환 동일)

<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

을 설정해야합니다.및 Accept 헤더는 응용 프로그램/xml입니다. 또한 반드시 필요한 것은 아니지만 적절한 REST 의미를 사용하려면 메서드를 @DELETE으로 설정하는 것이 좋습니다.

+0

정말 고마워요! 수락 헤더가 없습니다. –

+0

도와 줘서 기쁩니다. 프로젝트에 행운을 빌어 요! – Vidya

관련 문제