Loading
ASYNC web service example with JAX WS

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  ASYNC Web Service example with JAX-WS


Ans)

@WebService(name="StockQuote", serviceName="StockQuoteService")
public class StockQuoteImpl {
        @WebMethod(operationName="getQuote")
       public double getQuote(String ticker) {
                double result = 0.0;
                if (ticker.equals("MHP")) {
                        result = 50.0;
                } else if (ticker.equals("IBM")) {
                        result = 83.0;
                }
                return result;
        }
}

Server Ant Target :
<?xml version="1.0" encoding="UTF-8"?>
<target depends="setup" name="build-server-java">
  <apt debug="${debug}" destdir="${build.classes.home}" fork="true"
    sourcedestdir="${build.classes.home}" sourcepath="${basedir}/src" verbose="${verbose}">
    <classpath>
      <path refid="jaxws.classpath"/>
      <pathelement location="${basedir}/src"/>
    </classpath>
    <option key="r" value="${build.home}"/>
    <source dir="${basedir}/src">
      <include name="**/server/*.java"/>
    </source>
  </apt>
</target>

Client Async Target :

<?xml version="1.0" encoding="UTF-8"?>
<target depends="setup" name="generate-client-async">
  <wsimport debug="${debug}" destdir="${build.classes.home}"
    extension="${extension}" keep="${keep}" verbose="${verbose}" wsdl="${client.wsdl}">
    <binding dir="${basedir}/etc" includes="${schema.binding}"/>
    <binding dir="${basedir}/etc" includes="${client.binding.async}"/>
  </wsimport>
</target>

----- Client with Call back Class
private class GetQuoteCallbackHandler implements AsyncHandler<GetQuoteResponse>{
 private GetQuoteResponse output;
 public void handleResponse (Response<GetQuoteResponse>response)
 {
 try
 { output = response.get ();
 } catch (ExecutionException e)
 { e.printStackTrace (); }
 catch (InterruptedException e)
 { e.printStackTrace (); }
 }
 
 GetQuoteResponse getResponse (){
 return output;
 }
 }

Client :

StockQuote port = new StockQuoteService().getStockQuotePort();
 
 GetQuoteCallbackHandler callbackHandler = new GetQuoteCallbackHandler ();
 
 responseCallback = port.getQuoteAsync ("MHP", callbackHandler);
 while( ! responseCallback.isDone()){
 //some client side processes
 }

 result = callbackHandler.getResponse().getReturn();

 



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

ASYNC web service example with JAX WS


ASYNC web service example with JAX WS

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free