You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sriraman Gopalan <sr...@gmail.com> on 2013/01/26 08:37:47 UTC

Camel CXF component - Adding custom context classes via the uri options

Dear All,

We use the camel - cxf component to invoke external web services. We use the
uri format with options to set various attributes as shown below:

cxf://<url>?serviceName=<serviceName>&portName=<portName>&wsdlURL=<wsdlURL>&defaultOperationName=<defaultOperationName>&serviceClass=<serviceClass>

This works well for most cases without any issues. However, the issue is
with one of the web services wherein for one operation's response , one of
the element's type is marked as xsd:any which resulted in the generated
classes having Object as the attribute type.

wsdl snippet:

<s:element name="GetWTDataResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetWTDataResult">
              <s:complexType>
                <s:sequence>
                  
                  <s:any />
                </s:sequence>
              </s:complexType>
            </s:element>
          </s:sequence>
        </s:complexType>
      </s:element>

Generated Java Code Snippet:

public static class GetWTDataResult {

        @XmlAnyElement(lax = true)
        protected Object any;

       
        public Object getAny() {
            return any;
        }

      
        public void setAny(Object value) {
            this.any = value;
        }

    }


While invoking the actual service ( a .NET web service), the response comes
with the xsd and the data.

Actual web service response snippet:

<GetWTDataResponse xmlns="http://tempuri.org/">
      <GetWTDataResult>
        <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
          <xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
            <xs:complexType>
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="Table">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="InsType" type="xs:string"
minOccurs="0"/>
                      <xs:element name="MarketVal" type="xs:double"
minOccurs="0"/>
                      <xs:element name="InvestAmount" type="xs:double"
minOccurs="0"/>
                      <xs:element name="TransDate" type="xs:dateTime"
minOccurs="0"/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
              </xs:choice>
            </xs:complexType>
          </xs:element>
        </xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <NewDataSet xmlns="">
            

              <InsType>Equity</InsType>
              <MarketVal>6626</MarketVal>
              <InvestAmount>14947.77</InvestAmount>
              <TransDate>2013-01-25T15:52:00+05:30</TransDate>
            

          </NewDataSet>
        </diffgr:diffgram>
      </GetWTDataResult>
    </GetWTDataResponse>


To make jaxb aware of this element "NewDataSet", we generated the jaxb
classes from the xsd in the web service response as shown above using
maven-jaxb2-plugin.

Now, the issue is how do we make this custom jaxb classes available to cxf
so that it correctly deserializes the response?

After searching the net, we found that this can be accomplished via code as
shown in the following link:

progress documentation
<http://documentation.progress.com/output/Iona/artix/5.1/jaxws_pguide/JAXWSDataMappingOverMoreClasses.html>  

Since, we are using camel cxf component, is there any other way to indicate
to cxfendpoint to use these extra jaxb classes?

I did notice that the camel cxf component allows setting of custom cxf
properties via the properties.XXX format.

However, I am not too sure how to set this for the
jaxb.additionalContextClasses property which is a property in the
jaxwsproxyfactory bean.

Any help would be highly appreciated.

best regards
Sriraman.




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-component-Adding-custom-context-classes-via-the-uri-options-tp5726313.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel CXF component - Adding custom context classes via the uri options

Posted by Sriraman Gopalan <sr...@gmail.com>.
After some digging, I finally fixed the issue. Here is how I did it.
Probably, there is a better way of doing this. But, here is my version and
this works .

Step I:

Extract the schema from the web service response. Generate jaxb entities
using the maven-jaxb2-plugin. (Ensure that the schema's namespace matches
the wrapper's element's namespace.


Step II:

Create a JAX-WS logical Handler. In the handleMessage method, grab the
payload as follows:

...;
LogicalMessage lm = context.getMessage();
Source payload = lm.getPayload();
...;

Step III:

Stripped all unwanted xsd:schema elements as shown in the previous post by
using nekohtml.

Step IV:

Created a jaxb context and unmarshalled the stripped response.

The logical handler is configured via the uri options as follows:

cxf://<url>?serviceName=<serviceName>&portName=<portName>&wsdlURL=<wsdlURL>&defaultOperationName=<defaultOperationName>&serviceClass=<serviceClass>&*handlers=#cxfhandlers*

The #cxfhandlers will look up the registry with bean id = "cxfhandlers".

The cxfhandlers bean is defined as follows:

<bean class="com.example.ListFactoryBean" id="cxfhandlers" >
		<property name="classes">
			<list>
				<value>com.example.DataHandler</value>
			</list>
		</property>
</bean>

The ListFactoryBean is a factory bean which returns a list of objects
implementing the handler interface.

With these, I was able to get the response as a JaxB object.


best regards
Sriraman.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-CXF-component-Adding-custom-context-classes-via-the-uri-options-tp5726313p5726403.html
Sent from the Camel - Users mailing list archive at Nabble.com.