Customizing Content With Oracle XML DB and J2EE features

News Export - Web Service Implementation in XMLNews 

December 2002
  Oracle9i  
previous page

Web Services:

Web services are a set of emerging standards that describe service-oriented, component-based application architecture. Web Services enable loosely coupled, reusable software components that semantically encapsulate discrete functionality and are distributed and programmatically accessible over standard Internet protocols. Web Services as they stand today comprise of open Internet standards like WSDL(Web Services Description Language), SOAP(Simple Object Access Protocol), and UDDI(Universal Description Discovery and Integration). WSDL is used to describe the Web Service, UDDI is used to publish and query Web Services described in WSDL, and finally SOAP is used to invoke the Web Service. This is the common Web Services programming model.

News Export Web service:
One of the important services - the News WebService, is implemented in the services layer.  The Web Service will enable users to export news from the current application. In the services layer, the NewsServiceBean, a session bean exposes the method – getAllNews() as a Web Service. As the underlying process, the NewsServicenBean in turn will call the business layer EJB method to get the news items. Any client which will consume this web service will call the getAllNews() method of the Web Service stub to get the news.

Implementation:
getAllNews() method of NewsService session bean takes in date value as a  string parameter. The title and description of all the news items separated by "##"  for the passed date will be retrieved as a String array. The stub for the webservice is shipped with the application. Any client which will consume this web service will call the getAllNews() method of the stub to get the news.

Below is how the webservice endpoint is created in the stub.
 public class NewsServiceBeanStub {
public static void main(String[] args) throws Exception {
NewsServiceBeanStub stub = new NewsServiceBeanStub();

}
public String endpoint = "http://152.69.168.207:8888/xmlnews/OTNDynamicNewsService";
private OracleSOAPHTTPConnection m_httpConnection = null;
private SOAPMappingRegistry m_smr = null;
public NewsServiceBeanStub() {
try {
endpoint = ResourceBundle.getBundle("Misc").getString("webservice.endpoint");
}
catch(Exception ex) {

}
m_httpConnection = new OracleSOAPHTTPConnection();
m_smr = new SOAPMappingRegistry();
}
.............

Here is the stub code snippet that calls the bean method to retrieve new items.
.................
public String[] getAllNews(String newsDate) throws Exception {
String[] returnVal = null;
URL endpointURL = new URL(endpoint);
Call call = new Call();
call.setSOAPTransport(m_httpConnection);
call.setTargetObjectURI("OtnDynamicNewsService");
call.setMethodName("getAllNews");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("newsDate", java.lang.String.class, newsDate, null));
call.setParams(params);
call.setSOAPMappingRegistry(m_smr);
Response response = call.invoke(endpointURL, "");
if(!response.generatedFault()) {
Parameter result = response.getReturnValue();
returnVal = (String[])result.getValue();
}
else {
Fault fault = response.getFault();
throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
}
return returnVal;
}
................

Here is an example of a simple java client code which can consume XMLNews web service.

.................
WebServiceClient webServiceClient = new WebServiceClient();
NewsServiceBeanStub newsServiceBeanStub = new NewsServiceBeanStub();
try {
// get news items into an array by passing a date value
String[] newsArray = newsServiceBeanStub.getAllNews("17-Nov-2002");

................


Post you comments in the OTN Sample Code forum
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy