createCustomer() 메소드가 있는데이 메소드는 POST 메소드이며 MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON을 모두 사용하므로 실제 MIME 유형을 확인하려고합니다. 클라이언트에서 온 요청은 XML 또는 JSON 일 수 있으며 요청의 MIME 유형에 따라 두 가지 다른 메소드를 호출하려고합니다.MIME 유형을 기반으로 REST 요청을 처리합니다.
들어오는 요청의 MIME 형식을 확인하고 두 가지 방법으로 형식 호출을 기반으로 코드를 제공 해줄 수 있습니까?
아래의 예제 코드는 다음과 같습니다
@POST
@Path("/createCustomer")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response createCustomer(Customer customer) {
//if the request is in JSON then call the method createCustomerJSON()
//else if the request is in XML then call the method createCustomerXML()
//String output = output from either the method createCustomerJSON() or createCustomerXML()
return Response.status(200).entity(output).build();
}