aspose file tools*
The moose likes Web Services and the fly likes Questions on RPCServiceClient with axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Questions on RPCServiceClient with axis2" Watch "Questions on RPCServiceClient with axis2" New topic
Author

Questions on RPCServiceClient with axis2

Daniel Sagayaraj
Ranch Hand

Joined: Mar 15, 2010
Posts: 32
Hai Friends..

I am using axis2.
My web service has three methods

1)addQuote
2)getQuote
3)getAllQuotes


------------------------------
This is the service that is running ....

/**
*/

package stocks.soapservices;

import java.util.*;

/**
* Demo related packages
*/

import stocks.util.StockQuote;

/**
* StockQuoteService.java
*
* SOAP based Stock Quote Services include :
* - addQuote() - to add a new stock quote
* - getQuote() - to get the current price of a given stock symbol
* - getAllQuotes() - to get all the quotes in the database
*
* for demo purposes, this service contains an 'init' method to
* load some same stock quotes.
*
*/

public final class StockQuoteService {
public final Hashtable stockData;

/**
* Constructor
*/

public StockQuoteService() {
stockData = new Hashtable();
init(); // Usually initializes JDBC Access in a real-world situation
}

/**
* Add/Update a stock quote
*
* @param StockQuote
*/

@SuppressWarnings("unchecked")
public boolean addQuote(StockQuote stockQuote) {
if (stockQuote != null) {
stockData.put(stockQuote.getSymbol().trim(), stockQuote);
ServerNotificationHandler.getInstance().dataChanged();
return true;
}
return false;
}



/**
* Get the StockQuote for a specified Stock Symbol
*
* @param String
* @return StockQuote
*/

public StockQuote getQuote(String symbol) {
return (StockQuote) stockData.get(symbol);
}

/**
* Get all the StockQuotes from the database.
*
* @return Hashtable
*/

public Hashtable getAllQuotes() {
return stockData;
}

/**
* Initialize temporary data for demo purpose only
*
*/

private void init() {
stockData.put("CSCO", new StockQuote("CSCO", "Cisco", 19.62));
stockData.put("INTC", new StockQuote("INTC", "Intel", 33.81));
stockData.put("IBM", new StockQuote("IBM", "IBM", 122.20));
stockData.put("MSFT", new StockQuote("MSFT", "Microsoft", 69.27));
stockData.put("ORCL", new StockQuote("ORCL", "Oracle", 15.05));
stockData.put("SUNW", new StockQuote("SUNW", "Sun", 12.58));
}

}



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

This is the sample client class that access the web service to perform the action..
-----------------------------------


package stocks.clientservices;

import java.util.Enumeration;
import java.util.Hashtable;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.log4j.Logger;

import stocks.util.StockQuote;

//

public class ConsoleInteraction {

/**
* @param args
* @throws AxisFault
*/
public static void main(String[] args) throws AxisFault {
// TODO Auto-generated method stub

Logger logger = Logger.getLogger(ConsoleInteraction.class);

logger.info("Intro..");

// Create client to access a service
RPCServiceClient serviceClient = new RPCServiceClient();

// Get client options to interact with the service
Options options = serviceClient.getOptions();

// Create service end point reference
EndpointReference endPointRef = new EndpointReference(
"http://localhost:8080/axis/services/StockQuoteService");

// Set end point reference to service client options
options.setTo(endPointRef);
// System.out.println("calling the method....");

StockQuote Data = new StockQuote();

System.out.println("calling add method....");
QName qualsetStock = new QName("http://soapservices.stocks", "addQuote");

Data.setName("IBM");
Data.setSymbol("IBM");
Data.setValue(78.44);

Object[] objSetStockVal = new Object[] { Data };

serviceClient.invokeRobust(qualsetStock, objSetStockVal);

logger.info("Fetch.... just one ");

QName keyQuote = new QName("http://soapservices.stocks", "getQuote");
Object[] objStockVal = new Object[] { "1" };
Class[] returnStockTypes = new Class[] { StockQuote.class };

// Send service request
Object[] keyResponse = serviceClient.invokeBlocking(keyQuote,
objStockVal, returnStockTypes);

for (int i = 0; i < keyResponse.length; i++) {
StockQuote stockKeyQuote = (StockQuote) keyResponse[i];

System.out.println(stockKeyQuote.getName());
System.out.println(stockKeyQuote.getSymbol());
System.out.println(stockKeyQuote.getValue());

System.out.println("-------------------------");

}

// Fetch Stock values
logger.info("Fetch....All");

QName allQuote = new QName("http://soapservices.stocks", "getAllQuotes");
Object[] objGetStockVal = new Object[] {};
Class[] returnTypes = new Class[] { Hashtable.class };

// Send service request
Object[] response = serviceClient.invokeBlocking(allQuote,
objGetStockVal, returnTypes);
logger.info("Proceed..");

logger.info(response.length);
Hashtable result = (Hashtable) response[0];

logger.info(result.keys().hasMoreElements()); //I am getting the value as false.. This where i am stuck...

for (Enumeration e = result.keys(); e.hasMoreElements();) {

String symbol = (String) e.nextElement();
System.out.println(symbol);
StockQuote stockQuote = (StockQuote) result.get(symbol);
System.out.println(stockQuote.getName());
System.out.println(stockQuote.getSymbol());
System.out.println(stockQuote.getValue());
System.out.println("-------------------------");
}

}

}


-----------------------------------------------------
I do not not get any exceptions..

The first two method works fine but not in the client class while accessing the getAllQuotes method the returned hashtable is empty

Please check my code and help me to learn....





 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Questions on RPCServiceClient with axis2
 
Similar Threads
cannot find symbol
HashTable not working in axis web service
not able to call a service from another service using axis2
Web Services problem
complex data type in axis 2 web service