Package com.lbslocal.api.view

Source Code of com.lbslocal.api.view.Api

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.control.ControlAPI;
import com.lbslocal.api.objects.TokenValidated;
import com.lbslocal.api.proxy.Proxy;
import com.lbslocal.api.utils.Common;

/**
* Servlet implementation class Api
*/
public class Api extends HttpServlet {
  private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Api() {
        super();
    }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    TokenValidated tokenValidated = new TokenValidated();
    Proxy proxy;
    String valor = "var exception = '%s';";

        try
        {
            // levanta parametros para o Proxy
            proxy = new Proxy(request);

            tokenValidated = Common.ValidateUser(proxy);
            switch (proxy.TypeCall)
            {
                // É download de javascript
                case Proxy.JavaScriptRequest:
                    valor = ControlAPI.getLBSAPI(proxy, tokenValidated);
                    break;
                default:
                    valor = String.format(valor, "No Action");
                    break;
            }
           
        }catch (Exception ex) {
          valor = String.format(valor, ex.getMessage());
    }
       
        // força encoding
        response.setHeader("Content-Encoding", "UTF-8");
        // força content typ
        response.setContentType("application/x-javascript");
        response.getWriter().write(valor);

  }

}
TOP

Related Classes of com.lbslocal.api.view.Api

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.