I'm trying to make a rest call to my spring controller, it works when I put the URL in browser and able to see the JSON response. But, when I try the same by integrating into the Angular code, it doesn't throw any exception either in browser console or server console.
Here is my code.
Imports
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
class Result {
statusCode : number;
errorMsg: string;
result: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
ngOnInit() {
this.getEmployees();
}
public getEmployees(): Observable<Result[]> {
return this.http
.get(this.API_URL + '/employees')
.map(response => {
const todos = response.json();
console.log(todos);
return "";
})
.catch(this.handleError);
}
private handleError (error: Response | any) {
console.error('ApiService::handleError', error);
return Observable.throw(error);
}
And here is my spring code
@RequestMapping(value ="/employees", method = RequestMethod.GET)
public ResultDto getEmployees(HttpServletRequest req) {
ResultDto result = null;
try {
ServletContext ctx = req.getServletContext();
@SuppressWarnings("unchecked")
Map<String,String> users = (Map<String, String>) ctx.getAttribute("userRoles");
result = new ResultDto();
result.setStatusCode(EmapConstants.SUCCESS);
result.setResult(users);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
My ResultDto class is having three properties
private int statusCode;
private String errorMsg;
private Object result;
Any ideas why its not hitting the method?