getProduct Method
Parameter skuParam;
// Create SOAP RPC Call Object
Call call = new Call ();
// Set Encoding Style to standard SOAP encoding
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Set Object URI and Method Name
call.setTargetObjectURI ("urn:examples:productservice2");
call.setMethodName ("getProductInfo");
// Add JavaXML Mapping for Product Bean
// First, Create a Bean Serializer
BeanSerializer bSerializer = new BeanSerializer();
// Second, Get the current SOAPMappingRegistry
// This object is pre-registered with basic mappings
SOAPMappingRegistry registry = new SOAPMappingRegistry();
// Third, Create an new Qualified Namespace for Product Bean
QName qname = new QName ("urn:examples", "product");
// Fourth, Register new mapping for ProductBean
registry.mapTypes (Constants.NS_URI_SOAP_ENC, qname,
com.ecerami.soap.ProductBean.class, bSerializer, bSerializer);
// Fifth, Set MappingRegistry for the Call object
call.setSOAPMappingRegistry(registry);
// Set Method Parameters
Vector paramList = new Vector ();
skuParam = new Parameter("sku", String.class,
sku, Constants.NS_URI_SOAP_ENC);
paramList.addElement (skuParam);
call.setParams (paramList);
// Set the URL for the Web Service
URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");
// Invoke the Service
Response resp = call.invoke (url, null);
// Check for Success
if (!resp.generatedFault()) {
// Extract Return value
Parameter result = resp.getReturnValue ();
ProductBean product = (ProductBean) result.getValue();
return product;
}
// Check for Faults
else {
// Extract Fault Code and String
Fault fault = resp.getFault();
String faultString = fault.getFaultString();
throw new ProductNotFoundException (faultString, fault);
}