Results 1 to 10 of 18

Thread: Newbie Question: Using Groovy on file sample

Hybrid View

  1. #1
    Join Date
    May 2011
    Posts
    10

    Unhappy Newbie Question: Using Groovy on file sample

    I am a newbie to Spring Integration and Love everything I have seen so far.

    I have been experimenting with the sample apps and making minor modifications to make sure I understand them.

    I am working with the file sample. I would like to implement the org.springframework.integration.sampes.filecopy.Ha ndler in Groovy.

    When I test it by running TextFileCopyTest, I receive the following stack trace:

    (Any Thoughts? Does someone have an example using Spring Integration and Groovy this way from the Samples?)


    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.config.ConsumerEn dpointFactoryBean#1': Cannot resolve reference to bean 'org.springframework.integration.config.ServiceAct ivatorFactoryBean#0' while setting bean property 'handler'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.config.ServiceAct ivatorFactoryBean#0': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$finalize(), public boolean org.springframework.integration.samples.filecopy.G roovyHandler.super$1$equals(java.lang.Object), public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$wait(long), public void org.springframework.integration.samples.filecopy.G roovyHandler.setMetaClass(groovy.lang.MetaClass), public java.lang.Object org.springframework.integration.samples.filecopy.G roovyHandler.this$dist$get$2(java.lang.String)]
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1325)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:563)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:197)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:172)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:158)
    at org.springframework.integration.samples.filecopy.T extFileCopyTest.testTextBasedCopy(TextFileCopyTest .java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.integration.config.ServiceAct ivatorFactoryBean#0': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$finalize(), public boolean org.springframework.integration.samples.filecopy.G roovyHandler.super$1$equals(java.lang.Object), public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$wait(long), public void org.springframework.integration.samples.filecopy.G roovyHandler.setMetaClass(groovy.lang.MetaClass), public java.lang.Object org.springframework.integration.samples.filecopy.G roovyHandler.this$dist$get$2(java.lang.String)]
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:149)
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.getObjectFromFactoryBean(Factor yBeanRegistrySupport.java:102)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getObjectForBeanInstance(AbstractBeanF actory.java:1429)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:245 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:322)
    ... 38 more
    Caused by: java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.String] for method match: [public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$finalize(), public boolean org.springframework.integration.samples.filecopy.G roovyHandler.super$1$equals(java.lang.Object), public void org.springframework.integration.samples.filecopy.G roovyHandler.super$1$wait(long), public void org.springframework.integration.samples.filecopy.G roovyHandler.setMetaClass(groovy.lang.MetaClass), public java.lang.Object org.springframework.integration.samples.filecopy.G roovyHandler.this$dist$get$2(java.lang.String)]
    at org.springframework.util.Assert.isNull(Assert.java :89)
    at org.springframework.integration.util.MessagingMeth odInvokerHelper.findHandlerMethodsForTarget(Messag ingMethodInvokerHelper.java:350)
    at org.springframework.integration.util.MessagingMeth odInvokerHelper.<init>(MessagingMethodInvokerHelpe r.java:165)
    at org.springframework.integration.util.MessagingMeth odInvokerHelper.<init>(MessagingMethodInvokerHelpe r.java:117)
    at org.springframework.integration.util.MessagingMeth odInvokerHelper.<init>(MessagingMethodInvokerHelpe r.java:112)
    at org.springframework.integration.handler.MethodInvo kingMessageProcessor.<init>(MethodInvokingMessageP rocessor.java:56)
    at org.springframework.integration.handler.ServiceAct ivatingHandler.<init>(ServiceActivatingHandler.jav a:34)
    at org.springframework.integration.config.ServiceActi vatorFactoryBean.createMethodInvokingHandler(Servi ceActivatorFactoryBean.java:48)
    at org.springframework.integration.config.AbstractSta ndardMessageHandlerFactoryBean.createHandler(Abstr actStandardMessageHandlerFactoryBean.java:72)
    at org.springframework.integration.config.AbstractSim pleMessageHandlerFactoryBean.createHandlerInternal (AbstractSimpleMessageHandlerFactoryBean.java:89)
    at org.springframework.integration.config.AbstractSim pleMessageHandlerFactoryBean.getObject(AbstractSim pleMessageHandlerFactoryBean.java:68)
    at org.springframework.integration.config.AbstractSim pleMessageHandlerFactoryBean.getObject(AbstractSim pleMessageHandlerFactoryBean.java:31)
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport.doGetObjectFromFactoryBean(Fact oryBeanRegistrySupport.java:142)
    ... 43 more

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Could you please post your configuration so we can get some context as to how you are doing it?

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    One important point this raises is that we need to add a Groovy sample, so I just created a task in JIRA for that: https://jira.springsource.org/browse/INT-1888

    In the meantime, you can see a few examples of using Groovy scripts from within Spring Integration components in these test configurations (see the XML files): http://git.springsource.org/spring-i.../groovy/config

    Hope that helps.
    -Mark

  4. #4
    Join Date
    May 2011
    Posts
    10

    Default Config Info

    Mark and Oleg,

    Thanks for the speedy reply, . . . I will look at the examples and see if I get some insights.

    Here is my config file and GroovyHandler:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:integration="http://www.springframework.org/schema/integration"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schem...ntegration.xsd
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">

    <bean class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"/>

    <file:inbound-channel-adapter id="filesIn"
    directory="/temp/spring-integration-samples/input"
    >
    <!--
    filename-pattern="[a-z]+.txt">
    -->
    <integrationoller id="poller" fixed-delay="5000"/>
    </file:inbound-channel-adapter>

    <file:file-to-string-transformer input-channel="filesIn" output-channel="store"/>

    <integration:channel id="store"/>

    <integration:service-activator input-channel="store"
    output-channel="filesOut"
    ref="handler"/>

    <file:outbound-channel-adapter id="filesOut" directory="file:/temp/spring-integration-samples/output"/>

    <bean id="handler" class="org.springframework.integration.samples.fil ecopy.GroovyHandler"/>

    </beans>

    ==============================

    package org.springframework.integration.samples.filecopy

    class GroovyHandler {

    public String handleString(String input) {
    System.out.println("Copying text: " + input);
    return input.toUpperCase();
    }

    }

  5. #5
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    When you look at those samples (in the tests), you will see that in Spring Integration you can use Groovy as *just a Script* instead of a class.

    However, if you do want a "bean" that is actually Groovy-based, then just have a look at the core Spring support for that as described here: http://static.springsource.org/sprin...e-beans-groovy

  6. #6
    Join Date
    May 2011
    Posts
    10

    Question Still having an issue

    I 've tried to simplify the example and have an attachment of the eclipse project.

    In order to simplify the process I switched from a service activator to an transformer with an inline groovy script.

    Note it is using the loadConfig in the same directory as the test, not the resource version.

    When I run TextFileCopyTest, I receive the following error and stack trace:

    Cannot resolve the name 'integration:innerPollerType' to a(n) 'type definition' component.

    Any help would be appreciated.


    org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 52 in XML document from class path resource [org/springframework/integration/samples/filecopy/loadConfig.xml] is invalid; nested exception is org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'integration:innerPollerType' to a(n) 'type definition' component.
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:302)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:143)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:122)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:92)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:467)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:397)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:197)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:172)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:158)
    at org.springframework.integration.samples.filecopy.T extFileCopyTest.testTextBasedCopy(TextFileCopyTest .java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'integration:innerPollerType' to a(n) 'type definition' component.
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(ErrorHandlerWrapper.java:131)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:384)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.reportSchemaErr(XSDHandler.java:253 7)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.reportSchemaError(XSDHandler.java:2 528)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.getGlobalDecl(XSDHandler.java:1472)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDElementTraverser.traverseNamedElement(XSDEl ementTraverser.java:369)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDElementTraverser.traverseLocal(XSDElementTr averser.java:179)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.traverseLocalElements(XSDHandler.ja va:2049)
    at com.sun.org.apache.xerces.internal.impl.xs.travers ers.XSDHandler.parseSchema(XSDHandler.java:582)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maLoader.loadSchema(XMLSchemaLoader.java:552)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.findSchemaGrammar(XMLSchemaValidator.j ava:2436)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:1781)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.startElement(XMLSchemaValidator.java:7 05)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:400)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDriver.next(XM LDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.next(XMLNSDocumentScannerImpl.java: 140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:235)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:284)
    at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:388)
    ... 34 more
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Ok, first change your POM to use 2.0.2.BUILD-SNAPSHOT. The 'innerPollerType' was removed https://jira.springsource.org/browse/INT-1715.
    Let us now. I'll try to run it in a bit.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •