Skip to content

Instantly share code, notes, and snippets.

@cignextraining
Created April 22, 2018 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cignextraining/86378344e9d43db01d30b1f69149ae9b to your computer and use it in GitHub Desktop.
Save cignextraining/86378344e9d43db01d30b1f69149ae9b to your computer and use it in GitHub Desktop.
Transformers - XML Unmarshalling
<!-- Scans within the base package of the application for @Components to
configure as beans -->
<context:component-scan base-package="com.cd.spring" />
<!-- Adapter for reading files -->
<int-file:inbound-channel-adapter id="producer-file-adapter"
channel="inboundChannel" directory="file:d://si-inbound"
prevent-duplicates="true">
<int:poller fixed-rate="5000" />
</int-file:inbound-channel-adapter>
<!-- a direct inbound channel -->
<int:channel id="inboundChannel" />
<!-- File to String Transformer -->
<!--
This transformer converts a SI message with File as its payload to a
SI message with a string as its payload.
The String in the resulting message contains the content of the file.
-->
<int-file:file-to-string-transformer
id="file-2-string-transformer" input-channel="inboundChannel"
output-channel="xml-inboundChannel" charset="UTF-8" />
<!-- a direct inbound channel for reading strings containing XML data provided by file-to-string-transformer -->
<int:channel id="xml-inboundChannel" />
<!-- a direct outbound channel -->
<int:channel id="outboundChannel" />
<!-- Service Activator -->
<!-- Takes messages from outboundChannel and
prints the content of messages to the console view -->
<int:service-activator id="printing-service-activator"
input-channel="outboundChannel" ref="serviceActivator" />
<bean id="serviceActivator" class="com.cd.spring.ExampleServiceActivator" />
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="contextPath" value="com.cd.spring.domain" /> </bean>
<int-xml:unmarshalling-transformer id="xml-2-object-transformer" input-channel="xml-inboundChannel" output-channel="outboundChannel" unmarshaller="jaxbMarshaller" />
package com.cd.spring;
public class ExampleServiceActivator {
public void printShiporder(Object order){
System.out.println(order);
}
}
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2018.04.18 at 12:55:41 PM IST
//
package com.cd.spring.domain;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.cd.spring.domain package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.cd.spring.domain
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Shiporder }
*
*/
public Shiporder createShiporder() {
return new Shiporder();
}
/**
* Create an instance of {@link Shiporder.Shipto }
*
*/
public Shiporder.Shipto createShiporderShipto() {
return new Shiporder.Shipto();
}
/**
* Create an instance of {@link Shiporder.Item }
*
*/
public Shiporder.Item createShiporderItem() {
return new Shiporder.Item();
}
}
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2018.04.18 at 12:55:41 PM IST
//
package com.cd.spring.domain;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="orderperson" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="shipto">
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="address" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="city" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="country" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;/element>
* &lt;element name="item" maxOccurs="unbounded">
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="note" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
* &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;/element>
* &lt;/sequence>
* &lt;attribute name="orderid" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"orderperson",
"shipto",
"item"
})
@XmlRootElement(name = "shiporder")
public class Shiporder {
@XmlElement(required = true)
protected String orderperson;
@XmlElement(required = true)
protected Shiporder.Shipto shipto;
@XmlElement(required = true)
protected List<Shiporder.Item> item;
@XmlAttribute(name = "orderid", required = true)
protected String orderid;
/**
* Gets the value of the orderperson property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getOrderperson() {
return orderperson;
}
/**
* Sets the value of the orderperson property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setOrderperson(String value) {
this.orderperson = value;
}
/**
* Gets the value of the shipto property.
*
* @return
* possible object is
* {@link Shiporder.Shipto }
*
*/
public Shiporder.Shipto getShipto() {
return shipto;
}
/**
* Sets the value of the shipto property.
*
* @param value
* allowed object is
* {@link Shiporder.Shipto }
*
*/
public void setShipto(Shiporder.Shipto value) {
this.shipto = value;
}
/**
* Gets the value of the item property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the item property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getItem().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Shiporder.Item }
*
*
*/
public List<Shiporder.Item> getItem() {
if (item == null) {
item = new ArrayList<Shiporder.Item>();
}
return this.item;
}
/**
* Gets the value of the orderid property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getOrderid() {
return orderid;
}
/**
* Sets the value of the orderid property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setOrderid(String value) {
this.orderid = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="note" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
* &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"title",
"note",
"quantity",
"price"
})
public static class Item {
@XmlElement(required = true)
protected String title;
protected String note;
@XmlElement(required = true)
@XmlSchemaType(name = "positiveInteger")
protected BigInteger quantity;
@XmlElement(required = true)
protected BigDecimal price;
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
/**
* Gets the value of the note property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getNote() {
return note;
}
/**
* Sets the value of the note property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setNote(String value) {
this.note = value;
}
/**
* Gets the value of the quantity property.
*
* @return
* possible object is
* {@link BigInteger }
*
*/
public BigInteger getQuantity() {
return quantity;
}
/**
* Sets the value of the quantity property.
*
* @param value
* allowed object is
* {@link BigInteger }
*
*/
public void setQuantity(BigInteger value) {
this.quantity = value;
}
/**
* Gets the value of the price property.
*
* @return
* possible object is
* {@link BigDecimal }
*
*/
public BigDecimal getPrice() {
return price;
}
/**
* Sets the value of the price property.
*
* @param value
* allowed object is
* {@link BigDecimal }
*
*/
public void setPrice(BigDecimal value) {
this.price = value;
}
@Override
public String toString() {
return "Item [title=" + title + ", note=" + note + ", quantity=" + quantity + ", price=" + price + "]";
}
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="address" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="city" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="country" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"address",
"city",
"country"
})
public static class Shipto {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String address;
@XmlElement(required = true)
protected String city;
@XmlElement(required = true)
protected String country;
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the address property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getAddress() {
return address;
}
/**
* Sets the value of the address property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setAddress(String value) {
this.address = value;
}
/**
* Gets the value of the city property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCity() {
return city;
}
/**
* Sets the value of the city property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCity(String value) {
this.city = value;
}
/**
* Gets the value of the country property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCountry() {
return country;
}
/**
* Sets the value of the country property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCountry(String value) {
this.country = value;
}
@Override
public String toString() {
return "Shipto [name=" + name + ", address=" + address + ", city=" + city + ", country=" + country + "]";
}
}
@Override
public String toString() {
return "Shiporder [orderperson=" + orderperson + ", shipto=" + shipto + ", item=" + item + ", orderid="
+ orderid + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment