You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by he...@apache.org on 2006/02/18 00:21:30 UTC

svn commit: r378652 - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client: ServiceClient.java WSDLBasedPolicyProcessor.java WSDLBasedServiceConfigurationBuilder.java WSDLMEPClientBuilder.java

Author: hemapani
Date: Fri Feb 17 15:21:26 2006
New Revision: 378652

URL: http://svn.apache.org/viewcvs?rev=378652&view=rev
Log:
remove MEPClient Builder, add a WOM based AxisService creator and stubs to implement dynamic policy support .. code is not tested .. but not linked as well

Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedPolicyProcessor.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedServiceConfigurationBuilder.java
Removed:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLMEPClientBuilder.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java?rev=378652&r1=378651&r2=378652&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/ServiceClient.java Fri Feb 17 15:21:26 2006
@@ -17,6 +17,7 @@
 import org.apache.ws.commons.soap.SOAPFactory;
 import org.apache.ws.commons.soap.SOAPHeader;
 import org.apache.wsdl.WSDLConstants;
+import org.apache.wsdl.WSDLDescription;
 
 import javax.xml.namespace.QName;
 import java.io.IOException;
@@ -95,6 +96,37 @@
         ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
                 (AxisServiceGroup) this.axisService.getParent());
         this.serviceContext = sgc.getServiceContext(this.axisService);
