java - Unzip with spring integration -
i want listen directory, read in new .zip files , in best case pass on @serviceactivator unzips directory. in worst case @ least want absolute path read in zip files , call java unzip util on path unzip it.
here's inboundchanneladapter:
@bean @inboundchanneladapter(value = "requestchannel", poller = @poller(fixeddelay = "100")) public filereadingmessagesource adapter() { filereadingmessagesource source = new filereadingmessagesource(); source.setdirectory(new file("path/to/zip/directory")); return source; } this reads in new .zips , passes them on. tried small writer, writes them directory, works fine.
@bean @serviceactivator(inputchannel = "requestchannel" ) public boolean unzipme() { byte[] buffer = new byte[1024]; try { zipinputstream zis = new zipinputstream(new fileinputstream("path/to/zip")); zipentry ze = zis.getnextentry(); while(ze!=null){ string filename = ze.getname(); file output = new file("path/out/directory" + file.separator + filename); fileoutputstream fos = new fileoutputstream(output); int len; system.out.println("output " + output.tostring()); while((len = zis.read(buffer))> 0){ fos.write(buffer, 0, len); } fos.close(); ze = zis.getnextentry(); } zis.closeentry(); zis.close(); } catch (exception e) { e.printstacktrace(); } return true; } this unzip method, should invoked message comes requestchannel, , unzip file. @ moment hardcoded path .zip, because can't message arrives here. implementation gives me error, don't understand.
exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'integrationconfiguration' defined in file [d:\workspaces\integrationnnn\target\classes\demo\integrationconfiguration.class]: initialization of bean failed; nested exception java.lang.illegalargumentexception: found ambiguous parameter type [class java.lang.boolean] method match: [public static boolean java.lang.boolean.parseboolean(java.lang.string), public static java.lang.boolean java.lang.boolean.valueof(boolean), public boolean java.lang.boolean.booleanvalue()] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:547) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:755) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.boot.springapplication.refresh(springapplication.java:686) @ org.springframework.boot.springapplication.run(springapplication.java:320) @ org.springframework.boot.springapplication.run(springapplication.java:957) @ org.springframework.boot.springapplication.run(springapplication.java:946) @ demo.integrationnnnapplication.main(integrationnnnapplication.java:12) caused by: java.lang.illegalargumentexception: found ambiguous parameter type [class java.lang.boolean] method match: [public static boolean java.lang.boolean.parseboolean(java.lang.string), public static java.lang.boolean java.lang.boolean.valueof(boolean), public boolean java.lang.boolean.booleanvalue()] @ org.springframework.util.assert.isnull(assert.java:89) @ org.springframework.integration.util.messagingmethodinvokerhelper.findhandlermethodsfortarget(messagingmethodinvokerhelper.java:446) @ org.springframework.integration.util.messagingmethodinvokerhelper.<init>(messagingmethodinvokerhelper.java:192) @ org.springframework.integration.util.messagingmethodinvokerhelper.<init>(messagingmethodinvokerhelper.java:136) @ org.springframework.integration.util.messagingmethodinvokerhelper.<init>(messagingmethodinvokerhelper.java:131) @ org.springframework.integration.handler.methodinvokingmessageprocessor.<init>(methodinvokingmessageprocessor.java:57) @ org.springframework.integration.handler.serviceactivatinghandler.<init>(serviceactivatinghandler.java:37) @ org.springframework.integration.config.annotation.serviceactivatorannotationpostprocessor.createhandler(serviceactivatorannotationpostprocessor.java:65) @ org.springframework.integration.config.annotation.abstractmethodannotationpostprocessor.postprocess(abstractmethodannotationpostprocessor.java:117) @ org.springframework.integration.config.annotation.messagingannotationpostprocessor$1.dowith(messagingannotationpostprocessor.java:151) @ org.springframework.util.reflectionutils.dowithmethods(reflectionutils.java:496) @ org.springframework.util.reflectionutils.dowithmethods(reflectionutils.java:503) @ org.springframework.integration.config.annotation.messagingannotationpostprocessor.postprocessafterinitialization(messagingannotationpostprocessor.java:131) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:422) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1571) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) ... 13 more this reliably unzip .zip file right directory, crashes horribly afterwards.
the simple solution implement own messagehandler , overwrite handlemessageinternal method.
Comments
Post a Comment