Commit fbec7745 by Pedro Rolon

se agregó api key

parent ba4ae0de
......@@ -6,6 +6,9 @@ jQuery(function($){
//url: 'http://192.168.67.126:8095/ApiGeolocalizacion/punto/81', //URL de Albaro
url: 'http://localhost:8080/Api-e004/punto/'+$("#idBaja").val(),
type: "DELETE",
headers:{
apiKey: "pqntslc"
},
//dataType:"json",
success: function(result, textStatus, jqXHR) {
//En result se guarda lo que retorna el servlet
......
......@@ -5,6 +5,9 @@ jQuery(function($){
$.ajax({
url: 'http://localhost:8080/Api-e004/punto/'+$("#idConsulta").val(),
type: 'GET',
headers:{
apiKey: "pqntslc"
},
success: function(result){
console.log(result);
},
......
......@@ -5,6 +5,9 @@ jQuery(function($){
$.ajax({
url:'http://localhost:8080/Api-e004/buscar_puntos',
type: 'GET',
headers:{
apiKey: "pqntslc"
},
data:{
"lat": $("#latitudConsulta").val(),
"lon": $('#longitudConsulta').val()
......
......@@ -8,6 +8,9 @@ jQuery(function($){
url: 'http://localhost:8080/Api-e004/guardar',
type: "POST",
//dataType:"json",
headers:{
apiKey: "pqntslc"
},
data:{
"lat": $("#latitudAlta").val(),//-25.2820464,
"lon": $("#longitudAlta").val(),//-57.6129376,
......
......@@ -23,12 +23,15 @@ import modelo.PuntoGeografico;
@WebServlet({ "/GeoApi", "/punto/*", "/guardar", "/buscar_puntos" })
public class GeoApi extends HttpServlet {
private static final long serialVersionUID = 1L;
//El valor del api key
private String apiKey = "pqntslc";
/**
* @see HttpServlet#HttpServlet()
*/
public GeoApi() {
super();
// TODO Auto-generated constructor stub
}
......@@ -36,6 +39,11 @@ public class GeoApi extends HttpServlet {
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Para la validacion del api key
if(!request.getHeader("apiKey").equals(this.apiKey))
response.sendError(401, "El api key es incorrecto");
String url = request.getRequestURI();
String[] partes = url.split("/");
......@@ -135,6 +143,10 @@ public class GeoApi extends HttpServlet {
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Para la validacion del api key
if(!request.getHeader("apiKey").equals(this.apiKey))
response.sendError(401, "El api key es incorrecto");
// TODO Auto-generated method stub
response.setContentType("application/json");
......@@ -170,6 +182,10 @@ public class GeoApi extends HttpServlet {
* @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
*/
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Para la validacion del api key
if(!request.getHeader("apiKey").equals(this.apiKey))
response.sendError(401, "El api key es incorrecto");
System.out.println("Ejecutando el delete");
//Extrae los parámetros del URL. ya que el url que llama a este servlet es
......
......@@ -4,21 +4,17 @@ package controlador;
* @author pedro rolón
*/
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
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 javax.sql.DataSource;
import modelo.PuntoGeografico;
......
package controlador;
import java.io.IOException;
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 modelo.PuntoGeografico;
import controlador.GeoConexion;
/**
* Servlet implementation class Prueba
*/
@WebServlet({ "/Prueba", "/prueba","/prueba/*" })
public class Prueba extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Prueba() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
GeoConexion con = new GeoConexion();
float latitud=-25.2820216f;
float longitud=-57.6130814f;
String nombre="Cancha de tenis Herminio Gimenez";
String url = request.getRequestURL().toString();
String method = request.getMethod();
//System.out.println(request.getPathInfo().toString());
System.out.println(method);
System.out.println(url);
//hola
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
# Consideraciones
* El API es un servlet llamado GeoApi, que utiliza la clase GeoConexion para interactuar con la base de datos.
* El proyecto posee interfaz gráfica, pero para ver lo que retorna es necesario abrir la consola del navegador por el momento.
* El api key es "pqntslc".
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment