445495 Improve Exception message when no jndi resource to bind for a name in web.xml

This commit is contained in:
Jan Bartel 2014-10-01 13:29:23 +10:00
parent 149ee01047
commit bc265953a5
3 changed files with 48 additions and 1 deletions

View File

@ -892,7 +892,7 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
if (defaultNE!=null)
defaultNE.bindToENC(name);
else
throw new IllegalStateException("Nothing to bind for name "+nameInEnvironment);
throw new IllegalStateException("Nothing to bind for name " + name);
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.plus.webapp;
import java.lang.reflect.InvocationTargetException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -50,6 +51,7 @@ public class PlusDescriptorProcessorTest
protected FragmentDescriptor fragDescriptor1;
protected FragmentDescriptor fragDescriptor2;
protected FragmentDescriptor fragDescriptor3;
protected FragmentDescriptor fragDescriptor4;
protected WebAppContext context;
/**
* @throws java.lang.Exception
@ -81,6 +83,9 @@ public class PlusDescriptorProcessorTest
URL frag3Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-3.xml");
fragDescriptor3 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag3Xml));
fragDescriptor3.parse();
URL frag4Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-4.xml");
fragDescriptor4 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag4Xml));
fragDescriptor4.parse();
}
@After
@ -94,6 +99,32 @@ public class PlusDescriptorProcessorTest
Thread.currentThread().setContextClassLoader(oldLoader);
}
@Test
public void testMissingResourceDeclaration()
throws Exception
{
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
try
{
PlusDescriptorProcessor pdp = new PlusDescriptorProcessor();
pdp.process(context, fragDescriptor4);
fail("Expected missing resource declaration");
}
catch (InvocationTargetException ex)
{
Throwable cause = ex.getCause();
assertNotNull(cause);
assertNotNull(cause.getMessage());
assertTrue(cause.getMessage().contains("jdbc/mymissingdatasource"));
}
finally
{
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
@Test
public void testWebXmlResourceDeclarations()
throws Exception

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
version="3.0">
<name>Fragment 4</name>
<resource-ref>
<res-ref-name>jdbc/mymissingdatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-fragment>