[jboss-cvs] JBossAS SVN: r110519 - projects/jboss-jca/branches/performance/jmeter/src/main/java/org/jboss/jca/performance/servlet/http.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 2 15:24:27 EST 2011
Author: whitingjr
Date: 2011-02-02 15:24:27 -0500 (Wed, 02 Feb 2011)
New Revision: 110519
Added:
projects/jboss-jca/branches/performance/jmeter/src/main/java/org/jboss/jca/performance/servlet/http/HttpSelectServlet.java
Log:
Added servlet class.
Added: projects/jboss-jca/branches/performance/jmeter/src/main/java/org/jboss/jca/performance/servlet/http/HttpSelectServlet.java
===================================================================
--- projects/jboss-jca/branches/performance/jmeter/src/main/java/org/jboss/jca/performance/servlet/http/HttpSelectServlet.java (rev 0)
+++ projects/jboss-jca/branches/performance/jmeter/src/main/java/org/jboss/jca/performance/servlet/http/HttpSelectServlet.java 2011-02-02 20:24:27 UTC (rev 110519)
@@ -0,0 +1,149 @@
+package org.jboss.jca.performance.servlet.http;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+import javax.transaction.UserTransaction;
+
+public class HttpSelectServlet extends HttpServlet
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+ private static final String JNDI_NAME = "java:/SampleDS";
+ private static final String JNDI_USER_TRANSACTION = "java:/UserTransaction";
+ public static final String KEY_QUERY_RESULT_BEAN = "CONNECTION_BEAN";
+ public static final String VIEW = "/connection.jsp";
+ public static final String FAIL = "FAIL";
+ public static final String SUCCESS = "SUCCESS";
+ public static final String SELECT_STATEMENT = "SELECT 1;";
+ private Context context = null;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException
+ {
+ UserTransaction userTransaction = null;
+ DataSource dataSource = null;
+ Connection connection = null;
+ PreparedStatement selectPreparedStatement = null;
+ ResultSet resultSet = null;
+ String result = FAIL;
+ try
+ {
+ if (null != this.context)
+ {
+ userTransaction = (UserTransaction) context
+ .lookup(JNDI_USER_TRANSACTION);
+ userTransaction.begin();
+ dataSource = (DataSource) this.context.lookup(JNDI_NAME);
+ connection = dataSource.getConnection();
+ selectPreparedStatement = connection
+ .prepareStatement(SELECT_STATEMENT);
+ resultSet = selectPreparedStatement.executeQuery();
+ if (resultSet.next())
+ {
+ result = SUCCESS;
+ }
+ }
+ } catch (Exception e)
+ {
+ getServletContext().log(e.getMessage(), e);
+ } finally
+ {
+ try
+ {
+ if (null != resultSet)
+ resultSet.close();
+ } catch (Exception e)
+ {
+ }
+ try
+ {
+ if (null != selectPreparedStatement)
+ selectPreparedStatement.close();
+ } catch (Exception e)
+ {
+ }
+ try
+ {
+ if (null != connection)
+ connection.close();
+ } catch (Exception e)
+ {
+ }
+ try
+ {
+ if (null != userTransaction)
+ {
+ if (SUCCESS == result)
+ {
+ userTransaction.commit();
+ } else
+ {
+ userTransaction.rollback();
+ }
+ }
+ } catch (Exception e)
+ {
+ }
+ }
+ req.setAttribute(KEY_QUERY_RESULT_BEAN, result);
+ RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(
+ VIEW);
+ dispatcher.include(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ super.init();
+ try
+ {
+ this.context = new InitialContext();
+ } catch (Exception e)
+ {
+ log(e.getMessage());
+ }
+ }
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ init();
+ }
+
+ @Override
+ public void destroy()
+ {
+ try
+ {
+ if (null != this.context)
+ {
+ this.context.close();
+ }
+ } catch (Exception e)
+ {
+ log(e.getMessage());
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list