forked from bolollo/geocoder_catastro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcercaXYCadastre.jsp
52 lines (48 loc) · 1.8 KB
/
cercaXYCadastre.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="org.apache.commons.httpclient.*" %>
<%@ page import="org.apache.commons.httpclient.methods.*" %>
<%@ page import="net.sf.json.xml.XMLSerializer" %>
<%@ page import="net.sf.json.JSON" %>
<%@ page import="net.sf.json.JSONArray" %>
<%
response.setContentType("application/json");
HttpClient httpclient = new HttpClient();
String SERVIDOR_CATASTRO = "http://ovc.catastro.meh.es/ovcservweb/OVCSWLocalizacionRC/";
String SERVIDOR_CALLEJERO = SERVIDOR_CATASTRO+"OVCCoordenadas.asmx/";
String RUTA_CATASTRO_CPMRC = SERVIDOR_CALLEJERO+"Consulta_CPMRC?";
String jsonp = request.getParameter("jsonp");
String resp = "";
String rc = request.getParameter("rc");
String srs = request.getParameter("epsg");
String peticio = RUTA_CATASTRO_CPMRC+"RC="+rc+"&SRS="+srs+"&Provincia=&Municipio=&";
System.out.println(peticio);
GetMethod httpget = new GetMethod(peticio);
try {
String respuesta = "";
httpclient.executeMethod(httpget);
String status=httpget.getStatusLine().toString();
if(status.indexOf("OK") != -1){
respuesta = httpget.getResponseBodyAsString();
}else{
out.write("{\"ERROR\":\"No es pot obtenir el llistat de vies\"}");
}
//respuesta = respuesta.replaceAll("'","@");
JSON jsonResponse = new JSONArray();
XMLSerializer xmlS= new XMLSerializer();
xmlS.setSkipNamespaces(true);
jsonResponse = xmlS.read(respuesta);
resp = jsonResponse.toString();
if (jsonp != null){
resp = jsonp + "(" + resp + ")";
}
out.println(resp);
}catch(Exception e){
e.printStackTrace();
}finally {
httpget.releaseConnection();
}
%>