+    }
+    
+    /**
+     * This is WOM based constructor to configure the Service Client/
+     * We are going to make this policy aware
+     * @param configContext
+     * @param wsdldesc
+     * @param wsdlServiceName
+     * @param portName
+     * @throws AxisFault
+     */
+    
+    public ServiceClient(ConfigurationContext configContext, WSDLDescription wsdldesc,
+    		QName wsdlServiceName, String portName) throws AxisFault {
+		// create a config context if needed
+		initializeTransports(configContext);
+		try {
+			this.axisConfig = this.configContext.getAxisConfiguration();
+			WSDLBasedServiceConfigurationBuilder scb= new WSDLBasedServiceConfigurationBuilder(wsdldesc,configContext);
+			axisService = scb.buildAxisService(wsdlServiceName, portName,options);
+			// add the service to the config context if it isn't in there
+			// already
+			if (this.axisConfig.getService(this.axisService.getName()) == null) {
+			   this.axisConfig.addService(this.axisService);
+			}
+			ServiceGroupContext sgc = new ServiceGroupContext(this.configContext,
+			       (AxisServiceGroup) this.axisService.getParent());
+			this.serviceContext = sgc.getServiceContext(this.axisService);
+		} catch (IOException e) {
+			throw new AxisFault(e);
+		}
     }
 
     /**

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedPolicyProcessor.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedPolicyProcessor.java?rev=378652&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedPolicyProcessor.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedPolicyProcessor.java Fri Feb 17 15:21:26 2006
@@ -0,0 +1,119 @@
+/*
+ * 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.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.ws.policy.AndCompositeAssertion;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PrimitiveAssertion;
+import org.apache.ws.policy.XorCompositeAssertion;
+
+public class WSDLBasedPolicyProcessor {
+	private HashMap ns2modules = new HashMap();
+	
+	public WSDLBasedPolicyProcessor(ConfigurationContext configctx){
+		//create the Map for namespaces to modules this is 1:N mapping
+		// so we got to use array lists
+		
+		AxisConfiguration axisConfiguration = configctx.getAxisConfiguration();
+		for (Iterator iterator = axisConfiguration.getModules().values()
+				.iterator(); iterator.hasNext();) {
+			AxisModule axisModule = (AxisModule) iterator.next();
+			String[] namespaces = axisModule.getSupportedPolicyNamespaces();
+
+			if (namespaces == null) {
+				continue;
+			}
+
+			for (int i = 0; i < namespaces.length; i++) {
+				ArrayList moduleList = null;
+				Object obj = ns2modules.get(namespaces[i]);
+				if(obj == null){
+					moduleList = new ArrayList(5);
+					ns2modules.put(namespaces[i], moduleList);
+				}else{
+					moduleList = (ArrayList)obj;
+				}
+				moduleList.add(axisModule);
+				
+			}
+		}
+		
+	}
+	
+	public void configureOperationPolices(AxisOperation op,Policy policy){
+		if (!policy.isNormalized()) {
+			policy = (Policy) policy.normalize();
+		}
+
+		HashMap map = new HashMap();
+
+		XorCompositeAssertion XOR = (XorCompositeAssertion) policy.getTerms()
+				.get(0);
+		AndCompositeAssertion AND = (AndCompositeAssertion) XOR.getTerms().get(
+				0);
+
+		for (Iterator iterator = AND.getTerms().iterator(); iterator.hasNext();) {
+
+			AndCompositeAssertion nAND = new AndCompositeAssertion();
+			PrimitiveAssertion pa = (PrimitiveAssertion) iterator.next();
+
+			String namespace = pa.getName().getNamespaceURI();
+			nAND.addTerm(pa);
+
+			while (iterator.hasNext()) {
+				pa = (PrimitiveAssertion) iterator.next();
+
+				if (namespace.equals(pa.getName().getNamespaceURI())) {
+					nAND.addTerm(pa);
+				}
+			}
+
+			map.put(namespace, nAND);
+			AND.getTerms().removeAll(nAND.getTerms());
+
+			iterator = AND.getTerms().iterator();
+		}
+
+		for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
+			String namespace = (String) iterator.next();
+			
+			//for each module intersted in 
+			ArrayList moduleList = (ArrayList)ns2modules.get(namespace);
+			
+			if (moduleList == null) {
+				System.err.println("cannot find a module to process "
+						+ namespace + "type assertions");
+				continue;
+			}else{
+				for(int i = 0;i<moduleList.size();i++){
+					AxisModule axisModule = (AxisModule) moduleList.get(i);
+					//we should be notifying/consulting modules here
+					throw new UnsupportedOperationException();
+					
+				}
+			}
+		}
+	} 
+}

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedServiceConfigurationBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedServiceConfigurationBuilder.java?rev=378652&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedServiceConfigurationBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/client/WSDLBasedServiceConfigurationBuilder.java Fri Feb 17 15:21:26 2006
@@ -0,0 +1,167 @@
+/*
+ * 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.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.description.AxisService;
+import org.apache.wsdl.WSDLBinding;
+import org.apache.wsdl.WSDLBindingOperation;
+import org.apache.wsdl.WSDLConstants;
+import org.apache.wsdl.WSDLDescription;
+import org.apache.wsdl.WSDLEndpoint;
+import org.apache.wsdl.WSDLOperation;
+import org.apache.wsdl.WSDLService;
+import org.apache.wsdl.extensions.SOAPAddress;
+import org.apache.wsdl.extensions.SOAPOperation;
+
+public class WSDLBasedServiceConfigurationBuilder {
+	private ConfigurationContext configurationContext;
+
+	private WSDLDescription description;
+
+	public WSDLBasedServiceConfigurationBuilder(WSDLDescription wsdlDesc,
+			ConfigurationContext configctx) {
+		description = wsdlDesc;
+		configurationContext = configctx;
+	}
+
+	public AxisService buildAxisService(QName servicename, String endpointname,Options clientOptions)throws AxisFault {
+		WSDLService service = findService(servicename);
+		AxisService serviceDesc = new AxisService();
+		
+		//TODO we just pick first end point
+		WSDLEndpoint endpoint = findEndpoint(null, service);
+		
+		Iterator elements = endpoint.getExtensibilityElements().iterator();
+
+		while (elements.hasNext()) {
+			Object obj = elements.next();
+			if (obj instanceof SOAPAddress) {
+				SOAPAddress soapAddress = (SOAPAddress) obj;
+				clientOptions.setTo(new EndpointReference(soapAddress.getLocationURI()));
+			}
+		}
+
+		WSDLBinding binding = endpoint.getBinding();
+
+		// let us configure the complete AxisService out of this, not the
+		// current the Operation only
+		Iterator bindings = binding.getBindingOperations().values().iterator();
+
+		while (bindings.hasNext()) {
+			WSDLBindingOperation wsdlbop = (WSDLBindingOperation) bindings
+					.next();
+			serviceDesc.addOperation(configureOperation(wsdlbop));
+		}
+
+		return serviceDesc;
+	}
+	
+	
+	private AxisOperation configureOperation(WSDLBindingOperation bindingOperation) throws AxisFault{
+		WSDLOperation wsdlop = bindingOperation.getOperation();
+		AxisOperation axisOp = AxisOperationFactory.getAxisOperation(findMEP(wsdlop));
+
+		axisOp.setName(wsdlop.getName());
+		
+		
+		
+		
+		Iterator elments = bindingOperation.getExtensibilityElements().iterator();
+
+		while (elments.hasNext()) {
+			Object obj = elments.next();
+
+			if (obj instanceof SOAPOperation) {
+				SOAPOperation soapOp = (SOAPOperation) obj;
+				//TODO put soap action to right place
+				//axisOp.setSoapAction(soapOp.getSoapAction());
+				break;
+			}
+			
+			//TODO set style 
+		}
+		return axisOp;	
+	}
+	
+
+	private WSDLEndpoint findEndpoint(QName endpointname, WSDLService service)
+			throws AxisFault {
+		WSDLEndpoint endpoint;
+
+		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 int findMEP(WSDLOperation wsdlOp) throws AxisFault {
+		if (wsdlOp.getInputMessage() == null) {
+			throw new AxisFault("Unsupported MEP");
+		}
+
+		if (wsdlOp.getOutputMessage() == null) {
+			return WSDLConstants.MEP_CONSTANT_IN_ONLY;
+		} else {
+			return WSDLConstants.MEP_CONSTANT_IN_OUT;
+		}
+	}
+
+	private WSDLService findService(QName serviceName) throws AxisFault {
+		WSDLService service;
+
+		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;
+	}
+}