Naftuli Kay Naftuli Kay - 4 years ago 158
HTTP Question

How can I send a REST XML POST request via curl?

Basically, I have a project set up in Restlet which uses JAXRS for mapping resources to paths and uses JAXB for serializing and deserializing XML to/from Java types. I'm currently trying to send a POST request in order to test whether it works, and I'm running into a bit of trouble. Here's my resource:

@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);
}
}


Here's my
Stream
class:

@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
}


And here's how I'm invoking
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


Here's the error I'm getting from
curl
:

The given resource variant is not supported.


...and here's the error in 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)


What am I doing wrong here? This seems pretty straightforward, right?

Answer Source

Remove the quotes around text/xml.

In other words you want

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download