From f93c36f90650869f6d97c2c8bcb70f68ac636b37 Mon Sep 17 00:00:00 2001 From: maroni Date: Wed, 15 Feb 2012 10:32:49 -0200 Subject: [PATCH] --- src/conf/persistence.xml | 1 - .../simdecs/comunicacao/MetodoSelecionaCaso.java | 211 +++++++++----------- web/WEB-INF/web.xml | 8 + 3 files changed, 106 insertions(+), 114 deletions(-) diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index a3b17db..0f4e6b5 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -3,7 +3,6 @@ org.hibernate.ejb.HibernatePersistence jdbc/SimDeCS - org.ufcspa.simdecs.entities.ArquivoCaso org.ufcspa.simdecs.entities.Caso org.ufcspa.simdecs.entities.DependenciaNodo org.ufcspa.simdecs.entities.Log diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoSelecionaCaso.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoSelecionaCaso.java index caaa6b6..d6d02fa 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoSelecionaCaso.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoSelecionaCaso.java @@ -1,113 +1,98 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.ufcspa.simdecs.comunicacao; - -import java.io.IOException; -import java.io.PrintWriter; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * - * @author pbarros - */ -public class MetodoSelecionaCaso extends HttpServlet { - - /** - * Processes requests for both HTTP - * GET and - * POST methods. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - response.setContentType("text/html;charset=UTF-8"); - PrintWriter out = response.getWriter(); - //String file ; -/* - EntityManagerFactory emf = Persistence.createEntityManagerFactory("simdecsPU"); - EntityManager em = emf.createEntityManager(); - - URL url = null; - URLConnection urlConn = null; - BufferedInputStream buf = null; - ArquivoCaso arquivo; - Integer idCaso = Integer.valueOf(request.getParameter("idArquivoCaso")); - -// out.print(request.getParameter("idArquivoCaso")); - try { - - arquivo = (ArquivoCaso) em.createQuery("select arq from ArquivoCaso as arq where arq.id ="+idCaso) - //.setParameter("idC",idCaso) - .getSingleResult(); -// out.println(arquivo.getEndArquivo()); - url = getServletContext().getResource(arquivo.getEndArquivo()); - //set response header - response.setContentType("text/xml"); - urlConn = url.openConnection(); - //establish connection with URL presenting web.xml - urlConn.connect(); - buf = new BufferedInputStream(urlConn.getInputStream()); - int readBytes = 0; - while ((readBytes = buf.read()) != -1) - out.write(readBytes); - } catch (MalformedURLException mue) { - throw new ServletException(mue.getMessage()); - } catch (IOException ioe) { - throw new ServletException(ioe.getMessage()); - } finally { - out.close(); - buf.close(); - } -*/ - } - - // - /** - * Handles the HTTP - * GET method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Handles the HTTP - * POST method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ - @Override - public String getServletInfo() { - return "Short description"; - }// -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.comunicacao; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; +import javax.persistence.EntityManager; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.ufcspa.simdecs.entities.Caso; +import org.ufcspa.simdecs.util.DbUtil; + +/** + * + * @author maroni + */ +public class MetodoSelecionaCaso extends HttpServlet { + + /** + * Processes requests for both HTTP + * GET and + * POST methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + response.setContentType( "text/xml" ); + response.setHeader( "Cache-Control", "no-cache" ); + + EntityManager em = DbUtil.getInstance().getEntityManager(); + long pIdUsuario = Long.parseLong(request.getParameter("idusuario")); + + Iterator it = em.createQuery("From Caso where usuario.id=:pIdUsuario") + .setParameter("pIdUsuario", pIdUsuario) + .getResultList() + .iterator(); + while(it.hasNext()) { + Caso caso = it.next(); + out.println(" "); + } + + out.println( "" ); + out.println( "" ); + } + + // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 27f5175..e7beb95 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -13,6 +13,10 @@ MetodoAutenticacao org.ufcspa.simdecs.comunicacao.MetodoAutenticacao + + MetodoSelecionaCaso + org.ufcspa.simdecs.comunicacao.MetodoSelecionaCaso + Faces Servlet *.jsf @@ -21,6 +25,10 @@ MetodoAutenticacao /MetodoAutenticacao + + MetodoSelecionaCaso + /MetodoSelecionaCaso + 30 -- 1.7.6.4