-/*\r
- * To change this template, choose Tools | Templates\r
- * and open the template in the editor.\r
- */\r
-package org.ufcspa.simdecs.comunicacao;\r
-\r
-import java.io.IOException;\r
-import java.io.PrintWriter;\r
-import javax.servlet.ServletException;\r
-import javax.servlet.http.HttpServlet;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-/**\r
- *\r
- * @author pbarros\r
- */\r
-public class MetodoSelecionaCaso extends HttpServlet {\r
-\r
- /**\r
- * Processes requests for both HTTP\r
- * <code>GET</code> and\r
- * <code>POST</code> methods.\r
- *\r
- * @param request servlet request\r
- * @param response servlet response\r
- * @throws ServletException if a servlet-specific error occurs\r
- * @throws IOException if an I/O error occurs\r
- */\r
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)\r
- throws ServletException, IOException {\r
- response.setContentType("text/html;charset=UTF-8");\r
- PrintWriter out = response.getWriter();\r
- //String file ;\r
-/*\r
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("simdecsPU");\r
- EntityManager em = emf.createEntityManager();\r
- \r
- URL url = null;\r
- URLConnection urlConn = null;\r
- BufferedInputStream buf = null;\r
- ArquivoCaso arquivo;\r
- Integer idCaso = Integer.valueOf(request.getParameter("idArquivoCaso"));\r
- \r
-// out.print(request.getParameter("idArquivoCaso"));\r
- try {\r
- \r
- arquivo = (ArquivoCaso) em.createQuery("select arq from ArquivoCaso as arq where arq.id ="+idCaso)\r
- //.setParameter("idC",idCaso)\r
- .getSingleResult();\r
-// out.println(arquivo.getEndArquivo());\r
- url = getServletContext().getResource(arquivo.getEndArquivo());\r
- //set response header\r
- response.setContentType("text/xml");\r
- urlConn = url.openConnection();\r
- //establish connection with URL presenting web.xml\r
- urlConn.connect();\r
- buf = new BufferedInputStream(urlConn.getInputStream());\r
- int readBytes = 0;\r
- while ((readBytes = buf.read()) != -1)\r
- out.write(readBytes);\r
- } catch (MalformedURLException mue) {\r
- throw new ServletException(mue.getMessage());\r
- } catch (IOException ioe) {\r
- throw new ServletException(ioe.getMessage());\r
- } finally { \r
- out.close();\r
- buf.close();\r
- }\r
-*/\r
- }\r
-\r
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">\r
- /**\r
- * Handles the HTTP\r
- * <code>GET</code> method.\r
- *\r
- * @param request servlet request\r
- * @param response servlet response\r
- * @throws ServletException if a servlet-specific error occurs\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Override\r
- protected void doGet(HttpServletRequest request, HttpServletResponse response)\r
- throws ServletException, IOException {\r
- processRequest(request, response);\r
- }\r
-\r
- /**\r
- * Handles the HTTP\r
- * <code>POST</code> method.\r
- *\r
- * @param request servlet request\r
- * @param response servlet response\r
- * @throws ServletException if a servlet-specific error occurs\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Override\r
- protected void doPost(HttpServletRequest request, HttpServletResponse response)\r
- throws ServletException, IOException {\r
- processRequest(request, response);\r
- }\r
-\r
- /**\r
- * Returns a short description of the servlet.\r
- *\r
- * @return a String containing servlet description\r
- */\r
- @Override\r
- public String getServletInfo() {\r
- return "Short description";\r
- }// </editor-fold>\r
-}\r
+/*
+ * 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
+ * <code>GET</code> and
+ * <code>POST</code> 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<Caso> it = em.createQuery("From Caso where usuario.id=:pIdUsuario")
+ .setParameter("pIdUsuario", pIdUsuario)
+ .getResultList()
+ .iterator();
+ while(it.hasNext()) {
+ Caso caso = it.next();
+ out.println(" <caso id=\"" + caso.getId() + "\" titulo=\"" + caso.getNome() + "\" resumo=\"" + caso.getResumo() + "\" />");
+ }
+
+ out.println( "<xml>" );
+ out.println( "</xml>" );
+ }
+
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
+ /**
+ * Handles the HTTP
+ * <code>GET</code> 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
+ * <code>POST</code> 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";
+ }// </editor-fold>
+}