You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "gennady.shumakher" <gs...@gmail.com> on 2008/09/24 09:03:08 UTC

CXF JSON and Servlet transport configuration

Hello,
I would like to expose my service in JSON format when using spring aware
servlet as a transport.
I managed to run the sample restful_http_binding stand alone application and
I see that the JSON is configured  programmatically:
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("Content-Type", "text/plain");
        Map<String, String> nstojns = new HashMap<String, String>();
        nstojns.put("http://demo.restful.server", "acme");
        MappedXMLInputFactory xif = new MappedXMLInputFactory(nstojns);
        properties.put(XMLInputFactory.class.getName(), xif);
        MappedXMLOutputFactory xof = new MappedXMLOutputFactory(nstojns);
        properties.put(XMLOutputFactory.class.getName(), xof);
        sf.setProperties(properties);
        sf.create();

Now if I run within the Spring aware Servlet with CFXServet, how should I
configure it to achieve the same results and produce JSON response?
Should it be some configuration of <jaxrs:server.. in the beans.xml?

Thanks,
Gennady
-- 
View this message in context: http://www.nabble.com/CXF-JSON-and-Servlet-transport-configuration-tp19643091p19643091.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: CXF JSON and Servlet transport configuration

Posted by gshum <gs...@gmail.com>.
If someone is looking for solution on the same problem (CFX 2.1.2, Spring
2.5.5)

    <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
        <entry key="http://www.example.com/shakedown" value="e" />
        <entry key="http://cxf.apache.org/bindings/xformat" value="cxf" />
    </util:map>
    <bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.JSONProvider">
        <property name="namespaceMap" ref="jsonNamespaceMap" />
    </bean>
    <jaxrs:server id="jsonRestEndpoint" address="/system">
        <jaxrs:serviceBeans>  <ref bean="restImpl" />  </jaxrs:serviceBeans>
        <jaxrs:providers>  <ref bean="jsonProvider" />  </jaxrs:providers>
    </jaxrs:server>

You can see JIRA CXF-1671 for some implementation details.
-- 
View this message in context: http://www.nabble.com/CXF-JSON-and-Servlet-transport-configuration-tp19643091p19657451.html
Sent from the cxf-user mailing list archive at Nabble.com.