I have a simple prototype that is producing XML perfectly fine.  It uses
Spring configuration without annotations.

Today I added a "produces" attribute to the operation definition to
allow it to generate both XML and JSON.  When I set the "Accept" header
in my client to "application/json" the server operation appears to work,
but the response contains headers but no content.

I tried setting a breakpoint in
"AegisJSONProvider.createStreamWriter()", but it never got there.  It's
odd that this returns an "XMLStreamWriter", but that's probably due to
the requirements of the base class.

The following shows the HTTP headers in the requests and responses for
both the XML and JSON calls:
--------------------------
XML Request:
GET /SSAxis/rest/catalog/item/1 HTTP/1.1
Accept: application/xml
User-Agent: http4e/1.5.4
Host: localhost:7001

XML Response:
HTTP/1.1 200 OK
Date: Fri, 28 Aug 2009 16:56:28 GMT
Transfer-Encoding: chunked
Content-Type: application/xml
X-Powered-By: Servlet/2.5 JSP/2.1

<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Item><description>def</description><id>1</id><title>a
bc</title></Item>

JSON Request:
GET /SSAxis/rest/catalog/item/1 HTTP/1.1
Accept: application/json
User-Agent: http4e/1.5.4
Host: localhost:7001

JSON Response:
HTTP/1.1 200 OK
Date: Fri, 28 Aug 2009 16:57:18 GMT
Transfer-Encoding: chunked
Content-Type: application/json
X-Powered-By: Servlet/2.5 JSP/2.1

-----------------------------------

The following is my current "beans.xml".  In my Java code, I only added
a "@Produces" annotation, although that's ignored (different issue):
------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xmlns:jaxws="http://cxf.apache.org/jaxws";
    xmlns:jaxrs="http://cxf.apache.org/jaxrs";
    xmlns:cxf="http://cxf.apache.org/core";
        xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemascore.xsd";>

        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"
/>
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <import
resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
    
    <jaxrs:server name="restcatalogserver" address="/rest">
        <jaxrs:features>
            <cxf:logging/>
        </jaxrs:features>
        <jaxrs:model>
            <jaxrs:resource name="com.att.ecom.catalog.Catalog"
path="/catalog/">
                <jaxrs:operation name="getItem" verb="GET"
path="/item/{id}"
 
produces="application/xml, application/json">
                    <jaxrs:param name="id" type="PATH"/>
                </jaxrs:operation>
            </jaxrs:resource>
        </jaxrs:model>
        <jaxrs:serviceBeans>
            <ref bean="catalog"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>
     
    <bean id="catalog" class="com.att.ecom.catalog.Catalog">
        <property name="stuff" value="3"/>
    </bean>
</beans>
-------------------------

Reply via email to