Last active
August 14, 2021 08:13
-
-
Save cignextraining/7cf6a1d98125853aa018d8ccf0647d42 to your computer and use it in GitHub Desktop.
Enrichers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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-to-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" /> | |
<int-xml:unmarshalling-transformer | |
id="xml-2-object-transformer" input-channel="xml-inboundChannel" | |
output-channel="shipOrder-Channel" unmarshaller="jaxbMarshaller" /> | |
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> | |
<property name="contextPath" value="com.cd.spring.domain.enricher" /> | |
</bean> | |
<int:channel id="shipOrder-Channel" /> | |
<int:enricher id="ship-order-enricher" input-channel="shipOrder-Channel" output-channel="outboundChannel"> | |
<int:property name="shipped" expression="true"/> | |
</int:enricher> | |
<int:channel id="outboundChannel" /> | |
<bean id="serviceActivator" class="com.cd.spring.ExampleServiceActivator" /> | |
<int:service-activator id="printing-service-activator" | |
input-channel="outboundChannel" ref="serviceActivator" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cd.spring; | |
import org.springframework.messaging.Message; | |
import com.cd.spring.domain.Shiporder; | |
import com.cd.spring.domain.Shiporder.Item; | |
public class ShipOrderEnricher { | |
public double computeTotal(Message<Shiporder> order) { | |
double sum = 0; | |
for (Item item : order.getPayload().getItem()) { | |
sum = sum + (item.getPrice().doubleValue() * item.getQuantity().intValue()); | |
} | |
return sum; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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-to-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" /> | |
<int:channel id="shipOrder-Channel" /> | |
<int-xml:unmarshalling-transformer | |
id="xml-2-object-transformer" input-channel="xml-inboundChannel" | |
output-channel="shipOrder-Channel" unmarshaller="jaxbMarshaller" /> | |
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> | |
<property name="contextPath" value="com.cd.spring.domain" /> | |
</bean> | |
<int:channel id="outboundChannel" /> | |
<bean id="serviceActivator" class="com.cd.spring.ExampleServiceActivator" /> | |
<int:service-activator id="printing-service-activator" | |
input-channel="outboundChannel" ref="serviceActivator" /> | |
<int:channel id="total-price-enricher-channel" /> | |
<bean id="shipOrderEnricher" class="com.cd.spring.ShipOrderEnricher"/> | |
<int:service-activator id="enriching-service-activator" ref="shipOrderEnricher" | |
input-channel="total-price-enricher-channel"/> | |
<int:enricher id="ship-order-enricher" input-channel="shipOrder-Channel" | |
output-channel="outboundChannel" request-channel="total-price-enricher-channel"> | |
<int:property name="shipped" expression="true"/> | |
<int:property name="orderTotal" expression="payload" /> | |
</int:enricher> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 | |
// 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: 2014.07.27 at 10:39:30 PM CDT | |
// | |
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; | |
import javax.xml.bind.annotation.XmlTransient; | |
/** | |
* <p> | |
* Java class for anonymous complex type. | |
* | |
* <p> | |
* The following schema fragment specifies the expected content contained within | |
* this class. | |
* | |
* <pre> | |
* <complexType> | |
* <complexContent> | |
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> | |
* <sequence> | |
* <element name="orderperson" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="shipto"> | |
* <complexType> | |
* <complexContent> | |
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> | |
* <sequence> | |
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="address" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="city" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="country" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* </sequence> | |
* </restriction> | |
* </complexContent> | |
* </complexType> | |
* </element> | |
* <element name="item" maxOccurs="unbounded"> | |
* <complexType> | |
* <complexContent> | |
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> | |
* <sequence> | |
* <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="note" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> | |
* <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/> | |
* <element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/> | |
* </sequence> | |
* </restriction> | |
* </complexContent> | |
* </complexType> | |
* </element> | |
* </sequence> | |
* <attribute name="orderid" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /> | |
* </restriction> | |
* </complexContent> | |
* </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; | |
@XmlTransient | |
protected double orderTotal; | |
@XmlTransient | |
protected boolean shipped = false; | |
/** | |
* 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; | |
} | |
public double getOrderTotal() { | |
return orderTotal; | |
} | |
public void setOrderTotal(double orderTotal) { | |
this.orderTotal = orderTotal; | |
} | |
public boolean isShipped() { | |
return shipped; | |
} | |
public void setShipped(boolean shipped) { | |
this.shipped = shipped; | |
} | |
/** | |
* 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> | |
* <complexType> | |
* <complexContent> | |
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> | |
* <sequence> | |
* <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="note" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> | |
* <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/> | |
* <element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/> | |
* </sequence> | |
* </restriction> | |
* </complexContent> | |
* </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> | |
* <complexType> | |
* <complexContent> | |
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> | |
* <sequence> | |
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="address" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="city" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* <element name="country" type="{http://www.w3.org/2001/XMLSchema}string"/> | |
* </sequence> | |
* </restriction> | |
* </complexContent> | |
* </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 [Order Total = " + orderTotal +"];[orderperson=" + orderperson + ", shipto=" + shipto | |
+ ", item=" + item + ", orderid=" + orderid + ", shipped= " + shipped + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment