如何通过卷曲测试泽西简单

时间:2013-09-15 12:45:42

标签: curl jersey-2.0

我有一个来自Jersey教程的简单课程。如何通过curl切换返回类型的格式进行简单的测试?我不想写客户。

@Path("/hello")
public class Hello {

    // This method is called if TEXT_PLAIN is request
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayPlainTextHello() {
        return "Hello Jersey";
    }

    // This method is called if XML is request
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayXMLHello() {
        return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
    }

    // This method is called if HTML is request
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHtmlHello() {
        return "<html> " + "<title>" + "Hello Jersey" + "</title>" + "<body><h1>" + "Hello Jersey" + "</body></h1>"
                + "</html> ";
    }

}

1 个答案:

答案 0 :(得分:1)

尝试使用XML:

curl -H "Accept: text/xml" -H "Content-Type: text/xml" -X GET "http://localhost:8080/yourapp/hello"

类似于text / html和text / plain