package net.winstone.testApplication.servlets;

import java.io.IOException; 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

/**
 * Check DataSource
 * @author Jerome Guibert
 */
public class JndiDataSourceServlet extends HttpServlet {
    public static final String JNDI_DATASOURCE = "jdbc/myDatasource";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            InitialContext initialContext = new InitialContext();
            Context envCtx = (Context) initialContext.lookup("java:comp/env");
            DataSource dataSource = (DataSource) envCtx.lookup(JNDI_DATASOURCE);
            if (dataSource == null) {
                throw new ServletException("Datasource 'jdbc/myDatasource' should be found");
            }
        } catch (NamingException ex) {
            throw new ServletException(ex);
        }
    }
}

@@ -68,17 +68,16 @@
 ception;
- 
 %0Aimport 
@@ -396,16 +396,20 @@
 aSource%0A
+ * %0A
  * @auth
@@ -487,20 +487,87 @@
 rvlet %7B%0A
-    
+%0A%09private static final long serialVersionUID = -2418327420316254139L;%0A%09
 public s
@@ -625,20 +625,17 @@
 urce%22;%0A%0A
-    
+%09
 @Overrid
@@ -636,20 +636,17 @@
 verride%0A
-    
+%09
 protecte
@@ -751,34 +751,19 @@
 n %7B%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 Init
@@ -812,28 +812,19 @@
 text();%0A
-            
+%09%09%09
 Context 
@@ -882,28 +882,19 @@
 /env%22);%0A
-            
+%09%09%09
 DataSour
@@ -954,28 +954,19 @@
 OURCE);%0A
-            
+%09%09%09
 if (data
@@ -987,24 +987,12 @@
 ) %7B%0A
-                
+%09%09%09%09
 thro
@@ -1069,30 +1069,15 @@
 %22);%0A
-            %7D%0A        
+%09%09%09%7D%0A%09%09
 %7D ca
@@ -1107,20 +1107,11 @@
 ) %7B%0A
-            
+%09%09%09
 thro
@@ -1142,22 +1142,13 @@
 x);%0A
-        %7D%0A    
+%09%09%7D%0A%09
 %7D%0A%7D%0A

add sid