我正在创建一个货币转换器web服务,其工作方式类似于计算器。我在我的服务类中有以下代码。
@WebService(serviceName = "CalculadoraWebService")
public class CalculadoraWebService {
/**
* Web service operation
*/
@WebMethod(operationName = "Calculadora")
public BigDecimal operation(@WebParam(name = "Corvesion") BigDecimal bolf) {
double bols;
String op;
op = String.valueOf(bolf);
bols = Double.parseDouble(op) / 1000;
long partent = (long) bols;
double partdec = bols - partent;
if (partent ==0 && partdec < 0.750){
partdec=0.500;
} else if (partent ==0 && partdec >0.750){
partdec=1;}
BigDecimal v1;
BigDecimal v2 = new BigDecimal(partdec);
BigDecimal v3 = new BigDecimal(partent);
v1 = v2.add(v3);
v1 = v1.setScale(3, RoundingMode.HALF_UP);
DecimalFormatSymbols simbolo=new DecimalFormatSymbols();
simbolo.setDecimalSeparator(',');
simbolo.setGroupingSeparator('.');
DecimalFormat formato = new DecimalFormat("###,###.##",simbolo);
BigDecimal resul = new BigDecimal(formato.format(v1));
return resul;
}
}当我调用上面的webservice时,我在日志中得到了下面的错误。此错误的可能原因是什么?
WS00041: Service invocation threw an exception with message : null; Refer to the server log for more details
Exceptions details : java.lang.reflect.InvocationTargetException
javax.servlet.ServletException: java.lang.reflect.InvocationTargetException at org.glassfish.webservices.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:342) at org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:106) at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:157) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at ..... 发布于 2018-06-16 07:15:30
你很可能会得到一个数字格式的异常,你需要交换',‘和'.’在你的简单定义中。
顺便说一句,既然你要返回一个BigDecimal,为什么你还需要十进制格式呢?为什么不直接返回v1。
https://stackoverflow.com/questions/50882575
复制相似问题