基本上,我有一個在Restlet中設置的項目,它使用JAXRS將資源映射到路徑,並使用JAXB將XML序列化並從Java類型反序列化XML。我目前正在嘗試發送POST請求以測試它是否有效,並且我遇到了一些麻煩。這裏是我的資源:如何通過curl發送REST XML POST請求?
@Path("stream")
public class StreamResource {
@POST
@Consumes("text/xml")
@Produces("text/xml")
public Stream save(Stream value) {
logger.debug("saving new stream...");
return (Stream)this.streamPersistence.save(value);
}
}
這裏是我的Stream
類:
@XmlRootElement(name="stream")
@XmlType(propOrder={"id", "streamName", "title", "description", fileSystemPath"})
public class Stream {
private Long id;
private String streamName;
private String fileSystemPath;
private String title;
private String description;
// getters/setters omitted for brevity
}
下面是我如何調用curl
:
curl -X POST -d '<stream><streamName>helloWorld.flv</streamName><title>Amazing Stuff, Dude!</title><description>This stream is awesome-cool.</description><fileSystemPath>/home/rfkrocktk/Desktop/helloWorld.flv</fileSystemPath></stream>' --header 'Content-Type:"text/xml"' http://localhost:8888/stream
下面是我從curl
得到錯誤:
The given resource variant is not supported.
...這是在的Restlet錯誤:
15:02:25.809 [Restlet-961410881] WARN org.restlet.Component.Server - Error while parsing entity headers java.lang.IllegalArgumentException: Illegal token: "text
at org.restlet.data.MediaType.normalizeToken(MediaType.java:647)
at org.restlet.data.MediaType.normalizeType(MediaType.java:686)
at org.restlet.data.MediaType.<init>(MediaType.java:795)
at org.restlet.data.MediaType.<init>(MediaType.java:767)
at org.restlet.engine.http.header.ContentTypeReader.createContentType(ContentTypeReader.java:84)
at org.restlet.engine.http.header.ContentTypeReader.readValue(ContentTypeReader.java:112)
at org.restlet.engine.http.header.ContentType.<init>(ContentType.java:99)
at org.restlet.engine.http.header.HeaderUtils.extractEntityHeaders(HeaderUtils.java:664)
at org.restlet.engine.http.connector.Connection.createInboundEntity(Connection.java:313)
at org.restlet.engine.http.connector.ServerConnection.createRequest(ServerConnection.java:136)
at org.restlet.engine.http.connector.ServerConnection.readMessage(ServerConnection.java:229)
at org.restlet.engine.http.connector.Connection.readMessages(Connection.java:673)
at org.restlet.engine.http.connector.Controller$2.run(Controller.java:95)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
什麼我錯在這裏做什麼?這看起來很簡單,對吧?
[你是海盜。](http://www.youtube.com/watch?v=os5TXyJlEMc)你贏了。 –