So, basically, I'm wanting to trigger an event on my server that doesn't
require any parameters. Specifically, I'm wanting to clear out a value
that's being held in memory. Now, WebResource exposes a parameter-less POST
method, so I can write a JUnit test that looks like this :
try {
URI baseUri =
UriBuilder.fromUri("
http://localhost:8081/myWebApp/rest/Semaphore/Clear").build();
WebResource service = client.resource(baseUri);
service.post();
System.out.println("Semaphore cleared");
}
catch (Exception ex) {
fail(ex.toString());
}
So I would think that I should be allowed to write webservice code that
looks like this :
@Path("/Semaphore")
public class Semaphore {
static private Result lastResult = SemaphoreConstants.NULL_RESULT;
static private Status status = Status.STABLE;
static private Object RESULT_LOCK = new Object();
@POST
@Path("Clear")
static public void clear() {
synchronized(RESULT_LOCK) {
status = Status.STABLE;
lastResult = SemaphoreConstants.NULL_RESULT;
}
}
...
}
However, when I hit that webservice with my JUnit test, I get back :
junit.framework.AssertionFailedError:
com.sun.jersey.api.client.UniformInterfaceException: POST
http://localhost:8081/myWebApp/rest/Semaphore/Clear returned a response
status of 400
I know that I could just implement this function as a GET request, but that
seems semantically wrong. Likewise, I know that I could implement it as a
more traditional POST request where I'm actually providing the NULL_RESULT
values as parameters, but that seems cumbersome and unnecessary.
Is there a way to successfully receive a POST request without parameters?
Or do I just need to suck it up and implement this differently?
--
View this message in context: http://jersey.576304.n2.nabble.com/Can-I-write-a-webservice-that-recieves-a-POST-request-without-any-parameters-tp5600043p5600043.html
Sent from the Jersey mailing list archive at Nabble.com.