spring mvc - RestTemplate with Kryo converter -


i attempting post rest endpoint using resttemplat kryo message converter (application/x-kryo). problem that: a) message header not correctly set despite corrcet use of resttemplate b) kryo message converter not invoked, again despite setting resttemplate converters.

  • the rest end point defined as:

    @requestmapping(         value = "/my-service/initialization",          method = requestmethod.post,         headers = "accept=application/x-kryo",         consumes = "application/x-kryo",         produces = "application/json" ) public responseentity<string> init(         @requestparam(value = "mycontext", required = true) final mycontext mycontext) 
  • kryo message converter defined , registered as:

     public class kryohttpmessageconverter extends abstracthttpmessageconverter<object> {         public static final mediatype mediatypekryo = new mediatype("application", "x-kryo");      @override protected boolean supports(class<?> clazz) {         return object.class.isassignablefrom(clazz);     }      @override protected object readinternal(             class<? extends object> clazz, httpinputmessage inputmessage) throws ioexception {         input input = new input(inputmessage.getbody());         return kryothreadlocal.get().readclassandobject(input);     }      @override protected void writeinternal(object object, httpoutputmessage outputmessage) throws ioexception      {         output output = new output(outputmessage.getbody());         kryothreadlocal.get().writeclassandobject(output, object);         output.flush();     }      @override protected mediatype getdefaultcontenttype(object object) {         return mediatypekryo;     } } 

my bean context declaring converter is:

<bean id="contentnegotiationmanager" class="org.springframework.web.accept.contentnegotiationmanagerfactorybean">         <property name="favorpathextension" value="false" />         <property name="favorparameter" value="false" />         <property name="ignoreacceptheader" value="false" />         <property name="usejaf" value="false" />         <property name="defaultcontenttype" value="application/x-kryo" />         <property name="mediatypes">             <map>                 <entry key="json" value="application/json" />                 <entry key="kryo" value="application/x-kryo" />                             </map>         </property>     </bean>      <mvc:annotation-driven content-negotiation-manager="contentnegotiationmanager">         <mvc:message-converters>                <bean    id="kryomarshaller"                      class="com.cisco.apicem.matlab.service.http.converter.kryohttpmessageconverter"             />         </mvc:message-converters>     </mvc:annotation-driven>       

here resttemplate usage:

resttemplate resttemplate = new resttemplate();     resttemplate.getmessageconverters().add(new kryohttpmessageconverter());      httpheaders headers = new httpheaders();     headers.setaccept(arrays.aslist(kryohttpmessageconverter.mediatypekryo));     headers.setcontenttype(kryohttpmessageconverter.mediatypekryo);      multivaluemap<string,mycontext> parameters = new linkedmultivaluemap<string,mycontext>();     parameters.add("mycontext", ctx);      httpentity<multivaluemap<string, mycontext>> request = new httpentity<multivaluemap<string, mycontext>>(parameters, headers);               httpentity<?> thereq = new httpentity<>(request, headers);             final string response = new resttemplate().postforobject(endpoint, thereq, string.class); 

here error:

debug o.s.web.client.resttemplate - created post request "https://172.24.100.235/api/v1/my-service/initialization" 13:55:34.109 [main] debug o.s.web.client.resttemplate - setting request accept header [text/plain, application/json, application/*+json, /] exception in thread "main" org.springframework.web.client.restclientexception: not write request: no suitable httpmessageconverter found request type [org.springframework.http.httpentity] , content type [application/x-kryo] @ org.springframework.web.client.resttemplate$httpentityrequestcallback.dowithrequest(resttemplate.java:691) @ org.springframework.web.client.resttemplate.doexecute(resttemplate.java:508) @ org.springframework.web.client.resttemplate.execute(resttemplate.java:473) @ org.springframework.web.client.resttemplate.postforobject(resttemplate.java:322)

my questions:

  1. why accept header set application/json when have set resttemplate accept header mediatype.kryo?
  2. why not find registered kryo message converter?

any gratefully acknowledged!


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -