Reputation: 180
Hi I am Trying to extract multiple messages from a single message and split those into multiple messages using a splitter element. But my Splitter is throwing the below error
2015-10-26 15:09:06,257 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#1': Cannot create inner bean 'org.springframework.integration.config.SplitterFactoryBean#20e2ef61' of type [org.springframework.integration.config.SplitterFactoryBean] while setting bean property 'handlers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.SplitterFactoryBean#20e2ef61': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public java.util.List com.salesorder.payment.util.PoslogToIsellRequests.poslogTransformer(java.lang.String), public java.util.List com.salesorder.payment.util.PoslogToIsellRequests.split(java.util.List)] at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121) at
The splitter block:
<si:splitter>
<bean
class="com.ikea.pip.salesorder.payment.util.PoslogToIsellRequests"
p:mapTaxRateCategory="${common.map.tax.rate.category}" p:buCode="${common.country.code.iso}"
p:sourceRegion="${common.isell.order.source}" p:countryCode ="${common.country.code.iso}" />
</si:splitter>
Java Code of the class:
public class PoslogToIsellRequests implements Splitter {
private static final Logger LOG = LoggerFactory
.getLogger(PoslogToIsellRequests.class);
private static final String ORDER= "SpecialOrderNumber";
private static XMLInputFactory inputFactory;
private final SimpleXslt transformPoslogXslt = new SimpleXslt(
"xsl/POSLogToAddPaymentRequest.xsl");
private String sourceRegion;
private String buCode;
private String mapTaxRateCategory;
private String countryCode;
static {
inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
Boolean.TRUE);
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
@Override
public List<String> split(List<String> xmlToSplit) {
List<String> splittedPayload = new ArrayList<String>();
for (String xml : xmlToSplit) {
splittedPayload.addAll(split(xml));
}
return splittedPayload;
}
public void setSourceRegion(String sourceRegion) {
this.sourceRegion = sourceRegion;
}
public void setBuCode(String buCode) {
this.buCode = buCode;
}
public void setMapTaxRateCategory(String mapTaxRateCategory) {
this.mapTaxRateCategory = mapTaxRateCategory;
}
/* @param xmlToSplit
* @return
* @throws Exception
*/
@Override
public List<String> split(String xmlToSplit) {
List<String> resultSet=new ArrayList<String>();
resultSet=poslogTransformer(xmlToSplit);
return resultSet;
}
public List<String> poslogTransformer(String xmlToSplit) {
List<String> resultSet=null;
Set<String> orderNos=new HashSet<String>();
String payload = xmlToSplit;
try{
orderNos= parseOrderNos(payload);
resultSet=new ArrayList<String>();
}
catch (XMLStreamException e) {
LOG.warn("Could not parse Transaction");
}
for(String orderno:orderNos){
Map<String, String> parameters = createParams(orderno);
String result = transformPoslogXslt.transform(payload,
parameters);
resultSet.add(result);
}
return resultSet;
}
private Map<String, String> createParams(String orderNo) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("sourceRegion", sourceRegion);
parameters.put("buCode",buCode );
parameters.put("mapTaxRateCategory",mapTaxRateCategory );
parameters.put("orderNo",orderNo );
parameters.put("countryCode", countryCode);
return parameters;
}
private Set<String> parseOrderNos(String payload) throws XMLStreamException {
Set<String> orders=new HashSet<String>();
XMLEventReader reader;
reader = inputFactory.createXMLEventReader(new StringReader(payload));
String currentElement = "";
try {
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
currentElement = event.asStartElement().getName()
.getLocalPart();
} else if (currentElement.equals(ORDER)
&& event.isCharacters()) {
String value = event.asCharacters().getData();
if(StringUtils.isNotBlank(value)){
orders.add(value);}
}
}
} finally {
reader.close();
}
return orders;
}
}
The Splitter interface is just contains two split method. Is method overloading not allowed in spring Integration?
One additional query can I have string input as a parameter instead of message?
Upvotes: 0
Views: 1263
Reputation: 174584
If you don't explicity identify the method name in the splitter, the framework will detect multiple method candidates and won't be able to determine which one to call.
Hence:
Found ambiguous parameter type [class java.lang.String] for method match: [public java.util.List com.salesorder.payment.util.PoslogToIsellRequests.poslogTransformer(java.lang.String), public java.util.List com.salesorder.payment.util.PoslogToIsellRequests.split(java.util.List)]
All public methods are considered for POJO method matching unless you specify method="split"
.
If you add that, the framework will invoke the appropriate split
method, depending on the payload type of the inbound message.
Upvotes: 1