TransformationFeaturePage edited by Freeman FangChanges (3)
Full ContentTransformation Feature The CXF Transformation feature provides for a flexible and fast way to do the dynamic transformations of the inbound and/or outbound XML messages. This feature can be used in a number of cases: dropping the namespace of the outbound messages, qualifying the incoming message, changing namespaces, appending or dropping elements and converting attributes to elements. The "outTransformElements", "inTransformElements", "outDropElements", "inDropElements", "outAppendElements", "inAppendElements" and "attributesAsElements" properties can be used. Spring configurationThe following properties can be set from Spring:
<bean id="transformFeature" class="org.apache.cxf.feature.StaxTransformFeature"> <property name="outTransformElements"> <map> <!-- change "book" to "thebook" --> <entry key="book" value="thebook"/> <!-- drop the namespace from "book" --> <entry key="{http://books}book" value="book"/> <!-- qualify "book" with "http://books" --> <entry key="book" value="{http://books}thebook"/> <!-- change namespace to "http://books" for all the elements with the "http://book" namespace --> <entry key="{http://book}*" value="{http://books}*"/> </map> </property> </bean>
<bean id="transformFeature" class="org.apache.cxf.feature.StaxTransformFeature"> <property name="outAppendElements"> <map> <!-- append "book" before "thebook" --> <entry key="book" value="thebook"/> <!-- qualify "book" with "http://books" --> <entry key="{http://books}book" value="book"/> <!-- drop the namespace from the "book" --> <entry key="book" value="{http://books}thebook"/> <!-- change namespace to "http://book" for all the elements with the "http://books" namespace --> <entry key="{http://book}*" value="{http://books}*"/> </map> </property> </bean>
<bean id="transformFeature" class="org.apache.cxf.feature.StaxTransformFeature"> <property name="outDropElements"> <list> <!-- ignore drop and {http://numbers}number elements --> <value>{http://numbers}number</value> <value>index</value> </list> </property> </bean>
The combination of "attributesAsElements" and "outDropElements" properties can be used to have certain attributes ignored in the output by turning then into elements first and then blocking them. Configuring the feature from the codeThe feature can be configured from the code for JAX-WS or JAX-RS clients and endpoints. JAX-WSHere is how a JAX-WS client can be configured: CustomerServiceService service = new CustomerServiceService(); CustomerService customerService = service.getCustomerServicePort(); Client client = ClientProxy.getClient(customerService); // drop namespace from all elements qualified by 'http://customers' Map<String, String> outTransformMap = Collections.singletonMap("{http://customers}*", "*"); org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor = new org.apache.cxf.interceptor.transform.TransformOutInterceptor(); transformOutInterceptor.setOutTransformElements(outTransformMap); client.getOutInterceptors().add(transformOutInterceptor); // qualify the incoming 'customer' element with 'http://customers' Map<String, String> inTransformMap = Collections.singletonMap("customer", "{http://customers}customer"); org.apache.cxf.interceptor.transform.TransformInInterceptor transformInInterceptor = new org.apache.cxf.interceptor.transform.TransformInInterceptor(); transformInInterceptor.setInTransformElements(inTransformMap); client.getInInterceptors().add(transformInInterceptor); JAX-RSHere is how a JAX-RS client can be configured: CustomerService customerServiceProxy = JAXRSClientFactory.create(endpointAddress, CustomerService.class); ClientConfiguration config = WebClient.getConfig(customerServiceProxy); // or //WebClient client = WebClient.create(endpointAddress); //ClientConfiguration config = WebClient.getConfig(client); // drop namespace from all elements qualified by 'http://customers' Map<String, String> outTransformMap = Collections.singletonMap("{http://customers}*", "*"); org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor = new org.apache.cxf.interceptor.transform.TransformOutInterceptor(); transformOutInterceptor.setOutTransformElements(outTransformMap); config.getOutInterceptors().add(transformOutInterceptor); // qualify the incoming 'customer' element with 'http://customers' Map<String, String> inTransformMap = Collections.singletonMap("customer", "{http://customers}customer"); org.apache.cxf.interceptor.transform.TransformInInterceptor transformInInterceptor = new org.apache.cxf.interceptor.transform.TransformInInterceptor(); transformInInterceptor.setInTransformElements(inTransformMap); config.getInInterceptors().add(transformInInterceptor);
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence
- [CONF] Apache CXF Documentation > TransformationFeature confluence