package com.lbslocal.api.view;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lbslocal.api.connect.ControlAddressFinder;
import com.lbslocal.api.connect.ControlMapRender;
import com.lbslocal.api.connect.ControlProximity;
import com.lbslocal.api.connect.ControlRoute;
import com.lbslocal.api.objects.TokenValidated;
import com.lbslocal.api.objects.Webservices;
import com.lbslocal.api.proxy.Proxy;
import com.lbslocal.api.utils.Common;
/**
* Servlet implementation class ApiSVC
*/
public class ApiSVC extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ApiSVC() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TokenValidated tokenValidated;
Proxy proxy;
String valor = "var exception = '%s';";
try {
// trata chamada
proxy = new Proxy(request);
// autentica usuário
tokenValidated = Common.ValidateUser(proxy);
// Qual serviço
if (proxy.TypeCall == Proxy.ServiceRequest) {
switch (proxy.GetWebservice()) {
case Webservices.AddressFinder:
valor = ControlAddressFinder.runService(proxy, tokenValidated);
break;
case Webservices.MapRender:
valor = ControlMapRender.runService(proxy, tokenValidated);
break;
case Webservices.Route:
valor = ControlRoute.runService(proxy, tokenValidated);
break;
case Webservices.Proximity:
valor = ControlProximity.runService(proxy, tokenValidated);
break;
}
valor = "AjaxCrossCall.remoteloader.callback('" + valor.replace('\'', '`') + "','" + proxy.GetCallback() + "')";
} else
valor = String.format(valor, "No Action");
} catch (Exception ex) {
valor = String.format(valor, ex.getMessage());
}
response.setHeader("Content-Encoding", "UTF-8");
response.setContentType("application/x-javascript");
response.getWriter().write(new String(valor.getBytes("UTF-8"), "ISO-8859-1"));
}
}