OraMonREST.java 2.94 KB


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import se.lil.om.Registry;

/**
 * Servlet implementation class OraMonREST
 */
@WebServlet(description = "REST API for OraMon", urlPatterns = { "/OraMonREST" })
public class OraMonREST extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OraMonREST() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json");
		StringBuffer sb = new StringBuffer();
		if(request.getParameterMap().containsKey("connectionString")) {
			// We have a connection string, find the monitor or create it and call getData() on the monitor
			// Check that we have a valid connection string
			String[] conStrParamArray = request.getParameter("connectionString").split(":");
			if(conStrParamArray.length != 5) {
				// Error, we need 3 parts in the con string
				response.sendError(HttpServletResponse.SC_BAD_REQUEST, "connectionString needs to be in format host:port:sid:username:password");
				return;
			}
			String conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2];
			String userStr = conStrParamArray[3];
			String passStr = conStrParamArray[4];
			
		} else {
			// No input, just return the list of monitors
			sb.append("{\"count\":" + Registry.getList().size() + "}");
		}
		
		PrintWriter out = response.getWriter();
		out.println(sb.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPut(HttpServletRequest, HttpServletResponse)
	 */
	protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
	 */
	protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doHead(HttpServletRequest, HttpServletResponse)
	 */
	protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}