有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我在控制器(update_nameupdate_definition)中定义了以下两个Web服务。我正在测试这两个Web服务 然后在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_namewebservice的控制器总是出现以下错误:

{
  "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,然后构建了它,但没有任何帮助

webservice的控制器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;
 }

webservice的控制器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) 个答案