camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chubutin <>
Subject How to return null element with Camel-CXF
Date Wed, 12 Feb 2014 15:35:22 GMT

I'm having problems when I try to return a null element in SOAP response.
When I send a null body as response to CXF Bean, this Bean doesn't create a
null response and return that null element to the response. So, i want to
return a null element in the response but I can't.

If I test the service with mocks I can see if the response is 

<soapenv:Envelope xmlns:soapenv=""

This will get a null element in the response and this is what I want.

But, CXF doesn't make that response with any element in the body response.

My camel route with CXF consumer, processors, http call and xslt 

this is my route 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<route group="com.esb.camel.route.InternalGetRouteBuilder"
id="searchByNameRouteGET" xmlns="">
    <from uri="cxf:bean:getConsumerEndpoint"/>
    <to uri="getByNamePreProcessor"/>
    <setHeader headerName="CamelHttpQuery">
    <setHeader headerName="CamelHttpMethod">
        <expressionDefinition/> (this is setBody(xpath("/*"))
    <to uri="xslt:xslt/transformationByNameXSLT.xslt?failOnNullBody=false"/>
        <protobuf xsi:type="dataFormat"

I use a dataformat at the end to Marshall the XML after the XSLT. When I
send null to the dataformat it get an exception.

After the xslt transformation I send many thing to test, but I cant get
figure what to configure in my service to response a null response. like [1]

I only can response a not null response, like 

<soapenv:Envelope xmlns:soapenv=""

My CXF bean is 

	<camelcxf:cxfEndpoint id="getConsumerEndpoint"
			<entry key="dataFormat" value="POJO" />

The SEI of The service is 

@WebService(name = "VesselVisitorsService")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, style =
Style.DOCUMENT, use = Use.LITERAL)
public interface com.esb.service.vessel.VesselVisitorsService

	@WebMethod(operationName = "getByName")
	@RequestWrapper(localName = "visitorName")
	@ResponseWrapper(localName = "getByNameResponse")
	@WebResult(name = "vesselVisitor")
	@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, style =
Style.DOCUMENT, use = Use.LITERAL)
	public VesselVisitor getByName(
			@WebParam(name = "vesselName") String vesselName) throws

In org.apache.cxf.databinding.AbstractWrapperHelper

Object wrapperObject = createWrapperObject(wrapperType);
            for (int x = 0; x < setMethods.length; x++) {
                if (getMethods[x] == null
                    && setMethods[x] == null 
                    && fields[x] == null) {
                    //this part is a header or something
                    //that is not part of the wrapper.
              *  Object o = lst.get(x); [2]*
                o = getPartObject(x, o);                
                if (o instanceof List && getMethods[x] != null) {
                    List col =
                    if (col == null) {
                        //broken generated java wrappers
                        if (setMethods[x] != null) {
                            setMethods[x].invoke(wrapperObject, o);
                        } else {
                            fields[x].set(wrapperObject, lst.get(x));
                    } else {
                        List olst = CastUtils.cast((List<?>)o);
                } else if (setMethods[x] != null) {                        
                    setMethods[x].invoke(wrapperObject, o);
                } else if (fields[x] != null) {
                    fields[x].set(wrapperObject, lst.get(x));

The line remarked is what get the NPE. So in debugging I initialized a List
and put a null element to the list. And with this I had a null valid

So, Does I always have to response with a list with a element inside the
wrapper to make  a null response? 

Thank you!

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message