参数未到达服务器上的控制器但在本地eclipse设置中

时间:2017-12-01 16:31:08

标签: java eclipse web-services spring-4

我在控制器中定义了以下两个web服务(update_nameupdate_definition)。我正在测试这两个web服务  在我的本地eclipse设置上,然后在RHEL OS上部署它。当我使用以下URL时,两个web服务在本地eclipse设置上都能正常工作  用于本地测试

update_name

 http://localhost:8080/MyProject/update_name?id=1234&name=localNameTest
  http://localhost:8080/MyProject/update_definition?id=1234&definition=localdefinitionTest

我可以分别看到以上两个webservice调用的以下JSON响应:

 {
  "status" : "SUCCESS",
  "message" : "Updated Name!"
}

{
  "status" : "SUCCESS",
  "message" : "Updated Definition Name!"
}

但是,当我尝试在我的服务器上运行相同的两个Web服务时,由于某种原因,name参数未到达 update_name webservice的控制器,我最终得到以下错误:

{
  "status" : "ERROR",
  "message" : "Invalid Name Parameter"
}

我在日志中看到New Name值为空行logger.info("update__name ws params :ID " +id+" New Name:"+name);所在的位置 因为它显示在我的本地设置eclipse控制台日志

另一方面,在服务器上,webservice update_definition完全正常,因为它适用于本地eclipse设置,我也获得同样的成功 我进入当地的消息:

{
  "status" : "SUCCESS",
  "message" : "Updated Definition Name!"
}

有谁知道我可以做什么错?我无法弄清楚因为我的本地exlipse设置中的事情完全正常。 在服务器上,我甚至在项目上做了mvn clean,然后构建了它,但它没有帮助。

网络服务控制器update_name

    @RequestMapping(value = "/update_name", method = RequestMethod.GET)
    public String updateName
    (
     @RequestParam(value = "id", defaultValue = "0") Integer id,
     @RequestParam(value = "name", defaultValue = "") String name

    ) {

  String wsStatusJsonString = null;
  logger.info("-----------------------------------------------------------------------------------------------------------");
  logger.info("update__name ws params :ID " + id + " New  Name:" + name);
  boolean updateStatus = true;

  try {

   // Validate the input parameters.
   if (id < 1) {
    throw new Exception("Invalid ID parameter");
   }
   if (StringUtils.isNullOrEmpty(name)) {
    throw new Exception("Invalid  Name Parameter");
   }
   EmployeeDao employeeDao = (EmployeeDao) context.getBean("employeeDao");
   Company company = null;
   List < Company > companyList = employeeDao.findByEmployeeId(id);

   if ((companyList != null) && (!companyList.isEmpty())) {
    company = companyList.get(0);
    company.setName(name);
    updateStatus = employeeDao.insertOrUpdate(company);
    logger.info("update__name:" + updateStatus);
    if (updateStatus) {
     wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(true, "Updated  Name!", true);
    } else {
     wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(false, "Unable to update  Name!", true);
    }

   }

  } catch (Throwable th) {
   th.printStackTrace();
   wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(false, th.getMessage(), true);
  }

  return wsStatusJsonString;
 }

网络服务控制器update_definition

  @RequestMapping(value = "/update_definition", method = RequestMethod.GET)
  public String updateDefinition
  (
   @RequestParam(value = "id", defaultValue = "0") Integer id,
   @RequestParam(value = "definition", defaultValue = "") String definition

  ) {

   String wsStatusJsonString = null;
   logger.info("-----------------------------------------------------------------------------------------------------------");
   logger.info("update__definition ws params :ID " + id + " New  Name:" + definition);
   boolean updateStatus = true;
   try {
    // Validate the input parameters.
    if (id < 1) {
     throw new Exception("Invalid ID parameter");
    }
    if (StringUtils.isNullOrEmpty(definition)) {
     throw new Exception("Invalid  Definition Parameter");
    }
    EmployeeDao employeeDao = (EmployeeDao) context.getBean("employeeDao");
    Company company = null;
    List < Company > companyList = employeeDao.findByEmployeeId(id);

    if ((companyList != null) && (!companyList.isEmpty())) {
     company = companyList.get(0);
     company.setDefinition(definition);
     updateStatus = employeeDao.insertOrUpdate(company);
     logger.info("update__definition:" + updateStatus);
     if (updateStatus) {
      wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(true, "Updated Definition Name!", true);
     } else {
      wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(false, "Unable to update Definition Name!", true);
     }

    }

   } catch (Throwable th) {
    th.printStackTrace();
    wsStatusJsonString = GenericOrmStatusView.OrmStatusToJsonString(false, th.getMessage(), true);
   }

   return wsStatusJsonString;
  }

0 个答案:

没有答案