root/SPARQLBuilderWWW2016/src/java/org/biohackathon/SPARQLBuilder/www/DSServlet.java @ 272

リビジョン 267, 3.6 KB (コミッタ: atsuko, 9 年 前)

メタデータ仕様変更,フェデレートサーチ対応向け

行番号 
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 */
6package org.biohackathon.SPARQLBuilder.www;
7
8import java.io.IOException;
9import java.io.PrintWriter;
10import javax.servlet.ServletException;
11import javax.servlet.annotation.WebServlet;
12import javax.servlet.http.HttpServlet;
13import javax.servlet.http.HttpServletRequest;
14import javax.servlet.http.HttpServletResponse;
15import org.biohackathon.SPARQLBuilder.OWL.*;
16
17/**
18 *
19 * @author atsuko
20 */
21@WebServlet(name = "DSServlet", urlPatterns = {"/dslist"})
22public class DSServlet extends HttpServlet {
23
24    /**
25     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
26     * methods.
27     *
28     * @param request servlet request
29     * @param response servlet response
30     * @throws ServletException if a servlet-specific error occurs
31     * @throws IOException if an I/O error occurs
32     */
33    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
34            throws ServletException, IOException {
35        response.setContentType("text/html;charset=UTF-8");
36        try (PrintWriter out = response.getWriter()) {
37            /* TODO output your page here. You may use following sample code. */
38            out.println("<!DOCTYPE html>");
39            out.println("<html>");
40            out.println("<head>");
41            out.println("<title>Servlet DSServlet</title>");           
42            out.println("</head>");
43            out.println("<body>");
44            out.println("<h1>Servlet DSServlet at " + request.getContextPath() + "</h1>");
45            out.println("</body>");
46            out.println("</html>");
47        }
48    }
49
50    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
51    /**
52     * Handles the HTTP <code>GET</code> method.
53     *
54     * @param request servlet request
55     * @param response servlet response
56     * @throws ServletException if a servlet-specific error occurs
57     * @throws IOException if an I/O error occurs
58     */
59    @Override
60    protected void doGet(HttpServletRequest request, HttpServletResponse response)
61            throws ServletException, IOException {
62        //processRequest(request, response);
63        response.setContentType("application/json;charset=UTF-8");
64        response.setHeader("Access-Control-Allow-Origin", "*");
65        response.setHeader("Access-Control-Allow-Methods", "GET");
66        response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
67        response.setHeader("Access-Control-Max-Age", "-1");       
68        PrintWriter out = response.getWriter();
69
70        out.print(getDSList());
71    }
72
73    /**
74     * Handles the HTTP <code>POST</code> method.
75     *
76     * @param request servlet request
77     * @param response servlet response
78     * @throws ServletException if a servlet-specific error occurs
79     * @throws IOException if an I/O error occurs
80     */
81    @Override
82    protected void doPost(HttpServletRequest request, HttpServletResponse response)
83            throws ServletException, IOException {
84        processRequest(request, response);
85    }
86
87    /**
88     * Returns a short description of the servlet.
89     *
90     * @return a String containing servlet description
91     */
92    @Override
93    public String getServletInfo() {
94        return "Short description";
95    }// </editor-fold>
96
97    private String getDSList(){
98        StringBuilder sb = new StringBuilder();
99       
100        return sb.toString();
101    }
102}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。