aspose file tools
The moose likes Java in General and the fly likes Catch a root cause exception under a Java IO Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Catch a root cause exception under a Java IO Exception" Watch "Catch a root cause exception under a Java IO Exception" New topic
Author

Catch a root cause exception under a Java IO Exception

Prasanna krishnan
Greenhorn

Joined: Oct 05, 2009
Posts: 5
Hi All,

I have some java code which initialises a MBean server connection. This code is called by a ant task. The ant task uses parameters like host name, username and password. On executing the ant task with the parameters, I get an exception as shown below:

/**
* This is the standard ant entry point for task
* execution.
* @throws BuildException
*/
public void execute() throws BuildException
{

try
{
checkRequiredParameters();
if (mSetAntClassLoader)
{
mTaskClassLoader =
(AntClassLoader)this.getClass().getClassLoader();
mTaskClassLoader.setThreadContextLoader();
}
initConnection(mHostname, mPortString, mUsername, mPassword);

//verify MDSDOmainRuntimeMBean is registered.
boolean registered =
mConnection.isRegistered(getMDSDomainRuntimeMBeanObjectName());


if (registered)
{
log("MDSDomainRuntimeMBean registered.", Project.MSG_INFO);
validatePartition();
}
else
{
throw new BuildException("MDSDomainRuntimeMBean is not registered. MDS infrastructure is not available.");

}

if (isAttributeSet(mApplication) && isAttributeSet(mServer))
{
//verify MDSAppRuntimeMBean is registered.
boolean appRegistered =
mConnection.isRegistered(getAppRuntimeMBeanName());
if (!appRegistered)
{
throw new BuildException("MDSAppRuntimeMBean is not registered. MDS may not be available for application " +
mApplication + " on server " +
mServer);
}
else
{
log("MDSAppRuntimeMBean registered.", Project.MSG_INFO);
validateMetadataLabel();
}
}
if (mSetAntClassLoader && mTaskClassLoader != null)
{
mTaskClassLoader.resetThreadContextLoader();
}

System.out.println("MDS validated successfully.");
}
catch (BuildException be)
{
throw be;
}
catch (Exception e)
{
e.printStackTrace();
throw new BuildException(e);
}
finally
{
if (mConnector != null)
{
try
{
mConnector.close();
}
catch (Exception e)
{
throw new BuildException(e);
}
}
}
}


EXCEPTION
------------------

validateMDSwithInvalidHost:
[ValidateMDS] java.io.IOException
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:187)
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:81)
[ValidateMDS] at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:338)
[ValidateMDS] at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
[ValidateMDS] at oracle.apps.fnd.provisioning.ant.taskdefs.validation.ValidateMDS.initConnection(ValidateMDS.java:352)
[ValidateMDS] at oracle.apps.fnd.provisioning.ant.taskdefs.validation.ValidateMDS.execute(ValidateMDS.java:207)
[ValidateMDS] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[ValidateMDS] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
[ValidateMDS] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ValidateMDS] at java.lang.reflect.Method.invoke(Method.java:597)
[ValidateMDS] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[ValidateMDS] at org.apache.tools.ant.Task.perform(Task.java:348)
[ValidateMDS] at org.apache.tools.ant.Target.execute(Target.java:357)
[ValidateMDS] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[ValidateMDS] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[ValidateMDS] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[ValidateMDS] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[ValidateMDS] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[ValidateMDS] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[ValidateMDS] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[ValidateMDS] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[ValidateMDS] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[ValidateMDS] Caused by: javax.naming.ServiceUnavailableException [Root exception is java.net.UnknownHostException: stpcy05]
[ValidateMDS] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:34)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:783)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:365)
[ValidateMDS] at weblogic.jndi.Environment.getContext(Environment.java:315)
[ValidateMDS] at weblogic.jndi.Environment.getContext(Environment.java:285)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
[ValidateMDS] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
[ValidateMDS] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
[ValidateMDS] at javax.naming.InitialContext.init(InitialContext.java:223)
[ValidateMDS] at javax.naming.InitialContext.<init>(InitialContext.java:197)
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:169)
[ValidateMDS] ... 21 more
[ValidateMDS] Caused by: java.net.UnknownHostException: stpcy05
[ValidateMDS] at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
[ValidateMDS] at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
[ValidateMDS] at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
[ValidateMDS] at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
[ValidateMDS] at java.net.InetAddress.getAllByName(InetAddress.java:1083)
[ValidateMDS] at java.net.InetAddress.getAllByName(InetAddress.java:1019)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.getDnsEntries(RJVMFinder.java:422)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:192)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:170)
[ValidateMDS] at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:153)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate$1.run(WLInitialContextFactoryDelegate.java:344)
[ValidateMDS] at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
[ValidateMDS] at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:339)
[ValidateMDS] ... 29 more




