<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to marshall requests? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319455#M6456</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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
        });
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;./nuxeoctl bootstrap contribution&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I chose some names and parameters that may not be relevant, except this:
I chose the &lt;CODE&gt;org.nuxeo.ecm.core.io.MarshallerRegistry&lt;/CODE&gt; as the target and the &lt;CODE&gt;marshallers&lt;/CODE&gt; as the extension point.
It created a &lt;CODE&gt;myextension-contrib.xml&lt;/CODE&gt; file. In this file I registered my marshaller:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;extension target="org.nuxeo.ecm.core.io.MarshallerRegistry" point="marshallers"&amp;gt;
	  &amp;lt;register class="com.gregoreki.core.MyMarshaller" enable="true" /&amp;gt;	
  &amp;lt;/extension&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Its code is listed below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
// ... imports omitted
@Setup(mode = Instantiations.SINGLETON, priority = Priorities.REFERENCE)
public class MyMarshaller extends AbstractJsonReader&amp;lt;MyBodyRequest&amp;gt; {

	@Override
	public MyBodyRequest read(JsonNode jn) throws IOException {
        return new ObjectMapper().readValue(jn.toString().getBytes(), MyBodyRequest.class);
	}
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, I need the MyBodyRequest.java:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
public class MyBodyRequest {
	private String myKey;

	public String getMyKey(){
		return myKey;
	}

	public void setMyKey(String myKey){
		this.myKey = myKey;
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then, in my endpoint, I have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
	@POST
	@Path("mytestendpoint")
	@Consumes(MediaType.APPLICATION_JSON)
	public Object postTestEndpoint(MyBodyRequest request){
		// do something with the request marshalled object
	}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;	public Object postTestEndpoint(String request){ ... }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it works. Why isn't my marshaller working? Why does it only accept a String as the parameter?&lt;/P&gt;
&lt;P&gt;Regards,
Carlos G.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 11:49:11 GMT</pubDate>
    <dc:creator>Carlos_Gregorek</dc:creator>
    <dc:date>2019-10-03T11:49:11Z</dc:date>
    <item>
      <title>How to marshall requests?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319455#M6456</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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
        });
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;./nuxeoctl bootstrap contribution&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I chose some names and parameters that may not be relevant, except this:
I chose the &lt;CODE&gt;org.nuxeo.ecm.core.io.MarshallerRegistry&lt;/CODE&gt; as the target and the &lt;CODE&gt;marshallers&lt;/CODE&gt; as the extension point.
It created a &lt;CODE&gt;myextension-contrib.xml&lt;/CODE&gt; file. In this file I registered my marshaller:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;extension target="org.nuxeo.ecm.core.io.MarshallerRegistry" point="marshallers"&amp;gt;
	  &amp;lt;register class="com.gregoreki.core.MyMarshaller" enable="true" /&amp;gt;	
  &amp;lt;/extension&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Its code is listed below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
// ... imports omitted
@Setup(mode = Instantiations.SINGLETON, priority = Priorities.REFERENCE)
public class MyMarshaller extends AbstractJsonReader&amp;lt;MyBodyRequest&amp;gt; {

	@Override
	public MyBodyRequest read(JsonNode jn) throws IOException {
        return new ObjectMapper().readValue(jn.toString().getBytes(), MyBodyRequest.class);
	}
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, I need the MyBodyRequest.java:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
public class MyBodyRequest {
	private String myKey;

	public String getMyKey(){
		return myKey;
	}

	public void setMyKey(String myKey){
		this.myKey = myKey;
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then, in my endpoint, I have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;
	@POST
	@Path("mytestendpoint")
	@Consumes(MediaType.APPLICATION_JSON)
	public Object postTestEndpoint(MyBodyRequest request){
		// do something with the request marshalled object
	}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;	public Object postTestEndpoint(String request){ ... }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it works. Why isn't my marshaller working? Why does it only accept a String as the parameter?&lt;/P&gt;
&lt;P&gt;Regards,
Carlos G.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:49:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319455#M6456</guid>
      <dc:creator>Carlos_Gregorek</dc:creator>
      <dc:date>2019-10-03T11:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to marshall requests?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319456#M6457</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Did you follow the documentation here: &lt;A href="https://doc.nuxeo.com/nxdoc/howto-contribute-to-the-rest-api/#extending-the-rest-api-the-workflow-case"&gt;https://doc.nuxeo.com/nxdoc/howto-contribute-to-the-rest-api/#extending-the-rest-api-the-workflow-case&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;You need to deploy 2 different bundles:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;one with the &lt;CODE&gt;Fragment-Host: org.nuxeo.ecm.platform.restapi.server&lt;/CODE&gt; entry in the &lt;CODE&gt;MANIFEST.MF&lt;/CODE&gt;. This bundle will contain the REST endpoint (annotated with &lt;CODE&gt;@WebObject&lt;/CODE&gt;)&lt;/LI&gt;
&lt;LI&gt;another one for the Nuxeo contribution (the MyBodyRequest object, the marshaller, ...)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Contributions from the bundle with the &lt;CODE&gt;Fragment-Host&lt;/CODE&gt; are not deployed by Nuxeo.&lt;/P&gt;
&lt;P&gt;See the warning on the page:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;This also causes all of the other components in the fragment bundle not to be deployed. Thus, any endpoint or web adapter class you add, respectively annotated with &lt;CODE&gt;@WebObject&lt;/CODE&gt; or &lt;CODE&gt;@WebAdapter&lt;/CODE&gt;, need to be in a standalone bundle, not in the same bundle as extension point XML contributions for instance.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:38:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319456#M6457</guid>
      <dc:creator>Thomas_Roger</dc:creator>
      <dc:date>2019-10-11T13:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to marshall requests?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319457#M6458</link>
      <description>&lt;P&gt;Thanks for your answer and for the heads up.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:49:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-marshall-requests/m-p/319457#M6458</guid>
      <dc:creator>Carlos_Gregorek</dc:creator>
      <dc:date>2019-10-11T13:49:30Z</dc:date>
    </item>
  </channel>
</rss>

