I have deployed the spring boot application in a vm in tomcat server. When I load the page, I get to see only the static part, none of the uri mapping to the ajax functions in the controller seem to work here. But the same works fine in my local application. Can anyone please help. I am attching the code of my rest controller class below.
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.abc.xyz.util.DLCUtils;
import java.util.Date;
import java.util.List;
@RestController
public class HomeController {
@RequestMapping("/home")
public ModelAndView home(Model model) {
int lastWeekInMonth = 0;
lastWeekInMonth = DLCUtils.getLastWeekInMonth(2, 2016);
System.out.println("last week"+lastWeekInMonth);
model.addAttribute("lastweek", lastWeekInMonth);
ModelAndView mav = new ModelAndView("/index");
return mav;
}
@RequestMapping("/review")
public ModelAndView reviewHours(Model model) {
ModelAndView mav = new ModelAndView("/review");
return mav;
}
@RequestMapping("/manage")
public ModelAndView manageHours(Model model) {
ModelAndView mav = new ModelAndView("/manage");
return mav;
}
@RequestMapping("/addnewemployee")
public ModelAndView addnewemployee(Model model) {
ModelAndView mav = new ModelAndView("/addemployee");
return mav;
}
@RequestMapping("/populateWeek")
@ResponseBody
public Integer lastweekMethod() {
int lastWeekInMonth = 0;
lastWeekInMonth = DLCUtils.getLastWeekInMonth(2, 2016);
System.out.println("last week in lastweek"+lastWeekInMonth);
return lastWeekInMonth;
}
@RequestMapping("/getCurrentWeek")
@ResponseBody
public Integer getCurrentweek() {
int weekOfMonth = 0;
weekOfMonth = DLCUtils.getWeekOfTheMonth();
//System.out.println("last week in lastweek"+lastWeekInMonth);
return weekOfMonth;
}
@RequestMapping(value="/getCurrentMonth",method=RequestMethod.GET)
@ResponseBody
public int getCurrentMonth(@RequestParam("monthname") String month) {
int monthnumber = 0;
monthnumber = DLCUtils.getMonthNumber(month.toUpperCase());
//System.out.println("last week in lastweek"+lastWeekInMonth);
return monthnumber;
}
@RequestMapping(value="/getRangeOfDate",method=RequestMethod.GET)
@ResponseBody
public String getRangeOfDate(@RequestParam("week") int week,@RequestParam("month") int month,@RequestParam("year") int year) {
System.out.println("week val"+week);
List<Date> dateRange=null;
StringBuilder submitList = new StringBuilder("");
Date fd=null,ld=null;
dateRange = DLCUtils.getAllDays(week, month, year);
for (int i = 0; i < dateRange.size(); i++) {
if (i == 0) {
fd = dateRange.get(0);
}
if (i == dateRange.size() - 1) {
ld = dateRange.get(i);
}
}
String firstdate = null;
String lastdate = null;
int fdate = 0;
int ldate = 0;
firstdate = fd.toString();
lastdate = ld.toString();
String firstdate1 = firstdate.substring(8, 10);
String lastdate1 = lastdate.substring(8, 10);
fdate = Integer.parseInt(firstdate1);
ldate = Integer.parseInt(lastdate1);
String monthName=DLCUtils.getMonthName(month);
submitList.append(monthName);submitList.append("+");submitList.append(fdate);submitList.append("+");submitList.append(ldate);submitList.append("+");submitList.append(DLCUtils.getCurrentYear());
return submitList.toString();
}
@RequestMapping(value="/getLastDate",method=RequestMethod.GET)
@ResponseBody
public String getLastDate(@RequestParam("month") int month,@RequestParam("year") int year){
return (DLCUtils.getEndDateOfTheMonth(month, year).toString());
}
@RequestMapping(value="/getAlldaysInweek",method=RequestMethod.GET)
@ResponseBody
public String getListDatesInAWeek(@RequestParam("week") int week,@RequestParam("month") int month,@RequestParam("year") int year){
List<Date> lstDates = null;
lstDates = DLCUtils.getAllDays(week, month, year);
String dayOfWeek=null;
StringBuilder submitList = new StringBuilder("");
String formattedDate = null;
String pattern = "yyyy/MM/dd";
for (Date date : lstDates) {
formattedDate = DLCUtils.getDateInPattern(date, pattern);
dayOfWeek=DLCUtils.getDayOfTheWeek(date);
submitList.append(dayOfWeek);submitList.append(",");submitList.append(formattedDate);submitList.append("+");
}
return submitList.toString();
}
@RequestMapping(value="/populatedetails",method=RequestMethod.GET)
@ResponseBody
public String populatedetails(@RequestParam("name") String name,@RequestParam("Id") String id,@RequestParam("Email") String email){
StringBuilder submitList = new StringBuilder("");
String place="Bangalore";String joiningdate="2014-01-01";String enddate="9999-12-31";String rights="Employee";String status="Active";String dept="EBU";String manager="David";
submitList.append("Name"+"+"+name+","+"GlobalId"+"+"+id+","+"Email"+"+"+email+","+"Location"+"+"+place+","+"Joining Date"+"+"+joiningdate+","+"Resignation Date"+"+"+enddate+","+"Rights"+"+"+rights+",");
submitList.append("Status"+"+"+status+","+"Division"+"+"+dept+","+"Manager"+"+"+manager+","+"Projects"+"+");
submitList.append("SPT"+".");submitList.append("SPM"+".");submitList.append("DLC"+".");submitList.append("TEST1"+".");submitList.append("TEST2"+".");submitList.append("TEST3"+".");
return submitList.toString();
}
}
out of this, only those that returns model and view woorks and all other mappings to functions called from angular js ajax calls are not invoked, it shows in the console that
angular.js:8611 GET http://172.16.77.83:8083/getCurrentWeek 404 (Not Found)
Similarly for other calls as well. Because of which, the data in my html pages are not populated properly. The same application works fine in my local machine. Only in this external vm, it shows this problem.
Adding the ajax call code of the js file.
function getCurrentWeek(){
console.log("in ajax");
$http({
method : "GET",
url : "/getCurrentWeek"
}).then(function mySucces(response) {
$scope.currentWeek=response.data;
var j=parseInt($scope.currentWeek)-1;
$('table.ui-datepicker-calendar tr:eq('+$scope.currentWeek+')').css({"border":"3px solid #e1e1e1"});
var weekVal=$('#weekvalues a')[j];
weekVal.style.border="3px solid #50a8e5";
weekVal.style.paddingRight="2px";
weekVal.style.paddingLeft="2px";
weekVal.style.paddingTop="1px";
}, function myError(response) {
//$scope.dateRange = response.statusText;
});
}
Thanks, Poorna.