com.seer.datacruncher.profiler.spring.ProfilerTreeController.java Source code

Java tutorial

Introduction

Here is the source code for com.seer.datacruncher.profiler.spring.ProfilerTreeController.java

Source

/*
 * Copyright (c) 2015  www.see-r.com
 * All rights reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.seer.datacruncher.profiler.spring;

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

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.codehaus.jackson.map.ObjectMapper;

import com.seer.datacruncher.profiler.bl.TableMetaDataBL;

public class ProfilerTreeController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try {

            response.setContentType("application/json");
            PrintWriter out = response.getWriter();
            ObjectMapper mapper = new ObjectMapper();
            TableMetaDataBL tmBL = new TableMetaDataBL();
            String json = mapper.writeValueAsString(tmBL.loadTree(request));
            out.println(json);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}