My question is: how can we catch the UnknownHostException here?
Please let me know.
Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Prasanna krishnan
Greenhorn

Joined: Oct 05, 2009
Posts: 5
Prasanna krishnan wrote:Hi All,

I have some java code which initialises a MBean server connection. This code is called by a ant task. The ant task uses parameters like host name, username and password. On executing the ant task with the parameters, I get an exception as shown below:




EXCEPTION
------------------

validateMDSwithInvalidHost:
[ValidateMDS] java.io.IOException
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:187)
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:81)
[ValidateMDS] at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:338)
[ValidateMDS] at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
[ValidateMDS] at oracle.apps.fnd.provisioning.ant.taskdefs.validation.ValidateMDS.initConnection(ValidateMDS.java:352)
[ValidateMDS] at oracle.apps.fnd.provisioning.ant.taskdefs.validation.ValidateMDS.execute(ValidateMDS.java:207)
[ValidateMDS] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[ValidateMDS] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
[ValidateMDS] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ValidateMDS] at java.lang.reflect.Method.invoke(Method.java:597)
[ValidateMDS] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[ValidateMDS] at org.apache.tools.ant.Task.perform(Task.java:348)
[ValidateMDS] at org.apache.tools.ant.Target.execute(Target.java:357)
[ValidateMDS] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[ValidateMDS] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[ValidateMDS] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[ValidateMDS] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[ValidateMDS] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[ValidateMDS] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[ValidateMDS] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[ValidateMDS] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[ValidateMDS] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[ValidateMDS] Caused by: javax.naming.ServiceUnavailableException [Root exception is java.net.UnknownHostException: stpcy05]
[ValidateMDS] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:34)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:783)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:365)
[ValidateMDS] at weblogic.jndi.Environment.getContext(Environment.java:315)
[ValidateMDS] at weblogic.jndi.Environment.getContext(Environment.java:285)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
[ValidateMDS] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
[ValidateMDS] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
[ValidateMDS] at javax.naming.InitialContext.init(InitialContext.java:223)
[ValidateMDS] at javax.naming.InitialContext.<init>(InitialContext.java:197)
[ValidateMDS] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:169)
[ValidateMDS] ... 21 more
[ValidateMDS] Caused by: java.net.UnknownHostException: stpcy05
[ValidateMDS] at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
[ValidateMDS] at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
[ValidateMDS] at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
[ValidateMDS] at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
[ValidateMDS] at java.net.InetAddress.getAllByName(InetAddress.java:1083)
[ValidateMDS] at java.net.InetAddress.getAllByName(InetAddress.java:1019)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.getDnsEntries(RJVMFinder.java:422)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:192)
[ValidateMDS] at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:170)
[ValidateMDS] at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:153)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate$1.run(WLInitialContextFactoryDelegate.java:344)
[ValidateMDS] at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
[ValidateMDS] at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
[ValidateMDS] at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:339)
[ValidateMDS] ... 29 more




My question is: how can we catch the UnknownHostException here?
Please let me know.
Thanks


Does that help? BTW, How do I use getRootCause() method? Is there an example?

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

Does that help?


To be blunt... no.

The purpose of code tags, is so that formatting would be preserved. With formatting, it would (much) easier to read and understand the source. You have absolutely no formatting in your code whatsoever. I am assuming that you don't actually write code like this, because it's very difficult to read, much less be able to understand and modify it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

As for "can we catch the UnknownHostException", you can catch that exception in any code that you write. But I don't think there's any such code in the stack trace you posted, is there? In which case your best bet is to just fix the configuration entries which cause this expression to be thrown.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

BTW, How do I use getRootCause() method? Is there an example?


Basically, when an exception is created, one of the options is to define an exception that is the cause of that exception. So, for example, you have a method that returns IO Exceptions, but the trigger of the IO Exception was another exception; in which case, you create and throw an IO exception, but set as the cause the exception that you caught while doing your processing.

It's not complicated, it is just a piece of data attached to the exception -- except that this piece of data is another exception.

Henry
Adam Michalik
Ranch Hand

Joined: Feb 18, 2008
Posts: 128
First, as far as I know the class Exception does not have the method getRootCause(), only getCause(). So what you would need is catch the IOException (or Exception) and iterate down the exception chain using getCause() until you find an exception of class UnknownHostException. To facilitate this you may wish to use ExceptionUtils from Apache Commons Lang - it has a getRootCause method and indexOfThrowable/indexOfType methods that let you specify the Exception class you are looking for.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Catch a root cause exception under a Java IO Exception
 
Similar Threads
Problem running ant script chapter 1 of ejb 3 in action with weblogic 10
java.rmi.ConnectException when updating the application
EJB 3.0 - NoInitialContextException
How to catch root exception thrown by domain runtime MBean Server in Weblogic
EJB creation failed