Hello Aki

Accorfing to http://camel.apache.org/cxf.html you can use CxfPayload class.
I did this:

        // argument 1 of RPC call - marshall using JAXB to DOM
        DOMResult arg1 = new DOMResult();
        m.marshal(new JAXBElement<>(new QName("", "arg1"), String.class,
"value1"), arg1);

        // argument 2 or RPC call - marshall using JAXB to DOM
        UserInfo userInfo = new UserInfo();
        userInfo.setName("name");
        userInfo.setAge(BigInteger.valueOf(38L));
        DOMResult arg2 = new DOMResult();
        m.marshal(new JAXBElement<>(new QName("", "arg2"), UserInfo.class,
userInfo), arg2);

        // nodes are packed into DOMSources
        sources.add(new DOMSource(arg1.getNode()));
        sources.add(new DOMSource(arg2.getNode()));

        // and used in CxfPayload
        CxfPayload<String> payload = new
CxfPayload<String>(Collections.<String>emptyList(), sources,
Collections.emptyMap());

        // which is sent to the endpoint
        Object result = template.sendBody("direct:start",
ExchangePattern.InOut, payload);

My route looks like this:

                from("direct:start")
                    .to("cxf://
http://localhost:8123/cxf/echoRPC?wsdlURL=src/test/resources/elakito/service.wsdl&dataFormat=PAYLOAD
");

I got correct result:

        CxfPayload<?> response = (CxfPayload<?>) result;
        Source s = response.getBodySources().get(0);
        JAXBElement<UserRating> rating =
jaxbContext.createUnmarshaller().unmarshal(s, UserRating.class);
        System.out.println("A: " + rating.getValue().getA());

For completeness here is the relevant part from WSDL:

    <types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://camel.test.grgr/elakito/types";
elementFormDefault="qualified">
            <xs:complexType name="UserInfo">
                <xs:sequence>
                    <xs:element name="name" type="xs:string" />
                    <xs:element name="age" type="xs:positiveInteger" />
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="UserRating">
                <xs:sequence>
                    <xs:element name="a" type="xs:int" />
                    <xs:element name="b" type="xs:int" />
                    <xs:element name="c" type="xs:int" />
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </types>

    <message name="HelloRequest">
        <part name="arg1" type="xs:string"/>
        <part name="arg2" type="types:UserInfo"/>
    </message>

    <message name="HelloResponse">
        <part name="result" type="types:UserRating"/>
    </message>

    <portType name="Elakito">
        <operation name="hello">
            <input message="tns:HelloRequest" />
            <output message="tns:HelloResponse" />
        </operation>
    </portType>

    <binding name="ElakitoSoap11Binding" type="tns:Elakito">
        <soap:binding style="rpc" transport="
http://schemas.xmlsoap.org/soap/http"; />
        <operation name="hello">
            <input name="helloRequest">
                <soap:body use="literal" namespace="
http://camel.test.grgr/elakito"; />
            </input>
            <output name="helloResponse">
                <soap:body use="literal" namespace="
http://camel.test.grgr/elakito"; />
            </output>
        </operation>
    </binding>

regards
Grzegorz Grzybek


2014-06-24 18:43 GMT+02:00 Aki Yoshida <[email protected]>:

> I am having the following problem and I am not sure if this is a known
> limitation.
>
> I have a rpc/literal styled wsdl that works fine with standalone CXF
> and would like to use this wsdl in my Camel scenario.
>
> In my Camel scenario, I set up a camel-cxf producer endpoint using a
> rpc/literal styled wsdl in the payload mode. That means, for an
> operation, its message parts corresponds to the parameters of the
> operation. And when the message is serialized, the operation name
> becomes the root element of the soap body child that in turn contains
> those parameters as its child elements.
>
> When I was passing the XML payload over my camel route to this
> endpoint, I thought I could pass the payload XML that has the
> operation name as the root element just as if its corresponding
> doc/literal wsdl were used. But this didn't work, as CXFEndpoint tried
> to match the root element against the message parts of the operation.
> That means, if the operation has one parameter and I pass this
> parameter as the XML payload, the call succeeds. But for other cases
> when there is zero parameter or more than one parameter in the
> operation, there is no way to pass a valid payload for this operation,
> as the payload is not a wellformed xml document.
>
> Ideally, I think we should be able to pass the same XML payload as if
> its corresponding doc/literal converted wsdl were used, that means,
> the XML payload with the operationName as the root and CXFEndpoint
> should unwrap the operation element for the rpc/literal case to fill
> the CXF's message content.
>
> I just wanted to ask if I am doing something wrong here or if this
> rpc/literal in camel-cxf is a known limitation?
>
> thanks.
> regards, aki
>

Reply via email to