Get a listing given an identifier in agularjs with api rest

0

Good evening I am developing an application with angularjs using rest services and perform a method to obtain a list of visits from a specific person for which I pass the ID number And I should return the list but it does not do so where is the error or what could I do to solve this? Thanks. I attach the code REST SERVICE

@RequestMapping(value = "/Visita/{chv_cedula}", method = RequestMethod.GET, produces = "application/json")
public void findVisitas(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @PathVariable("chv_cedula") String chv_cedula) {
            try {
                List<Evisitas> visitas = visitasDAO.findVisitas(chv_cedula);
                String jsonSalida = jsonTransformer.toJson(visitas);


            httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            httpServletResponse.setContentType("application/json; charset=UTF-8");
            httpServletResponse.getWriter().println(jsonSalida);

        } catch (BussinessException ex) {
            List<BussinessMessage> bussinessMessage = ex.getBussinessMessages();
            String jsonSalida = jsonTransformer.toJson(bussinessMessage);

            httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            httpServletResponse.setContentType("application/json; charset=UTF-8");
            try {
                httpServletResponse.getWriter().println(jsonSalida);
            } catch (IOException ex1) {
                Logger.getLogger(VisitaController.class.getName()).log(Level.SEVERE, null, ex1);
            }

        } catch (Exception ex) {
            httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        }}

SERVICE CONSUMPTION FROM ANGULARJS

var app = angular.module("app", ['ngRoute', 'satellizer', 'map']);
function RemoteResource($http, $q, baseUrl) {
this.listvisitam = function (chv_cedula) {
        var defered = $q.defer();
        var promise = defered.promise;

        $http({
            method: 'GET',
            url: baseUrl + '/api/Visita/' + chv_cedula 
        }).success(function (data, status, headers, config) {
            defered.resolve(data);
        }).error(function (data, status, headers, config) {
            if (status === 400) {
                defered.reject(data);
            } else {
                throw new Error("Fallo obtener los datos:" + status + "\n" + data);
            }
        });

        return promise;

    };
}

ROUTEPROVIDER

$routeProvider.when('/visitas/miembro', {
            templateUrl: "vistas/lstvisitasm.html",
            controller: "VisitasMiembroController",
            resolve: {
                vmiembro: ['remoteResource', 'sesionesControl', function (remoteResource, sesionesControl) {
                        var chv_cedula = sesionesControl.get("chv_cedula");
                         return remoteResource.listvisitam(chv_cedula);
                    }]
            }
        });

CONTROLER

app.controller("VisitasMiembroController", function ($scope, vmiembro) {
    $scope.vmiembro = vmiembro;

});
    
asked by Angela Samaniego 10.08.2017 в 04:57
source

1 answer

2

Thanks I found the problem for which the list was not loaded, it was because there is a method with the same name and as it was confused and it was not called as it should be just combine the path of the resource Rest and it worked .

@RequestMapping(value = "/Vmiembro/{chv_cedula}", method = RequestMethod.GET, produces = "application/json")
public void findVisitas(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @PathVariable("chv_cedula") String chv_cedula) {
    try {
        List<Evisitas> lstvisita = visitasDAO.findVisitas(chv_cedula);
        String jsonSalida = jsonTransformer.toJson(lstvisita);
        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);
    } catch (BussinessException ex) {
        List<BussinessMessage> bussinessMessage = ex.getBussinessMessages();
        String jsonSalida = jsonTransformer.toJson(bussinessMessage);

        httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        try {
            httpServletResponse.getWriter().println(jsonSalida);
        } catch (IOException ex1) {
            Logger.getLogger(VisitaController.class.getName()).log(Level.SEVERE, null, ex1);
        }

    } catch (Exception ex) {
        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    }

}
    
answered by 12.08.2017 в 22:06