dev@glassfish.java.net

Re: Resources declared in context.xml vs web.xml

From: Lance J. Andersen <Lance.Andersen_at_Sun.COM>
Date: Fri, 31 Oct 2008 13:43:33 -0400

Hi Amy,

Will do.

Thank you...

Amy Roh wrote:
> Hi Lance,
>
> Can you file an issue regarding context.xml warning with resource
> definition and assign to me? I'll take a look at it.
>
> Thanks,
> Amy
>
> Lance J. Andersen wrote:
>> Hi everyone,
>>
>> I have a question on whether the warning below is intentional:
>>
>> When I start prelude I get the following warning:
>>
>> WARNING: This web app [/C:/Netbeans/JPAWeb_V3/build/web/] has no
>> resource reference by the name of [jdbc/mysqlTestDB]
>>
>>
>> I have this resource defined in context.xml:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Context path="/JPAWeb_V3">
>> <Resource
>> name="jdbc/mysqlTestDB"
>> auth="Container"
>> type="javax.sql.DataSource"/>
>>
>> </Context>
>>
>>
>> The sun-web.xml contains:
>>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD
>> Application Server 9.0 Servlet 2.5//EN"
>> "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
>> <sun-web-app error-url="">
>> <context-root>/JPAWeb_V3</context-root>
>> <resource-ref>
>> <res-ref-name>jdbc/mysqlTestDB</res-ref-name>
>> <jndi-name>jdbc/mysqlTestDB</jndi-name>
>> </resource-ref>
>> <class-loader delegate="true"/>
>> <jsp-config>
>> <property name="classdebuginfo" value="true">
>> <description>Enable debug info compilation in the generated
>> servlet class</description>
>> </property>
>> <property name="mappedfile" value="true">
>> <description>Maintain a one-to-one correspondence between static
>> content and the generated servlet class' java code</description>
>> </property>
>> </jsp-config>
>> </sun-web-app>
>>
>>
>> There is no entry in web.xml for jdbc/mysqlTestDB and the app works
>> fine.
>>
>>
>> Now if I do not use the context.xml and instead add the entry to
>> web.xml I do not see the warning when I reboot (which makes sense):
>>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <web-app version="2.5" 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-app_2_5.xsd">
>> <servlet>
>> <servlet-name>ContactServlet</servlet-name>
>> <servlet-class>demo.servlet.ContactServlet</servlet-class>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>ContactServlet</servlet-name>
>> <url-pattern>/ContactServlet</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>ContactServlet</servlet-name>
>> <url-pattern>/displayContacts</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>ContactServlet</servlet-name>
>> <url-pattern>/addContact</url-pattern>
>> </servlet-mapping>
>> <session-config>
>> <session-timeout>
>> 30
>> </session-timeout>
>> </session-config>
>> <welcome-file-list>
>> <welcome-file>index.html</welcome-file>
>> </welcome-file-list>
>> <resource-ref>
>> <res-ref-name>jdbc/mysqlTestDB</res-ref-name>
>> <res-type>javax.sql.DataSource</res-type>
>> <res-auth>Container</res-auth>
>> <res-sharing-scope>Shareable</res-sharing-scope>
>> </resource-ref>
>> </web-app>
>>
>> I assume the warning is being generated because the context.xml is
>> not being taken into consideration?
>>
>> Also another interesting scenario is if i do not put the resource-ref
>> in sun-web.xml of
>> <resource-ref>
>> <res-ref-name>jdbc/mysqlTestDB</res-ref-name>
>> <jndi-name>jdbc/mysqlTestDB</jndi-name>
>> </resource-ref>
>>
>> I get the following error (which makes sense) using JSTL tag of
>>
>> <sql:query var="resultSet" dataSource="jdbc/mysqlTestDB" >
>> select * from contacts
>> </sql:query>
>>
>> javax.servlet.ServletException: javax.servlet.jsp.JspException:
>> Unable to get connection, DataSource invalid: "java.sql.SQLException:
>> No suitable driver found for jdbc/mysqlTestDB"
>>
>>
>> I am going to log an issue as the error can be clearer. However the
>> interesting part is that my app which uses Eclipselink has no issues
>> using the same JNDI resource:
>>
>> <persistence-unit name="JPAContactJNDIPU"
>> transaction-type="RESOURCE_LOCAL">
>> <non-jta-data-source>jdbc/mysqlTestDB</non-jta-data-source>
>> <class>demo.entity.Contact</class>
>> <properties>
>> <property name="eclipselink.logging.level" value="FINEST"/>
>> <property name="eclipselink.ddl-generation"
>> value="create-tables"/>
>> </properties>
>> </persistence-unit>
>>
>>
>> Regards
>> Lance
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>