1
我試過official samples Wild JAX-RS的問題。並試圖使用:關於生產
curl http://localhost:8080/wildfly-helloworld-rs/rest/ -H 'accept:application/xml'
curl http://localhost:8080/wildfly-helloworld-rs/rest/ -H 'accept:application/json'
兩個要求返回我的XML表示:
<xml><result>Hello World!</result></xml>
我甚至想補充一點:
@GET
@Path("/")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public String getHelloWorldText() {
return helloService.createHelloMessage("World");
}
它反正總是返回XML表示。
編輯:從聯例如
@Path("/")
public class HelloWorld {
@Inject
HelloService helloService;
@GET
@Path("/")
@Produces({ "application/json" })
public JsonObject getHelloWorldJSON() {
return Json.createObjectBuilder()
.add("result", helloService.createHelloMessage("World"))
.build();
}
@GET
@Path("/")
@Produces({ "application/xml" })
public String getHelloWorldXML() {
return "<xml><result>" + helloService.createHelloMessage("World")
+ "</result></xml>";
}
}
public class HelloService {
String createHelloMessage(String name) {
return "Hello " + name + "!";
}
}
這很有趣,只在Windows上引起這個問題。在Ubuntu上,我可以用'in -H寫入請求,並且它可以工作。無論如何,TNX,沒有它的工作) – Suvitruf 2014-11-23 10:21:20
我的意思是「現在」(: – Suvitruf 2014-11-23 10:27:41
我在Windows上。很高興知道:-) – 2014-11-23 10:42:47