@ApiOperation("To fetch and display records")
  @RequestMapping("/display")
  public ModelAndView display(HttpServletRequest request, HttpServletResponse responses) {
    String table = request.getParameter("table");
    String name = request.getParameter("name");
    ModelAndView mav = new ModelAndView();
    String msg = null;
    try {
      Client client = Client.create();
      String names = URLEncoder.encode(name, "UTF-8").replace("+", "%20");
      WebResource webResource =
          client.resource("http://localhost:8080/EmpOrderRest/api/display/" + table + "/" + names);
      ClientResponse response = webResource.head();
      if (response.getStatus() == 200) {

        JSONObject json =
            readJsonFromUrl(
                "http://localhost:8080/EmpOrderRest/api/display/" + table + "/" + names);
        msg = json.toString();
      } else {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    mav.setViewName("welcome.jsp");
    mav.addObject("msg", msg);
    return mav;
  }
 @RequestMapping("/flyways")
 public ModelAndView fly(HttpServletRequest request, HttpServletResponse responses) {
   String msg = null;
   ModelAndView mav = new ModelAndView();
   try {
     Client client = Client.create();
     WebResource webResource = client.resource("http://localhost:8080/EmployeeOrderRest/api/fly");
     ClientResponse response = webResource.head();
     if (response.getStatus() == 200) {
       msg = "DB versioning done Successfully";
     } else {
       throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   mav.setViewName("welcome.jsp");
   mav.addObject("msg", msg);
   return mav;
 }
예제 #3
0
 @Test
 public void testSimpleGet() {
   System.out.println("::: testSimpleGet :::");
   WebResource resource = client.resource("http://localhost:20090/");
   Assert.assertEquals(204, resource.head().getStatus());
 }