java - camel stream closed error in rest service csv reader -
i have read csv file, when invoke camel rest service url (with springboot):
http://localhost:8080/camel/csv
this route builder:
@component public class camelcontextconf extends routebuilder{ static final logger logger = logger.getlogger(camelcontextconf.class); @override /** * http://localhost:8080/camel/csv */ public void configure() throws exception { restconfiguration().component("servlet"); rest("/csv").get().to("direct:csvprocessor"); csvdataformat csv = new csvdataformat(); csv.setdelimiter(";"); csv.setskipheaderrecord(true); from("direct:csvprocessor") .to("file:src/main/resources/?filename=sample-data.csv&noop=true") //.split(body().tokenize("\\n")) .unmarshal(csv) .to("bean:mycsvhandler?method=dohandlecsvdata").endrest(); logger.info("** route config ok"); } }
this handler:
@component public class mycsvhandler { public void dohandlecsvdata(list<list<string>> csvdata) { int = 1; (list<string> rows : csvdata){ system.out.println("riga: " + (i++)); (string column : rows){ system.out.print(column + " ; "); } } } }
i have set camel servlet endpoint in class
@configuration @springbootapplication(exclude = { datasourceautoconfiguration.class, hibernatejpaautoconfiguration.class, datasourcetransactionmanagerautoconfiguration.class }) @componentscan(basepackages={"... list of"}) @enabletransactionmanagement @enableautoconfiguration public class webapplicationaware extends springbootservletinitializer { private static class<webapplicationaware> applicationclass = webapplicationaware.class; static final logger logger = logger.getlogger(webapplicationaware.class); public static void main(string[] args) { springapplication.run(applicationclass, args); } @override protected springapplicationbuilder configure(springapplicationbuilder application) { return application.sources(applicationclass); } @bean public servletregistrationbean camelservletregistrationbean() { servletregistrationbean registration = new servletregistrationbean(new camelhttptransportservlet(), "/camel/*"); registration.setname("camelservlet"); logger.info("** camelservlet initialized.."); return registration; } }
but give me error when invoke rest route browser:
08/2017 17:02:34.104 info [http-nio-8080-exec-1] - org.apache.camel.component.servlet.camelhttptransportservlet: initialized camelhttptransportservlet[name=camelservlet, contextpath=] 22/08/2017 17:02:34.196 error [http-nio-8080-exec-1] - org.apache.camel.component.servlet.camelhttptransportservlet: error processing request java.io.ioexception: stream closed @ org.apache.catalina.connector.inputbuffer.read(inputbuffer.java:339) @ org.apache.catalina.connector.coyoteinputstream.read(coyoteinputstream.java:152) @ org.apache.camel.util.iohelper.copy(iohelper.java:196) @ org.apache.camel.http.common.defaulthttpbinding.copystream(defaulthttpbinding.java:427) @ org.apache.camel.http.common.defaulthttpbinding.dowritedirectresponse(defaulthttpbinding.java:491) @ org.apache.camel.http.common.defaulthttpbinding.dowriteresponse(defaulthttpbinding.java:390) @ org.apache.camel.http.common.defaulthttpbinding.writeresponse(defaulthttpbinding.java:322) @ org.apache.camel.http.common.camelservlet.doservice(camelservlet.java:210) @ org.apache.camel.http.common.camelservlet.service(camelservlet.java:74) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:230) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.requestcontextfilter.dofilterinternal(requestcontextfilter.java:99) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.httpputformcontentfilter.dofilterinternal(httpputformcontentfilter.java:105) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:81) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:197) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:198) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:96) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:474) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:140) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:87) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:349) @ org.apache.coyote.http11.http11processor.service(http11processor.java:783) @ org.apache.coyote.abstractprocessorlight.process(abstractprocessorlight.java:66) @ org.apache.coyote.abstractprotocol$connectionhandler.process(abstractprotocol.java:798) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1434) @ org.apache.tomcat.util.net.socketprocessorbase.run(socketprocessorbase.java:49) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) 22/08/2017 17:02:34.198 error [http-nio-8080-exec-1] - org.apache.catalina.core.containerbase.[tomcat].[localhost].[/].[camelservlet]: servlet.service() servlet [camelservlet] in context path [] threw exception java.io.ioexception: stream closed @ org.apache.catalina.connector.inputbuffer.read(inputbuffer.java:339) @ org.apache.catalina.connector.coyoteinputstream.read(coyoteinputstream.java:152) @ org.apache.camel.util.iohelper.copy(iohelper.java:196) @ org.apache.camel.http.common.defaulthttpbinding.copystream(defaulthttpbinding.java:427) @ org.apache.camel.http.common.defaulthttpbinding.dowritedirectresponse(defaulthttpbinding.java:491) @ org.apache.camel.http.common.defaulthttpbinding.dowriteresponse(defaulthttpbinding.java:390) @ org.apache.camel.http.common.defaulthttpbinding.writeresponse(defaulthttpbinding.java:322) @ org.apache.camel.http.common.camelservlet.doservice(camelservlet.java:210) @ org.apache.camel.http.common.camelservlet.service(camelservlet.java:74) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:230) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.requestcontextfilter.dofilterinternal(requestcontextfilter.java:99) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.httpputformcontentfilter.dofilterinternal(httpputformcontentfilter.java:105) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:81) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:197) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:198) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:96) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:474) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:140) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:87) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:349) @ org.apache.coyote.http11.http11processor.service(http11processor.java:783) @ org.apache.coyote.abstractprocessorlight.process(abstractprocessorlight.java:66) @ org.apache.coyote.abstractprotocol$connectionhandler.process(abstractprotocol.java:798) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1434) @ org.apache.tomcat.util.net.socketprocessorbase.run(socketprocessorbase.java:49) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) 22/08/2017 17:02:34.215 info [http-nio-8080-exec-1] - org.apache.catalina.core.containerbase.[tomcat].[localhost].[/]: initializing spring frameworkservlet 'dispatcherservlet' 22/08/2017 17:02:34.216 info [http-nio-8080-exec-1] - org.springframework.web.servlet.dispatcherservlet: frameworkservlet 'dispatcherservlet': initialization started 22/08/2017 17:02:34.271 info [http-nio-8080-exec-1] - org.springframework.web.servlet.dispatcherservlet: frameworkservlet 'dispatcherservlet': initialization completed in 54 ms 22/08/2017 17:18:03.326 error [http-nio-8080-exec-3] - org.apache.camel.component.servlet.camelhttptransportservlet: error processing request java.io.ioexception: stream closed @ org.apache.catalina.connector.inputbuffer.read(inputbuffer.java:339) @ org.apache.catalina.connector.coyoteinputstream.read(coyoteinputstream.java:152) @ org.apache.camel.util.iohelper.copy(iohelper.java:196) @ org.apache.camel.http.common.defaulthttpbinding.copystream(defaulthttpbinding.java:427) @ org.apache.camel.http.common.defaulthttpbinding.dowritedirectresponse(defaulthttpbinding.java:491) @ org.apache.camel.http.common.defaulthttpbinding.dowriteresponse(defaulthttpbinding.java:390) @ org.apache.camel.http.common.defaulthttpbinding.writeresponse(defaulthttpbinding.java:322) @ org.apache.camel.http.common.camelservlet.doservice(camelservlet.java:210) @ org.apache.camel.http.common.camelservlet.service(camelservlet.java:74) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:230) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.requestcontextfilter.dofilterinternal(requestcontextfilter.java:99) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.httpputformcontentfilter.dofilterinternal(httpputformcontentfilter.java:105) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:81) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:197) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:192) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:165) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:198) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:96) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:474) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:140) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:87) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:349) @ org.apache.coyote.http11.http11processor.service(http11processor.java:783) @ org.apache.coyote.abstractprocessorlight.process(abstractprocessorlight.java:66) @ org.apache.coyote.abstractprotocol$connectionhandler.process(abstractprotocol.java:798) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1434) @ org.apache.tomcat.util.net.socketprocessorbase.run(socketprocessorbase.java:49) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) 22/08/2017 17:18:03.328 error [http-nio-8080-exec-3] - org.apache.catalina.core.containerbase.[tomcat].[localhost].[/].[camelservlet]: servlet.service() servlet [camelservlet] in context path [] threw exception java.io.ioexception: stream closed...
why ? whats problem?
thanks in advice
if enrich message can use .pollenrich()
java dsl this:
from("direct:csvprocessor") .pollenrich("file:src/main/resources/?filename=sample-data.csv&noop=true&idempotent=false") ...
update
if read same file again , again use .pollenrich("file://mydir?filename=test.csv&noop=true&idempotent=false")
, in sample (it's based on first post) route sends http 200 ok string "ok" if there wasn't exception during processing.
from("direct:csvprocessor") .pollenrich("file:src/main/resources/?filename=sample-data.csv&noop=true&idempotent=false") .unmarshal(csv) .to("bean:mycsvhandler?method=dohandlecsvdata") .setbody(constant("ok")) .setheader(exchange.http_response_code, constant(200));
wiki
Comments
Post a Comment