Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Catch a root cause exception under a Java IO Exception

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
Prasanna krishnan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Police line, do not cross. Well, this tiny ad can go through:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic