You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vargjohn <va...@gmail.com> on 2012/06/14 11:44:48 UTC
Need help in java.net.ConnectException: Connection refused
Hi All,
I have an application which has a camel server running and listening to
activemq server at port number 61616.
When the camel server is running, the activemq server should also be running
at the same time to listen to the messages.
When the activemq is not started i am getting the below exception.
"Could not connect to broker URL: tcp://localhost:61616. Reason:
java.net.ConnectException: Connection refused"
Instead of showing the above exception, i need to show a meaningful message
to the user something like please restart the activemq server, how do i
achieve this, Can anyone give me a solution for this exception.
Thanks & Regards,
John
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need help in java.net.ConnectException: Connection refused
Posted by vargjohn <va...@gmail.com>.
Hi Babak,
I wrote some code using Socket API and tried to connect to activemq within
the camel route and it worked but the onException() clause is not getting
called. but now i do not see the exception java.net.ConnectException:
Connection refused when my web application is started and the activemq is
down. Thank you very much for the solution.
But when i shutdown the activemq in the middle while my application is
running, i keep getting the java.net.ConnectException: Connection refused,
is there any method to rerun the camel route again or some other method.
Thanks & Regards,
John
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476p5714545.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need help in java.net.ConnectException: Connection refused
Posted by Babak Vahdat <ba...@swissonline.ch>.
Maybe this could be one possible way:
Using plain Java Socket API write a bean which only does try to connect on
localhost port 61616 inside your Camel route and rethrows the exception if
java.net.ConnectException with the message "Connection refused" is thrown so
that your onException clause get's kicked in.
Babak
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476p5714526.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need help in java.net.ConnectException: Connection refused
Posted by Babak Vahdat <ba...@swissonline.ch>.
Ah now I see the problem. The onException clause of yours will not help at
all as Camel does NOT see / get the java.net.ConnectException thrown here. I
don't see any possible way of achieving what you're looking for!
However in general there's a org.springframework.util.ErrorHandler which is
so to say the DMLC error handler/callback where you could provide your own
using:
JmsEndpoint.setErrorHandler()
Or:
JmsConfiguration.setErrorHandler()
Inside Java Code or Spring config but in this concrete case even using
ErrorHandler would not help. Following the code snippet from DMLC where the
exception is catched:
protected void refreshConnectionUntilSuccessful() {
while (isRunning()) {
try {
if (sharedConnectionEnabled()) {
refreshSharedConnection();
}
else {
Connection con = createConnection();
JmsUtils.closeConnection(con);
}
logger.info("Successfully refreshed JMS Connection");
break;
}
catch (Exception ex) {
StringBuilder msg = new StringBuilder();
msg.append("Could not refresh JMS Connection for destination '");
msg.append(getDestinationDescription()).append("' - retrying in ");
msg.append(this.recoveryInterval).append(" ms. Cause: ");
msg.append(ex instanceof JMSException ?
JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
if (logger.isDebugEnabled()) {
logger.warn(msg, ex);
}
else {
logger.warn(msg);
}
}
sleepInbetweenRecoveryAttempts();
}
}
That said maybe there're STILL a way of achieving what you need which others
in the forum could have in their mind, however I doubt that.
Babak
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476p5714525.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need help in java.net.ConnectException: Connection refused
Posted by vargjohn <va...@gmail.com>.
Hi Babak,
I am using below camel exception clause inside the camel route.
onException(java.net.ConnectException.class).to("bean:localRouteHelper?method=handleException").end()
but still i keep getting the below exception sent from camel server.
WARNING: Could not refresh JMS Connection for destination 'mediation-mq' -
retrying in 5000 ms. Cause: Could not connect to broker URL:
tcp://localhost:61616. Reason: java.net.ConnectException: Connection
refused.
Any other method to resolve this exception. Please help.
Thanks & Regards,
John Varghese
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476p5714524.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Need help in java.net.ConnectException: Connection refused
Posted by Willem Jiang <wi...@gmail.com>.
It looks like the exception is throw before it is ready to consume the
message. I doubt the ErrorHandler can do this work.
Maybe you should wrap the jms connector to catch this kind of error.
On 6/14/12 5:44 PM, vargjohn wrote:
> Hi All,
>
> I have an application which has a camel server running and listening to
> activemq server at port number 61616.
>
> When the camel server is running, the activemq server should also be running
> at the same time to listen to the messages.
>
> When the activemq is not started i am getting the below exception.
>
> "Could not connect to broker URL: tcp://localhost:61616. Reason:
> java.net.ConnectException: Connection refused"
>
> Instead of showing the above exception, i need to show a meaningful message
> to the user something like please restart the activemq server, how do i
> achieve this, Can anyone give me a solution for this exception.
>
> Thanks& Regards,
> John
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang
Re: Need help in java.net.ConnectException: Connection refused
Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi
Maybe this could help:
http://camel.apache.org/exception-clause.html#ExceptionClause-Handlingandsendingafixedresponsebacktotheclient
Babak
--
View this message in context: http://camel.465427.n5.nabble.com/Need-help-in-java-net-ConnectException-Connection-refused-tp5714476p5714490.html
Sent from the Camel - Users mailing list archive at Nabble.com.