java - How do I find out , what exception occurred in spring integration? -



java - How do I find out , what exception occurred in spring integration? -

how find out , exception occurred in spring integration, when send message server via tcp client. , there <int-ip:tcp-connection-factory> ( client ! ), , has error channel. when connection created between client , server , after few seconds server closes connection there exception.it's ok, , able grab it, exception : "read timed out". when connection dosn't create , because server doesn't hear specified port, don't cache exception via error channel. therefore, i'am trying cache exceptions in way :

try{ success = gateway.send(adaptor); } grab ( messagingexception exc){ system.out.println("exception occurred : timed out waiting response"); }

but - @ point - cache

timed out waiting response

exception reason. ( example, when server close connection, or the connection doesn't occurre ) can't take difference between exceptions. hence , hear both catching mechanism , error channel @ once.

my not elegant solution :

main service class : success = 0; try{ success = gateway.send(adaptor); // homecoming 1, if there aren't exception homecoming "success"; } grab ( messagingexception exc){ seek { thread.sleep(1000); // have wait error channel's message, portion not elegant ! } grab (interruptedexception e) { homecoming "error"; } if ( success == 2){ homecoming "the server closed connection"; } else { homecoming "there no connection server"; }

the error handler snippet :

public void onexception(tcpconnectionexceptionevent event){ mainservice.setsuccess(2); }

is there simple, , more elegant solution ?

correction: utilize spring integration 4.04 , here client pipe's beans :

<!-- client side --> <int:gateway id="gw" service-interface="hu.gmxdev.climaxreplica.service.simplegateway" default-request-channel="outputchannel" /> <int-ip:tcp-connection-factory id="client" type="client" host="localhost" port="10001" single-use="true" so-timeout="5000" /> <int:channel id="outputchannel" /> <int-ip:tcp-outbound-gateway id="outgateway" request-channel="outputchannel" reply-channel="replychannel" connection-factory="client" request-timeout="5000" reply-timeout="5000" /> <int:service-activator input-channel="replychannel" method="reply" ref="echoservice" id="serviceactivator"> </int:service-activator> <int:channel id="replychannel"></int:channel> <int-ip:tcp-connection-event-inbound-channel-adapter id="event" event-types="org.springframework.integration.ip.tcp.connection.tcpconnectionexceptionevent" channel="errorchannel" /> <int:channel id="errorchannel"></int:channel> <int:service-activator ref="tcperrorhandler" method="onexception" input-channel="errorchannel"> </int:service-activator>

i add together track trace. this 1 is, when server closes established connection, or server doesn't reply client within expected time. track trace same in both case. :

org.springframework.integration.messagetimeoutexception: timed out waiting response @ org.springframework.integration.ip.tcp.tcpoutboundgateway.handlerequestmessage(tcpoutboundgateway.java:132) @ org.springframework.integration.handler.abstractreplyproducingmessagehandler.handlemessageinternal(abstractreplyproducingmessagehandler.java:170) @ org.springframework.integration.handler.abstractmessagehandler.handlemessage(abstractmessagehandler.java:78) @ org.springframework.integration.dispatcher.abstractdispatcher.tryoptimizeddispatch(abstractdispatcher.java:116) @ org.springframework.integration.dispatcher.unicastingdispatcher.dodispatch(unicastingdispatcher.java:101) @ org.springframework.integration.dispatcher.unicastingdispatcher.dispatch(unicastingdispatcher.java:97) @ org.springframework.integration.channel.abstractsubscribablechannel.dosend(abstractsubscribablechannel.java:77) @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:255) @ org.springframework.integration.channel.abstractmessagechannel.send(abstractmessagechannel.java:223) @ org.springframework.messaging.core.genericmessagingtemplate.dosend(genericmessagingtemplate.java:109) @ org.springframework.messaging.core.genericmessagingtemplate.dosendandreceive(genericmessagingtemplate.java:144) @ org.springframework.messaging.core.genericmessagingtemplate.dosendandreceive(genericmessagingtemplate.java:44) @ org.springframework.messaging.core.abstractmessagingtemplate.sendandreceive(abstractmessagingtemplate.java:75) @ org.springframework.messaging.core.abstractmessagingtemplate.convertsendandreceive(abstractmessagingtemplate.java:125) @ org.springframework.messaging.core.abstractmessagingtemplate.convertsendandreceive(abstractmessagingtemplate.java:103) @ org.springframework.integration.gateway.messaginggatewaysupport.dosendandreceive(messaginggatewaysupport.java:241) @ org.springframework.integration.gateway.messaginggatewaysupport.sendandreceive(messaginggatewaysupport.java:220) @ org.springframework.integration.gateway.gatewayproxyfactorybean.invokegatewaymethod(gatewayproxyfactorybean.java:341) @ org.springframework.integration.gateway.gatewayproxyfactorybean.doinvoke(gatewayproxyfactorybean.java:304) @ org.springframework.integration.gateway.gatewayproxyfactorybean.invoke(gatewayproxyfactorybean.java:295) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:207) @ com.sun.proxy.$proxy115.send(unknown source) @ hu.gmxdev.climaxreplica.service.mainservice.senddata(mainservice.java:88) @ hu.gmxdev.climaxreplica.controller.maincontroller.senddata(maincontroller.java:42) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:215) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:749) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:689) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:83) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:938) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:870) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:961) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:863) @ javax.servlet.http.httpservlet.service(httpservlet.java:646) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:837) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1040) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:607) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:724)

a messagingexception thrown under both circumstances...

11:58:08.068 error [main][org.springframework.integration.ip.tcp.tcpoutboundgateway] tcp gateway exception org.springframework.integration.messagetimeoutexception: timed out waiting response

and

12:00:34.859 warn [main][org.springframework.integration.gateway.gatewayproxyfactorybean$methodinvocationgateway] failure occurred in gateway sendandreceive org.springframework.messaging.messagingexception: org.springframework.messaging.messagingexception: failed send or receive

you won't tcpconnectionexceptionevent in sec case - event exceptions on specific established connection. since didn't found connection, there's no connection study exception for.

in order determine actual exception, should traverse cause tree; like:

if (e.getcause() != null) { if (e.getcause().getcause() instanceof connectexception) { ... } }

you can alter gateway throw connectexception...

int send(foo adapter) throws connectexception;

...and framework automatically disclose you...

try { success = gateway.send(adaptor); } grab (messagingexception exc) { system.out.println("exception occurred : " + exc.getmessage()); } grab (connectexception e) { ... }

the messaging exception timeout (no response) messagetimeoutexception (subclass of messagingexception). errors occur while waiting reply, should get...

throw new messagingexception("exception while awaiting reply", (throwable) reply.getpayload());

java spring tcp exception-handling spring-integration

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -