Code listings for "Introduction to RESTful Web Services (Part 3)," Java Magazine, January/February 2012


Listing 1
package com.bonbhel.oracle.auctionApp.ws;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 * @author Max Bonbhel
 */
@WebService(serviceName = "AuctionAppSOAPws")
@Stateless()
public class AuctionAppSOAPws {
    /** This is a sample web service operation */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }
}


Listing 2
    /**
     * Web service operation
     */
    @WebMethod(operationName = "extrapolateAmountBid")
    public double extrapolateAmountBid
(@WebParam(name = "amountBid") double amountBid, 
        @WebParam(name = "factor") int factor) {
        double k = 0;
        if (factor == 0){
            k = amountBid;
        }
        else{
            k = amountBid * factor;
        }
        return k;
    }


Listing 3
private double extrapolateAmountBid
(double amountBid, int factor) {
com.bonbhel.oracle.auctionapp.ws.AuctionAppSOAPws 
port = service.getAuctionAppSOAPwsPort();
return port.extrapolateAmountBid(amountBid, factor);
}


Listing 4
   public String prepareView() {
        Double d = 0.00;
        current = (Bid) getItems().getRowData();
        try{
            d = extrapolateAmountBid( current.getAmount().intValue(), 100);
         } catch (Exception e) {
             d = 0.00;
         }
        current.setAmount(d);
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "View";
   }

Copyright 2012, Oracle Corporation