简体   繁体   中英

web service java ee 7

I am creating a Currency converter web service which works like a calculator. I have below code in my service class.

@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;
    }
}

When I call above webservice I am getting below error in log. What could be possible cause of this error ?

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 ..... 

You will most probably be getting a number format exception, you need to switch the ',' and '.' in your simbolo definitions.

btw, why do you need the decimal formating since you are returning a BigDecimal ? why not just return v1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM