IBM Mobilefirst 7.0- Java 适配器无法在服务器端执行
IBM Mobilefirst 7.0- Java Adapter fails to execute on the server side
我在 MobileFirst Java 适配器上执行添加时得到以下信息
Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
@Path("/calc")
public class Calculator {
@Context
HttpServletRequest request;
//Define the server api to be able to perform server operations
WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
@GET
@Path("/addTwoIntegers/{first}/{second}")
public int addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
int a=Integer.parseInt(first);
int b=Integer.parseInt(second);
int c=a+b;
return c;
}
}
您的问题出在适配器的 return 类型上。因为你正在 returning 一个 int
它试图将它转换成一个 string
而那是它失败的时候因此 Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
尝试按如下方式更新您的代码:
@Path("/calc")
public class Calculator {
@Context
HttpServletRequest request;
//Define the server api to be able to perform server operations
WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
@GET
@Path("/addTwoIntegers/{first}/{second}")
public String addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
int a=Integer.parseInt(first);
int b=Integer.parseInt(second);
int c=a+b;
return Integer.toString(c);
}
}
我在 MobileFirst Java 适配器上执行添加时得到以下信息
Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
@Path("/calc")
public class Calculator {
@Context
HttpServletRequest request;
//Define the server api to be able to perform server operations
WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
@GET
@Path("/addTwoIntegers/{first}/{second}")
public int addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
int a=Integer.parseInt(first);
int b=Integer.parseInt(second);
int c=a+b;
return c;
}
}
您的问题出在适配器的 return 类型上。因为你正在 returning 一个 int
它试图将它转换成一个 string
而那是它失败的时候因此 Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
尝试按如下方式更新您的代码:
@Path("/calc")
public class Calculator {
@Context
HttpServletRequest request;
//Define the server api to be able to perform server operations
WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
@GET
@Path("/addTwoIntegers/{first}/{second}")
public String addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
int a=Integer.parseInt(first);
int b=Integer.parseInt(second);
int c=a+b;
return Integer.toString(c);
}
}