Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 6258 invoked by uid 500); 3 Oct 2001 15:47:24 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 6249 invoked by uid 500); 3 Oct 2001 15:47:24 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Date: 3 Oct 2001 15:44:57 -0000 Message-ID: <20011003154457.46874.qmail@icarus.apache.org> From: dug@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/client Service.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N dug 01/10/03 08:44:57 Modified: java/samples/stock GetQuote1.java java/src/org/apache/axis/client Service.java Added: java/samples/stock GetQuote.wsdl Log: 1st pass at using wsdl to get the service info instead of manually setting it. Revision Changes Path 1.2 +7 -7 xml-axis/java/samples/stock/GetQuote1.java Index: GetQuote1.java =================================================================== RCS file: /home/cvs/xml-axis/java/samples/stock/GetQuote1.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- GetQuote1.java 2001/10/02 14:10:06 1.1 +++ GetQuote1.java 2001/10/03 15:44:57 1.2 @@ -64,6 +64,7 @@ import org.apache.axis.client.Service ; import org.apache.axis.rpc.Call ; import org.apache.axis.encoding.XMLType ; +import org.apache.axis.rpc.namespace.QName ; import org.apache.axis.client.Transport ; import org.apache.axis.transport.http.HTTPConstants; @@ -87,16 +88,15 @@ System.exit(1); } - Service service = new Service(); - Call call = service.createCall(); + Service service = new Service( "file:///wstk/xml-axis/java/samples/stock/GetQuote.wsdl", + new QName("urn:xmltoday-delayed-quotes", + "GetQuoteService") ); + QName qn = new QName( "urn:xmltoday-delayed-quotes", "GetQuote" ); + Call call = service.createCall( qn, "getQuote" ); - call.setTargetEndpointAddress( new URL(opts.getURL()) ); - call.setOperationName( "getQuote" ); - call.addParameter( "symbol", XMLType.XSD_STRING, call.PARAM_MODE_IN ); - call.setReturnType( XMLType.XSD_FLOAT ); + // params, return-type call.setProperty( Constants.NAMESPACE, "urn:xmltoday-delayed-quotes" ); - call.setProperty( HTTPConstants.MC_HTTP_SOAPACTION, "getQuote" ); call.setProperty( Transport.USER, opts.getUser() ); call.setProperty( Transport.PASSWORD, opts.getPassword() ); 1.1 xml-axis/java/samples/stock/GetQuote.wsdl Index: GetQuote.wsdl =================================================================== 1.3 +146 -22 xml-axis/java/src/org/apache/axis/client/Service.java Index: Service.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Service.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Service.java 2001/10/03 15:30:03 1.2 +++ Service.java 2001/10/03 15:44:57 1.3 @@ -62,35 +62,61 @@ * @author Doug Davis (dug@us.ibm.com) */ -import com.ibm.wsdl.xml.WSDLReader; -import org.apache.axis.rpc.JAXRPCException; -import org.apache.axis.rpc.namespace.QName; -import org.apache.axis.utils.XMLUtils; - -import javax.wsdl.Definition; -import javax.wsdl.Operation; -import javax.wsdl.PortType; -import java.net.URL; -import java.util.Iterator; -import java.util.List; +import java.net.URL ; +import java.lang.String ; +import java.util.Map ; +import java.util.Set ; +import java.util.List ; +import java.util.Iterator ; +import java.util.HashSet ; + +import org.apache.axis.utils.XMLUtils ; + +import org.apache.axis.rpc.JAXRPCException ; +import org.apache.axis.rpc.namespace.QName ; +import org.apache.axis.transport.http.HTTPConstants ; + +import javax.wsdl.Definition ; +import javax.wsdl.Binding ; +import javax.wsdl.BindingOperation ; +import javax.wsdl.Message ; +import javax.wsdl.Operation ; +import javax.wsdl.Output ; +import javax.wsdl.Port ; +import javax.wsdl.PortType ; + +import com.ibm.wsdl.xml.WSDLReader ; +import com.ibm.wsdl.extensions.soap.SOAPAddress ; +import com.ibm.wsdl.extensions.soap.SOAPOperation ; public class Service implements org.apache.axis.rpc.Service { - private URL wsdlLocation = null ; - private Definition wsdlDefinition = null ; + private URL wsdlLocation = null ; + private Definition wsdlDefinition = null ; + private javax.wsdl.Service wsdlService = null ; public Service() throws JAXRPCException { this.wsdlLocation = null ; this.wsdlDefinition = null ; } - public Service(URL WSDLdoc) throws JAXRPCException { + public Service(URL WSDLdoc, QName serviceName) throws JAXRPCException { try { org.w3c.dom.Document doc = XMLUtils.newDocument(WSDLdoc.toString()); WSDLReader reader = new WSDLReader(); Definition def = reader.readWSDL( null, doc ); - this.wsdlLocation = WSDLdoc ; + this.wsdlLocation = WSDLdoc ; this.wsdlDefinition = def ; + + // arg! + String ns = serviceName.getNamespaceURI(); + String lp = serviceName.getLocalPart(); + javax.wsdl.QName qn = new javax.wsdl.QName( ns, lp ); + + this.wsdlService = def.getService( qn ); + if ( this.wsdlService == null ) + throw new JAXRPCException( "Can't find service: " + + serviceName ); } catch( Exception exp ) { throw new JAXRPCException( "Error processing WSDL document: " + @@ -98,7 +124,8 @@ } } - public Service(String wsdlLocation) throws JAXRPCException { + public Service(String wsdlLocation, QName serviceName) + throws JAXRPCException { try { org.w3c.dom.Document doc = XMLUtils.newDocument(wsdlLocation); WSDLReader reader = new WSDLReader(); @@ -106,6 +133,16 @@ this.wsdlLocation = new URL(wsdlLocation) ; this.wsdlDefinition = def ; + + // arg! + String ns = serviceName.getNamespaceURI(); + String lp = serviceName.getLocalPart(); + javax.wsdl.QName qn = new javax.wsdl.QName( ns, lp ); + + this.wsdlService = def.getService( qn ); + if ( this.wsdlService == null ) + throw new JAXRPCException( "Can't find service: " + + serviceName ); } catch( java.net.MalformedURLException exp ) { throw new JAXRPCException( "Malformed WSDL URI: " + wsdlLocation + @@ -129,11 +166,36 @@ portName.getLocalPart() ); if ( wsdlDefinition == null ) throw new JAXRPCException( "Missing WSDL document" ); + + Port port = wsdlService.getPort( portName.getLocalPart() ); + if ( port == null ) + throw new JAXRPCException( "Can't find port: " + portName ); + PortType portType = wsdlDefinition.getPortType( qn ); if ( portType == null ) throw new JAXRPCException( "Can't find portType: " + portName ); + org.apache.axis.client.Call call = new org.apache.axis.client.Call(); call.setPortTypeName( portName ); + + // Get the URL + //////////////////////////////////////////////////////////////////// + List list = port.getExtensibilityElements(); + for ( int i = 0 ; list != null && i < list.size() ; i++ ) { + Object obj = list.get(i); + if ( obj instanceof SOAPAddress ) { + try { + SOAPAddress addr = (SOAPAddress) obj ; + URL url = new URL(addr.getLocationURI()); + call.setTargetEndpointAddress(url); + } + catch(Exception exp) { + throw new JAXRPCException("Can't set location URI: " + + exp.toString() ); + } + } + } + return( call ); } @@ -144,9 +206,12 @@ portName.getLocalPart() ); if ( wsdlDefinition == null ) throw new JAXRPCException( "Missing WSDL document" ); - PortType portType = wsdlDefinition.getPortType( qn ); - if ( portType == null ) - throw new JAXRPCException( "Can't find portType: " + portName ); + + Port port = wsdlService.getPort( portName.getLocalPart() ); + if ( port == null ) + throw new JAXRPCException( "Can't find port: " + portName ); + + PortType portType = wsdlDefinition.getPortType( qn ); List operations = portType.getOperations(); if ( operations == null ) throw new JAXRPCException( "Can't find operation: " + @@ -164,7 +229,48 @@ call.setPortTypeName( portName ); call.setOperationName( operationName ); - // set other fields from WSDL - dug + // Get the URL + //////////////////////////////////////////////////////////////////// + List list = port.getExtensibilityElements(); + for ( int i = 0 ; list != null && i < list.size() ; i++ ) { + Object obj = list.get(i); + if ( obj instanceof SOAPAddress ) { + try { + SOAPAddress addr = (SOAPAddress) obj ; + URL url = new URL(addr.getLocationURI()); + call.setTargetEndpointAddress(url); + } + catch(Exception exp) { + throw new JAXRPCException("Can't set location URI: " + + exp.toString() ); + } + } + } + + // Get the SOAPAction + //////////////////////////////////////////////////////////////////// + Binding binding = port.getBinding(); + BindingOperation bop = binding.getBindingOperation(operationName, + null, null); + list = bop.getExtensibilityElements(); + for ( int i = 0 ; list != null && i < list.size() ; i++ ) { + Object obj = list.get(i); + if ( obj instanceof SOAPOperation ) { + SOAPOperation sop = (SOAPOperation) obj ; + String action = sop.getSoapActionURI(); + if ( action != null ) + call.setProperty(HTTPConstants.MC_HTTP_SOAPACTION, action); + } + } + + // Get the parameters + //////////////////////////////////////////////////////////////////// + // to do - dug + + // Get the return type + //////////////////////////////////////////////////////////////////// + Output output = op.getOutput(); + Message messae = output.getMessage(); return( call ); } @@ -179,12 +285,30 @@ public QName getServiceName() { // not implemented yet - return( null ); + if ( wsdlService == null ) return( null ); + javax.wsdl.QName qn = wsdlService.getQName(); + return( new QName( qn.getNamespaceURI(), qn.getLocalPart() ) ); } public Iterator getPorts() { // not implemented yet - return( null ); + if ( wsdlService == null ) return( null ); + Map map = wsdlService.getPorts(); + + if ( map == null ) return( null ); + + Set set = map.keySet(); + Iterator iter = set.iterator(); + Set ports = null ; + + while ( iter.hasNext() ) { + String name = (String) iter.next(); + Port port = (Port) map.get( name ); + if ( ports == null ) ports = new HashSet(); + ports.add( port ); + } + if ( ports == null ) return( null ); + return( ports.iterator() ); } public javax.naming.Reference getReference() {