CapitalPortType
is a simple interface generated
from the WSDL stub and it should not be modified manually. The interface contains
the definition of the remote operation(s) as defined in the WSDL file. Notice
that the interface extends java.rmi.Remote
and also that
all operations include RemoteException
in their signature
following the Java RMI conventions.
package example.capitals; import java.rmi.Remote; import java.rmi.RemoteException; public interface CapitalPortType extends java.rmi.Remote public String getCapital(String aNation) throws java.rmi.RemoteException;
This class is also generated from the WSDL stub. This class contains
the actual plumbing needed to connect to the JAX-RPC runtime. It implements
the Stub so that the _get
and _setProperty
methods
can be used to set the characteristics of the connection to the Web Service.
In particular, the ENDPOINT_ADDRESS_ PROPERTY
value
is set to match to the address of the service.
To create this class:
Create the
class CapitalBinding_Stub
.
Assign the
class to the example.capitals
package and import the
required classes.
package example.capitals; import java.util.Hashtable; import java.util.Enumeration; import javax.xml.rpc.Stub; import javax.xml.rpc.JAXRPCException; import javax.xml.namespace.QName; import java.rmi.RemoteException; import javax.microedition.xml.rpc.Operation; import javax.microedition.xml.rpc.Type; import javax.microedition.xml.rpc.ComplexType; import javax.microedition.xml.rpc.Element;
Set the class
to implement CapitalPortType
and javax.xml.rpc.Stub
.
Use the setProperty()
method to set the name and value
of the configuration property for this Stub instance. Set the ENDPOINT_ADDRESS_
PROPERTY
value to match the address of the service.
public class CapitalBinding_Stub implements CapitalPortType, javax.xml.rpc.Stub { public CapitalBinding_Stub() { properties = new Hashtable(); properties.put(ENDPOINT_ADDRESS_PROPERTY,new String("http://194.137.80.38:80/CapitalService/Capitals").trim()); } /** * Sets the name and value of a configuration property for this Stub * instance. */ public void _setProperty(String name, Object value) { properties.put(name,value); }
Use the getProperty()
method
to fetch the values of specific configuration properties.
/** * Gets the value of a specific configuration property. */ public Object _getProperty(String value) { if (ENDPOINT_ADDRESS_PROPERTY.equals(value) || USERNAME_PROPERTY.equals(value) || PASSWORD_PROPERTY.equals(value)) { return null; } if (SESSION_MAINTAIN_PROPERTY.equals(value)) { return new Boolean(false); } if (properties.containsKey(value)) { return properties.get(value); } throw new JAXRPCException("Unknown property: "+value); } protected void prepareOperation(Operation oper) { Enumeration names = properties.keys(); Object key, val = null; if (names == null) return; while(names.hasMoreElements()) { key = names.nextElement(); val = properties.get(key); if (key instanceof String && val != null) { oper.setProperty((String)key,val.toString()); } } }
Implement
the methods from the generated interface CapitalPortType
.
// Implement methods from generated interface public String getCapital(String aNation) throws java.rmi.RemoteException { Object inputObject = aNation; Operation oper = Operation.newInstance(wsdl_name_getCapital, oper_Request,oper_Response); prepareOperation(oper); oper.setProperty(Operation.SOAPACTION_URI_PROPERTY, ""); Object outputObject = null; try { outputObject = oper.invoke(inputObject); } catch(JAXRPCException ex) { // Get the linked cause Throwable cause = ex.getLinkedCause(); if (cause instanceof RemoteException) { throw (RemoteException)cause; } throw ex; } return (String)outputObject; }
Implement as Hashtable that contains the Stub's properties.
/** Hashtable containing stubs properties */ private Hashtable properties; protected static final QName qname_Request = new QName("urn:nokia:example:capitals:2005-01", "request"); protected static final QName qname_Response = new QName("urn:nokia:example:capitals:2005-01", "response"); protected static final QName wsdl_name_getCapital = new QName("urn:nokia:example:capitals:2005-01","getCapital"); protected static final Element oper_Request; protected static final Element oper_Response; static { oper_Request = new Element(qname_Request,Type.STRING); oper_Response = new Element(qname_Response,Type.STRING); } }