📄 jaxrpcstockquoteserviceclient.java
字号:
/* * @author : Elangovan
* @version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : JAXRPCStockQuoteServiceClient.java
*
* Creation / Modification History
* Elangovan 19-Aug-2003 Created
*
*/
package oracle.otnsamples.ibfbs.admin.helper;
import javax.xml.rpc.Stub;
import javax.servlet.http.HttpServletRequest;
import java.util.StringTokenizer;
import java.rmi.RemoteException;
import oracle.otnsamples.ibfbs.admin.helper.wsclient.StockQuoteService;
import oracle.otnsamples.ibfbs.admin.helper.wsclient.StockQuoteEJB_Impl;
import oracle.otnsamples.ibfbs.admin.exception.AdminHelperException;
import oracle.otnsamples.ibfbs.utils.ConnectionParams;
/**
* This class is a JAX-RPC client for Stock Quote Web Service hosted by FBS.
* It uses a JAX-RPC static stub to invoke the Web Service.
*/
public class JAXRPCStockQuoteServiceClient {
/**
* This method invokes the 'getQuote' method on the Web Service with the
* specified symbols and returns the corresponding stock rates. JAX-RPC Web
* Services support array as input/output parameters.
*
* @param req HTTP Servlet request containing the stock symbols
* @return Stock rate for the specified symbols
* @throws if Web Service invocation fails
*/
public Float[] getQuote(HttpServletRequest req)
throws AdminHelperException {
// Get the symbols
String symbols = req.getParameter("SYMBOLS").trim();
// Individual symbols will be seperated by comma (,)
// Use tokenizer and construct an array of symbols
StringTokenizer tokens = new StringTokenizer(symbols, ",");
int len = tokens.countTokens();
String symbolArr[] = new String[len];
for(int i=0;i<len;i++)
symbolArr[i] = tokens.nextToken().trim();
try {
// Get a reference to the stub
Stub stub = (Stub) new StockQuoteEJB_Impl().getStockQuoteServicePort();
// Set the ENDPOINT address
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,ConnectionParams.endpointURL);
StockQuoteService quoteService = (StockQuoteService) stub;
req.setAttribute("SYMBOLS",symbolArr);
// Invoke the service and return the rates
return quoteService.getStockQuote(symbolArr);
} catch(RemoteException remoteEx) {
throw new AdminHelperException (" Error accessing web service : "+remoteEx.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -