Tuesday, August 19, 2014

JAX-WS EJB Endpoint

EJB3.0 specification has made writing web services much easier. You do not even need a web application to host the service. The web services can be hosted in EJB container in an easy way. To write the web service write a Stateless EJB and mark it as Web service

ProductPriceBean.java

@Stateless
@WebService
public class ProductPriceBean {

private Map productMap = new HashMap();
    
    {
        productMap.put("Java","500");
        productMap.put("C++","300");
    }

@WebMethod
public double getPrice(String symbol){
   String price = (String) productMap.get(symbol);
        if(price != null){
            return Double.parseDouble(price);
        }
   return -1;
}

Note that you donot have to write any interface like Local or Remote. Just write this, deploy it as a Jar in your EJB container and hit the ((WSDL)) at:

http://<hostName>/JAX_WS_EJB/ProductPriceBean?wsdl

More on Web services

No comments:

Post a Comment