prevent JMS printing stacktraces in the log file - java

I have this Message-driven Bean implementation class in my project:
#MessageDriven(
name="Updater",
activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/delete_topic"),
#ActivationConfigProperty(propertyName = "providerAdapterJNDI", propertyValue="java:/MyJMSProvider"),
#ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue=""+Integer.MAX_VALUE),
#ActivationConfigProperty(propertyName = "reconnectInterval", propertyValue="15"),
#ActivationConfigProperty(propertyName = "user", propertyValue=JbossJaasAuthenticator.principal),
#ActivationConfigProperty(propertyName = "password", propertyValue=JbossJaasAuthenticator.credentials)
})
#Interceptors(MediaExchangeSpringBeanAutowiringInterceptor.class)
public class MyUpdater implements MessageListener {...}
When my server is not reachable (which happens quite frequently), I'm getting this in my log file:
org.jboss.resource.adapter.jms.inflow.JmsActivation Unable to reconnect org.jboss.resource.adapter.jms.inflow.JmsActivationSpec#28d79ac8(ra=org.jboss.resource.adapter.jms.JmsResourceAdapter#6eff0db7 destination=topic/delete_topic destinationType=javax.jms.Topic tx=true durable=false reconnect=15 provider=java:/MyJMSProvider user=myuser pass=<not shown> maxMessages=1 minSession=1 maxSession=15 keepAlive=60000 useDLQ=true DLQHandler=org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler DLQJndiName=queue/DLQ DLQUser=null DLQMaxResent=5)javax.naming.CommunicationException: Could not obtain connection to any of these urls: my.url.net:49227 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server my.url.net/10.0.9.60:49227 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server my.url.net/10.0.9.60:49227 [Root exception is java.net.NoRouteToHostException: No route to host]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.jboss.util.naming.Util.lookup(Util.java:222)
at org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler.setupDLQDestination(AbstractDLQHandler.java:106)
at org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler.setup(AbstractDLQHandler.java:82)
at org.jboss.resource.adapter.jms.inflow.dlq.JBossMQDLQHandler.setup(JBossMQDLQHandler.java:48)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setupDLQ(JmsActivation.java:413)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setup(JmsActivation.java:351)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.handleFailure(JmsActivation.java:292)
at org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler.onException(AbstractDLQHandler.java:94)
at org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener.handleConnectionException(ConsolidatedRemotingConnectionListener.java:113)
at org.jboss.remoting.ConnectionValidator$1.run(ConnectionValidator.java:633)
Caused by: javax.naming.CommunicationException: Failed to connect to server my.url.net/10.0.9.60:49227 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server my.url.net/10.0.9.60:49227 [Root exception is java.net.NoRouteToHostException: No route to host]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734)
... 13 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server my.url.net/10.0.9.60:49227 [Root exception is java.net.NoRouteToHostException: No route to host]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305)
... 14 more
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:97)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:82)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301)
... 14 more
I do use log4j. What do I need to do to only print out the first line of the exception, rather than the full stacktrace? Is there some JMS configuration that I need to tweak, or something that I can do in log4j?

Related

Non-managed pom.xml file found (Unable to import maven project in IntelliJ)

I could not import my maven project in IntelliJ. The project has pom.xml file, but the IntelliJ does not load it. Check the log below:
Caused by: java.lang.RuntimeException: Cannot reconnect
Caused by: java.rmi.RemoteException: Cannot start maven service; nested exception is:
java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Operation timed out (Connection timed out)
Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Operation timed out (Connection timed out)
Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
I kept just the block below in etc/hosts and that works:
127.0.0.1 localhost

Ehcache - Unable to get distributed caching working

I am trying to enable distributed caching on ehcache for one of my projects between 2 nodes but I am running into issues.
I am using ehcache core 2.6.11 in a Java Spring project
Here are relevant portions of my ehcache config on each of the servers
Node 1
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="
peerDiscovery=manual,
rmiUrls=//node2.mydomain.com:40002/myCache1|//node2.mydomain.com:40002/myCache2"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=40001"/>
Node 2
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="
peerDiscovery=manual,
rmiUrls=//node1.mydomain.com:40001/myCache1|//node1.mydomain.com:40001/myCache2"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=40002"/>
When I update my cache and expect it to be replicated - here are the errors I get on my nodes
Node 1
03.03.2016 06:44:50 DEBUG [net.sf.ehcache.distribution.RMICacheManagerPeerProvider.lookupRemoteCachePeer():126] Lookup URL //node2.mydomain.com:40002/myCache1
03.03.2016 06:44:50 WARN [net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue():325] Unable to send message to remote peer. Message was: Connection refused to host: <node 2 IP Address>; nested exception is:
java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: <node 2 IP Address>; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at net.sf.ehcache.distribution.RMICachePeer_Stub.send(Unknown Source)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue(RMIAsynchronousCacheReplicator.java:314)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain(RMIAsynchronousCacheReplicator.java:127)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$000(RMIAsynchronousCacheReplicator.java:58)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run(RMIAsynchronousCacheReplicator.java:389)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory.createSocket(ConfigurableRMIClientSocketFactory.java:70)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 8 more
Node 2
03.03.2016 06:44:50 DEBUG [net.sf.ehcache.distribution.RMICacheManagerPeerProvider.lookupRemoteCachePeer():126] Lookup URL //node1.mydomain.com:40001/myCache1
03.03.2016 06:44:50 WARN [net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue():325] Unable to send message to remote peer. Message was: Connection refused to host: <node 2 IP Address>; nested exception is:
java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: <node 2 IP Address>; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
at net.sf.ehcache.distribution.RMICachePeer_Stub.send(Unknown Source)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue(RMIAsynchronousCacheReplicator.java:314)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain(RMIAsynchronousCacheReplicator.java:127)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$000(RMIAsynchronousCacheReplicator.java:58)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run(RMIAsynchronousCacheReplicator.java:389)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory.createSocket(ConfigurableRMIClientSocketFactory.java:70)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 8 more
UPDATE
I have changed my configuration now to use Automatic Discovery instead of Manual.
I have 4 servers, 2 in Site A and 2 in Site B.
The replicated is now working as expected on Site A between both nodes but no replication is occuring on Site B or between Site A and Site B.
I used netcat and telnet between each node and the other nodes and all connections were accepted.
Here are the relevant sections of my ehcache config for the automatic discovery
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,
multicastGroupAddress=230.3.0.0,
multicastGroupPort=4700,
timeToLive=255"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=43000,
socketTimeoutMillis=20000"/>
Could anyone offer any insight into how the replication is not working on Site B or any ideas I could try?
Thanks
Please check the below steps to fix this issue
Add the host name in the Listener as below.
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost,port=40001"/>
Check the port 40002 is open for access, so that It can be accessed from node1. Means node2.mydomain.com:40002 should be accessible from node1. From console, you can use telnet program to check it. Similarly, check if node1 is accessible from node2. (I believe this is what causing the issue)
Optional: You don't need to have different ports in the two servers. It can have the same port number 40001.
I reverted back to the manual discovery approach as we received advice from a Networking specialist that using Multicast accross data centers opens up a whole world of pain.
Using the manual approach with Thanga's suggestions has worked

Failed to connect to RMI registry

I am running activemq-5.9 on Ubuntu 12.04 and it would be fair to say that I am new to active MQ.
I suspect that I am queueing records and not de-queueing them, so I am looking into using JMX to connect to my active MQ broker and see what's going on. Jconsole fails.
This is hard because most of the docs on how to do this is old, but I finally get down to running activemq list. When I do, it throws a rather lengthy stacktrace:
Connecting to JMX URL: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
ERROR: java.lang.RuntimeException: Failed to execute list task. Reason: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused]
...
Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
... 21 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 26 more
Is there still something I have configured wrong? I have no firewall rules. I can't think what else to look for.
There is no 'failure to retrieve RMI server stub' here. There is a failure to connect to the RMI registry. Either it isn't running at all or you're looking in the wrong host, or port.
Make sure your RMI registry is running. You can do this with rmiregistry in another terminal, providing it's in the same working directory.

Apache commons email always uses localhost for SMTP

Why is when I setHostName("mail.metaregistrar.com") and sending the mail to use the SMTP on localhost?
Java code:
SimpleEmail email = new SimpleEmail();
email.setHostName(host);
email.setStartTLSEnabled(true);
email.setSmtpPort(25);
email.setAuthenticator(new DefaultAuthenticator(username, password));
email.setFrom(from);
email.setSubject(subject);
email.setMsg(message);
for (String address : addresses) {
email.addTo(address);
}
email.send();
Exception stack trace:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.metaregistrar.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1401)
at org.apache.commons.mail.Email.send(Email.java:1428)
at com.metaregistrar.mailer.Mailer.mail(Mailer.java:66)
at com.metaregistrarv2.schedule.ExternalPollMessageIisseHandler.handleUpdateMessage(ExternalPollMessageIisseHandler.java:88)
at com.metaregistrarv2.schedule.ExternalPollMessageIisseHandler.handleExternalPollMessage(ExternalPollMessageIisseHandler.java:67)
at com.metaregistrarv2.schedule.PollTaskTimer.handleStoredMessages(PollTaskTimer.java:58)
at com.metaregistrarv2.schedule.PollTaskTimer.execute(PollTaskTimer.java:38)
at com.metaregistrarv2.schedule.EppPollerTimedTaskAdapter.execute(EppPollerTimedTaskAdapter.java:28)
at com.metaregistrar.scheduling.TimedTask.run(TimedTask.java:22)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
at com.metaregistrar.concurrent.PoolThread.run(PoolThread.java:26)
Caused by: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25 (java.net.ConnectException: Connection refused))
at javax.mail.Transport.send(Transport.java:163)
at javax.mail.Transport.send(Transport.java:48)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1391)
... 17 more
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25 (java.net.ConnectException: Connection refused)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:254)
at javax.mail.Service.connect(Service.java:85)
at javax.mail.Service.connect(Service.java:70)
at javax.mail.Transport.send(Transport.java:94)
... 19 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 24 more
I don't know if you got this figured out, but I was having the same problem. Here's what I found:
The email.send() calls Transport.send(), which was using the server's default settings for the outgoing socket binding for that SMTP port (I'm running JBoss EAP 6.2). It was configured to use localhost on port 25... so every time I tried to send mail, it was trying to send to localhost:25.
I changed settings for that socket binding and now everything works.

sending email programmatically using google smtp

Good day SO people!
I am trying to send an email through java code by using the gmail smtp server for quite some time now and I'm still unlucky to get success. I tried to execute the codes from this tutorial
and I am getting an exception. Below is the log trace:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at ph.net.poolbeta.emailer.EmailDriver.sendEmailSSL(EmailDriver.java:108)
at ph.net.poolbeta.emailer.EmailDriver.main(EmailDriver.java:27)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 8 more
I've googled the connection exception error and I've tried some suggestions namely:
ping smtp.gmail.com --> successful.
telnet smtp.gmail.com 'port' --> unsuccessful. I've tried 465 and 587
Is there something that still need to do regarding network? Please help me to resolve this issue. Thanks in advance.

Categories

Resources