Hello all,
I'm trying to make an custom endpoint receive some data from a javascript application that uses Nuxeo JS client.
The JS application uses the following code to perform the request:
doEndpointTestRequest(){
// create the opts dict to be inserted into the request
var opts = {};
opts.json = true;
opts.method = "POST";
var body_json = { myKey: "myValue" };
opts.body = JSON.stringify(body_json);
this.nuxeo.request('ext/poc/mytestendpoint')
.post(opts)
.then(function(data) {
console.log("Post is done.")
})
.catch(function(error) {
throw error
});
}
To handle the data inside my endpoint, I'm trying to get a JSON-to-Java marshaller to work. (You can notice I'm trying to do the full mode feature/layer here)
For that, I went into my project folder and wrote:
./nuxeoctl bootstrap contribution
I chose some names and parameters that may not be relevant, except this:
I chose the org.nuxeo.ecm.core.io.MarshallerRegistry as the target and the marshallers as the extension point.
It created a myextension-contrib.xml file. In this file I registered my marshaller:
<extension target="org.nuxeo.ecm.core.io.MarshallerRegistry" point="marshallers">
<register class="com.gregoreki.core.MyMarshaller" enable="true" />
</extension>
Its code is listed below:
// ... imports omitted
@Setup(mode = Instantiations.SINGLETON, priority = Priorities.REFERENCE)
public class MyMarshaller extends AbstractJsonReader<MyBodyRequest> {
@Override
public MyBodyRequest read(JsonNode jn) throws IOException {
return new ObjectMapper().readValue(jn.toString().getBytes(), MyBodyRequest.class);
}
}
Of course, I need the MyBodyRequest.java:
public class MyBodyRequest {
private String myKey;
public String getMyKey(){
return myKey;
}
public void setMyKey(String myKey){
this.myKey = myKey;
}
And then, in my endpoint, I have:
@POST
@Path("mytestendpoint")
@Consumes(MediaType.APPLICATION_JSON)
public Object postTestEndpoint(MyBodyRequest request){
// do something with the request marshalled object
}
Well, it seems I got it right, doesn't it?
What happens is that the endpoint is never hit and I get a HTTP::405 error: method not supported.
When I change the endpoint code to
public Object postTestEndpoint(String request){ ... }
it works. Why isn't my marshaller working? Why does it only accept a String as the parameter?
Regards,
Carlos G.