You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Nayan Hajratwala <na...@chikli.com> on 2009/08/12 17:04:10 UTC

JSON parameters getting lost

Greetings.

I recently upgraded from cxf 2.0.4-incubator to 2.2.3.

After the upgrade it appears that my parameters are getting lost. I am
making POST JSON requests using http-binding. My config looks like this:

	<jaxws:endpoint
		id="fileManagerServiceJSON"
		implementor="#fileManagerService"
		implementorClass="com.xxx.xxx.service.filemanager.FileManagerServiceImpl"
		address="/sysadmin/filemanager/json"
		bindingUri="http://apache.org/cxf/binding/http">
		<jaxws:serviceFactory>
			<ref bean="json-service-factory" />
		</jaxws:serviceFactory>
	</jaxws:endpoint>

	<bean id="json-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
		<property name="properties">
			<map>
				<entry key="javax.xml.stream.XMLInputFactory" value-ref="xmlIn" />
				<entry key="javax.xml.stream.XMLOutputFactory" value-ref="xmlOut" />
				<entry key="Content-Type" value="text/plain" />
			</map>
		</property>
	</bean>
	
	<util:map id="nstojns" map-class="java.util.HashMap">
		<entry key="http://domain.model.xxx.com/" value="" />
	</util:map>

	<bean id="xmlIn"
class="org.codehaus.jettison.mapped.MappedXMLInputFactory" >
		<constructor-arg ref="nstojns" />
	</bean>

	<bean id="xmlOut"
class="org.codehaus.jettison.mapped.MappedXMLOutputFactory" >
		<constructor-arg ref="nstojns" />
	</bean>


A request to the server looks like this:

Address: /xxx/service/sysadmin/filemanager/json/getBatches
Encoding: UTF-8
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Headers: {accept-encoding=[gzip,deflate], connection=[keep-alive],
referer=[http://localhost:8080/xxx/sysadmin/service-tests-admin/template.jsp?name=filemanager-getBatches&toke=null],
accept-charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.7], pragma=[no-cache],
Content-Type=[application/x-www-form-urlencoded; charset=UTF-8],
x-ajax-reqid=[e], content-type=[application/x-www-form-urlencoded;
charset=UTF-8], cookie=[JSESSIONID=799AC2CFC9100A38C6BBCC7D732CD5D7;
fl-remember=FRd7UXI%3D; fl-user=; fl-pass=],
Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8],
keep-alive=[300], content-length=[40], cache-control=[no-cache],
host=[localhost:8080], accept-language=[en-us,en;q=0.5],
user-agent=[Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2]}
Payload: {getBatches: {offset:0, maxResults:1}}  

The service method looks like this:

	public ListResult<Batch> getBatches(String offset, String maxResults) {

I've isolated the problem down to jettison, i think.  When I use 1.0RC2
(what was used with CXF 2.0.4), the offset and maxResults come through
fine. When i use the new jettison 1.1, they are null. I *need* to use the
new jettison because of bug fixes relating to array and list processing.

Any ideas?

Thanks!

-- 
  Nayan Hajratwala
  http://agileshrugged.com
  734.658.6032

Re: JSON parameters getting lost

Posted by Daniel Kulp <dk...@apache.org>.
Can you try changing the method to:

public ListResult<Batch> getBatches(
    @WebParam(name = "offset", targetNamespace="http://domain.model.xxx.com/")
    String offset, 
    @WebParam(name = "maxResults", 
targetNamespace="http://domain.model.xxx.com/")
    String maxResults)

I'm willing to bet that the new jettison is not seeing a "prefix" on the 
offset and maxResults tags in the json and assigning them into the same 
namespace as the operation wrapper.    By default, with jaxws, the subelements 
would normally be unqualified so the runtime is probably looking for the 
unqualified elements, but jettison is feeding it qualified elements.   By 
adding targetNamespace decls above, that should force them to be qualified.

I'm not 100% sure that really is the case.   If that doesn't help, a test case 
would be really good.

Dan


On Wed August 12 2009 11:04:10 am Nayan Hajratwala wrote:
> Greetings.
>
> I recently upgraded from cxf 2.0.4-incubator to 2.2.3.
>
> After the upgrade it appears that my parameters are getting lost. I am
> making POST JSON requests using http-binding. My config looks like this:
>
> 	<jaxws:endpoint
> 		id="fileManagerServiceJSON"
> 		implementor="#fileManagerService"
> 		implementorClass="com.xxx.xxx.service.filemanager.FileManagerServiceImpl"
> 		address="/sysadmin/filemanager/json"
> 		bindingUri="http://apache.org/cxf/binding/http">
> 		<jaxws:serviceFactory>
> 			<ref bean="json-service-factory" />
> 		</jaxws:serviceFactory>
> 	</jaxws:endpoint>
>
> 	<bean id="json-service-factory"
> class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
> scope="prototype">
> 		<property name="properties">
> 			<map>
> 				<entry key="javax.xml.stream.XMLInputFactory" value-ref="xmlIn" />
> 				<entry key="javax.xml.stream.XMLOutputFactory" value-ref="xmlOut" />
> 				<entry key="Content-Type" value="text/plain" />
> 			</map>
> 		</property>
> 	</bean>
>
> 	<util:map id="nstojns" map-class="java.util.HashMap">
> 		<entry key="http://domain.model.xxx.com/" value="" />
> 	</util:map>
>
> 	<bean id="xmlIn"
> class="org.codehaus.jettison.mapped.MappedXMLInputFactory" >
> 		<constructor-arg ref="nstojns" />
> 	</bean>
>
> 	<bean id="xmlOut"
> class="org.codehaus.jettison.mapped.MappedXMLOutputFactory" >
> 		<constructor-arg ref="nstojns" />
> 	</bean>
>
>
> A request to the server looks like this:
>
> Address: /xxx/service/sysadmin/filemanager/json/getBatches
> Encoding: UTF-8
> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
> Headers: {accept-encoding=[gzip,deflate], connection=[keep-alive],
> referer=[http://localhost:8080/xxx/sysadmin/service-tests-admin/template.js
>p?name=filemanager-getBatches&toke=null],
> accept-charset=[ISO-8859-1,utf-8;q=0.7,*;q=0.7], pragma=[no-cache],
> Content-Type=[application/x-www-form-urlencoded; charset=UTF-8],
> x-ajax-reqid=[e], content-type=[application/x-www-form-urlencoded;
> charset=UTF-8], cookie=[JSESSIONID=799AC2CFC9100A38C6BBCC7D732CD5D7;
> fl-remember=FRd7UXI%3D; fl-user=; fl-pass=],
> Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8],
> keep-alive=[300], content-length=[40], cache-control=[no-cache],
> host=[localhost:8080], accept-language=[en-us,en;q=0.5],
> user-agent=[Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
> rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2]}
> Payload: {getBatches: {offset:0, maxResults:1}}
>
> The service method looks like this:
>
> 	public ListResult<Batch> getBatches(String offset, String maxResults) {
>
> I've isolated the problem down to jettison, i think.  When I use 1.0RC2
> (what was used with CXF 2.0.4), the offset and maxResults come through
> fine. When i use the new jettison 1.1, they are null. I *need* to use the
> new jettison because of bug fixes relating to array and list processing.
>
> Any ideas?
>
> Thanks!

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog