Web服务415不支持的媒体类型

时间:2014-03-07 06:40:42

标签: java json web-services rest

我的wadl(部分)

<resources base="http://localhost:8080/rest-sample/cxf/">
<resource path="/employeeservice/">
<resource path="add/">
<method name="POST">
<request>
<representation mediaType="application/xml" element="prefix1:Employee"/>
<representation mediaType="application/json"/>
</request>
<response>
<representation mediaType="application/xml"/>
<representation mediaType="application/json"/>
</response>
</method>
</resource>

bean类:

@XmlType(name = "EmployeesType", namespace = "com.test.dto")
@XmlRootElement(name = "Employees", namespace = "com.test.dto")
public class Employees {

    @XmlElement(name = "employee", required = true)
    @XmlElementWrapper(name = "employees")
    public Collection<Employee> getEmployees() {
        return employees;
    }

商务舱:

@Path("/employeeservice/")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public class EmployeeServiceImpl implements EmployeeService {

...

@POST
    @Path("/add/")
    @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response add(Employee employee) {
        System.out.println("Adding :" + employee);
        employee.setId(index++);
        update(employee);
        return Response.status(Response.Status.OK).build();
    }

    @PUT
    @Path("/update/")
    @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response update(Employee employee) {
        EMPLOYEE_MAP.put(employee.getId(), employee);
        return Response.status(Response.Status.OK).build();
    }

Http客户端:

接受:application / json 键入:POST

  

http://localhost:8080/rest-sample/cxf/employeeservice/add

收到以下错误:

415 Unsupported Media Type

获得PUT呼叫的错误相同。

遵循此link但没有解决方案。


0 个答案:

没有答案