You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by he...@apache.org on 2005/12/03 01:58:32 UTC

svn commit: r351861 - /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java

Author: hemapani
Date: Fri Dec  2 16:58:29 2005
New Revision: 351861

URL: http://svn.apache.org/viewcvs?rev=351861&view=rev
Log:
add a code to create a configured MEP client given a WSDL

Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java?rev=351861&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java Fri Dec  2 16:58:29 2005
@@ -0,0 +1,178 @@
+/*
+ *  Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+package org.apache.axis2.client;
+
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.wsdl.WSDLVersionWrapper;
+import org.apache.axis2.wsdl.builder.WOMBuilder;
+import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
+import org.apache.wsdl.WSDLBinding;
+import org.apache.wsdl.WSDLBindingOperation;
+import org.apache.wsdl.WSDLDescription;
+import org.apache.wsdl.WSDLEndpoint;
+import org.apache.wsdl.WSDLInterface;
+import org.apache.wsdl.WSDLOperation;
+import org.apache.wsdl.WSDLService;
+import org.apache.wsdl.extensions.SOAPAddress;
+import org.apache.wsdl.extensions.SOAPOperation;
+
+public class WSDLMEPClientBuilder {
+	private boolean isoneway= false;
+	private WSDLDescription description;
+	private String clienthome;
+	
+	public WSDLMEPClientBuilder(String clienthome){
+		this.clienthome = clienthome;
+	}
+	
+	public void defineDescription(URL wsdlurl)throws AxisFault{
+		try {
+			WOMBuilder buider = WOMBuilderFactory.getBuilder(WSDLConstants.WSDL_1_1);
+			WSDLVersionWrapper vw = buider.build(wsdlurl.openStream());
+			description = vw.getDescription();
+		} catch (Exception e) {
+			throw new AxisFault(e);
+		}
+	}
+	
+	public MEPClient createMEPClient(QName endpointname,String operationname) throws AxisFault{
+		return createMEPClient(null,endpointname,operationname);
+	}
+	public MEPClient createMEPClient(String operationname) throws AxisFault{
+		return createMEPClient(null,null,operationname);
+	}
+	
+	public MEPClient createMEPClient(QName servicename, QName endpointname,String operationname) throws AxisFault{
+		WSDLService service = findService(servicename);
+		WSDLEndpoint endpoint = findEndpoint(endpointname,service);
+		EndpointReference toepr = null;
+		String soapAction = "";
+		Options op = new Options();
+		
+		
+		Iterator elements = endpoint.getExtensibilityElements().iterator();
+        while (elements.hasNext()) {
+                Object obj = elements.next();
+                System.out.println("Extension = " +obj);
+                if(obj instanceof SOAPAddress){
+                        SOAPAddress soapAddress = (SOAPAddress) obj;
+                        System.out.println(soapAddress.getLocationURI());
+                        toepr = new EndpointReference(soapAddress.getLocationURI());
+                }
+        }
+        
+        if(toepr != null){
+        	op.setTo(toepr);
+        }else{
+        	throw new AxisFault("To Address not found");
+        }
+
+        WSDLBinding binding = endpoint.getBinding();
+
+        WSDLOperation wsdlop = getOperation(operationname,endpoint);
+        
+        WSDLBindingOperation bop = binding.getBindingOperation(wsdlop.getName());
+        Iterator elments = bop.getExtensibilityElements().iterator();
+        while (elments.hasNext()) {
+                Object obj = elments.next();
+                if (obj instanceof SOAPOperation) {
+                        SOAPOperation soapOp = (SOAPOperation) obj;
+                        op.setSoapAction(soapOp.getSoapAction());
+                        break;
+                }
+        }
+        
+        
+        MEPClient mepclient = new MessageSender(clienthome);
+        if(wsdlop.getInputMessage() != null && wsdlop.getOutputMessage() != null && !isoneway){
+        	mepclient = new Call(clienthome);
+        }else if(wsdlop.getInputMessage() != null || isoneway){
+            mepclient = new MessageSender(clienthome);        	
+        }else{
+        	throw new AxisFault("Unknown MEP");
+        }
+        
+        mepclient.setClientOptions(op);
+        return mepclient;
+	}
+	
+	
+	private WSDLService findService(QName serviceName) throws AxisFault{
+		WSDLService service = null;
+		if(serviceName == null){
+			Iterator services = description.getServices().values().iterator();
+			if(services.hasNext()){
+				service = (WSDLService)services.next();
+			}else{
+				throw new AxisFault("No service found");
+			}
+		}else{
+			service = description.getService(serviceName);
+		}
+		
+		if(service == null){
+			throw new AxisFault("No service found");
+		}
+		return service;
+	}
+	
+	private WSDLEndpoint findEndpoint(QName endpointname,WSDLService service) throws AxisFault{
+		WSDLEndpoint endpoint = null;
+		if(endpointname == null){
+			Iterator endpoints = service.getEndpoints().values().iterator();
+			if (endpoints.hasNext()) {
+				endpoint = (WSDLEndpoint) endpoints.next();
+			} else {
+				throw new AxisFault("No Endpoint Found in Service, " + service.getName());
+			}
+		}else{
+			endpoint = service.getEndpoint(endpointname);
+		}
+		if(endpoint == null){
+			throw new AxisFault("Endpoint Not found");
+		}
+		return endpoint;
+	}
+	
+	 private WSDLOperation getOperation(String operation,WSDLEndpoint endpoint) throws AxisFault {
+         WSDLInterface wsdlinterface = endpoint.getBinding().getBoundInterface();
+         Iterator operations = wsdlinterface.getAllOperations().values().iterator();
+         while(operations.hasNext()){
+                 WSDLOperation wsdlOp = (WSDLOperation)operations.next();
+                 if(wsdlOp.getName().getLocalPart().equals(operation)){
+                         return wsdlOp;
+                 }
+
+         }
+         throw new AxisFault("Operation Not found");
+ }
+
+	public WSDLDescription getDescription() {
+		return description;
+	}
+
+	public void setIsoneway(boolean isoneway) {
+		this.isoneway = isoneway;
+	}
+}