Is there a way to unlock all http methods without

2019-08-19 01:35发布

问题:

I have a .war file deployed in Jetty (I didn't build it, and it's not possible to create a new instance).

An OPTIONS request to http://example.com/rest/object/{uuid}responds with HEAD, DELETE, GET, OPTIONS. The people that built the war claim that it's not an issue with their file.

Is there a Jetty config file I can change to allow all the http methods?

If this is something I have to do in a Jetty Java file, I am a Jetty noob, so please be verbose, or point me to some docs that I can read.

Note: I can POST via CURL, but not via http...

Edit: (I was posting to a different Endpoint with CURL)

回答1:

This is not an answer to the question I posted, but it allowed me to understand what was happening, which lead to the question being irrelevant for my particular issue. With that being said, I won't mark this as the answer in the event it is answerable (which I don't think it is, you'll see why in a minute).

The short answer is I was trying to POST to an endpoint that expects the object to already exist:

http://example.com/rest/object/{uuid}

What I should have done was use an endpoint, where if you POST, it understands you want to create a new object:

http://example.com/rest/object

The longer answer

Let's say you have a REST Endpoint that allows you to get a specific object, like this:

http://example.com/rest/object/{uuid}

Since you're dealing with a specific object, you typically wouldn't want to POST a new object there. POST means 'create a new object'. If you were able to POST there, you'd essentially be overwriting that Object... and that's what PUT is for, but it's debatable. Also, PUT wasn't an option either...

So, because of its subjective nature, some Web Services limit request methods so you must do it the way the architects intended. The REST Server I am running doesn't have much in the way of documentation, so I was unaware of these restrictions, and am still puzzled by it.

What I thought I was doing was saying "OK, I want to create an object with this id. So if I POST my data to that specific UUID, the server will know I want to create a new object." What I should have been saying is "OK, I want to create a new object. It's UUID is already defined in the data, so all I need to do is send it to the endpoint that handles those objects, and expects a POST." Like this:

http://example.com/rest/object


标签: Jetty