1 | /* |
---|
2 | * To change this license header, choose License Headers in Project Properties. |
---|
3 | * To change this template file, choose Tools | Templates |
---|
4 | * and open the template in the editor. |
---|
5 | */ |
---|
6 | package org.biohackathon.SPARQLBuilder.www; |
---|
7 | |
---|
8 | import java.io.*; |
---|
9 | import javax.servlet.ServletException; |
---|
10 | import javax.servlet.annotation.WebServlet; |
---|
11 | import javax.servlet.http.HttpServlet; |
---|
12 | import javax.servlet.http.HttpServletRequest; |
---|
13 | import javax.servlet.http.HttpServletResponse; |
---|
14 | import org.biohackathon.SPARQLBuilder.OWL.*; |
---|
15 | |
---|
16 | /** |
---|
17 | * |
---|
18 | * @author atsuko |
---|
19 | */ |
---|
20 | @WebServlet(name = "DSServlet", urlPatterns = {"/dslist"}) |
---|
21 | public class DSServlet extends HttpServlet { |
---|
22 | |
---|
23 | /** |
---|
24 | * Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
---|
25 | * methods. |
---|
26 | * |
---|
27 | * @param request servlet request |
---|
28 | * @param response servlet response |
---|
29 | * @throws ServletException if a servlet-specific error occurs |
---|
30 | * @throws IOException if an I/O error occurs |
---|
31 | */ |
---|
32 | protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
---|
33 | throws ServletException, IOException { |
---|
34 | response.setContentType("text/html;charset=UTF-8"); |
---|
35 | try (PrintWriter out = response.getWriter()) { |
---|
36 | /* TODO output your page here. You may use following sample code. */ |
---|
37 | out.println("<!DOCTYPE html>"); |
---|
38 | out.println("<html>"); |
---|
39 | out.println("<head>"); |
---|
40 | out.println("<title>Servlet DSServlet</title>"); |
---|
41 | out.println("</head>"); |
---|
42 | out.println("<body>"); |
---|
43 | out.println("<h1>Servlet DSServlet at " + request.getContextPath() + "</h1>"); |
---|
44 | out.println("</body>"); |
---|
45 | out.println("</html>"); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
---|
50 | /** |
---|
51 | * Handles the HTTP <code>GET</code> method. |
---|
52 | * |
---|
53 | * @param request servlet request |
---|
54 | * @param response servlet response |
---|
55 | * @throws ServletException if a servlet-specific error occurs |
---|
56 | * @throws IOException if an I/O error occurs |
---|
57 | */ |
---|
58 | @Override |
---|
59 | protected void doGet(HttpServletRequest request, HttpServletResponse response) |
---|
60 | throws ServletException, IOException { |
---|
61 | //processRequest(request, response); |
---|
62 | response.setContentType("application/json;charset=UTF-8"); |
---|
63 | response.setHeader("Access-Control-Allow-Origin", "*"); |
---|
64 | response.setHeader("Access-Control-Allow-Methods", "GET"); |
---|
65 | response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers")); |
---|
66 | response.setHeader("Access-Control-Max-Age", "-1"); |
---|
67 | PrintWriter out = response.getWriter(); |
---|
68 | |
---|
69 | out.print(getDSList()); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * Handles the HTTP <code>POST</code> method. |
---|
74 | * |
---|
75 | * @param request servlet request |
---|
76 | * @param response servlet response |
---|
77 | * @throws ServletException if a servlet-specific error occurs |
---|
78 | * @throws IOException if an I/O error occurs |
---|
79 | */ |
---|
80 | @Override |
---|
81 | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
---|
82 | throws ServletException, IOException { |
---|
83 | processRequest(request, response); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Returns a short description of the servlet. |
---|
88 | * |
---|
89 | * @return a String containing servlet description |
---|
90 | */ |
---|
91 | @Override |
---|
92 | public String getServletInfo() { |
---|
93 | return "Short description"; |
---|
94 | }// </editor-fold> |
---|
95 | |
---|
96 | private String getDSList(){ |
---|
97 | StringBuilder sb = new StringBuilder(); |
---|
98 | File dsf = new File("dstable.txt"); |
---|
99 | try{ |
---|
100 | BufferedReader br = new BufferedReader(new FileReader(dsf)); |
---|
101 | }catch(IOException e){ |
---|
102 | e.printStackTrace(); |
---|
103 | } |
---|
104 | |
---|
105 | return sb.toString(); |
---|
106 | } |
---|
107 | } |
---|