Save This Page
Home » axis2-1.5-src » org.apache » axis2 » deployment » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements. See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership. The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License. You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied. See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   package org.apache.axis2.deployment;
   21   
   22   import org.apache.axiom.om.OMAttribute;
   23   import org.apache.axiom.om.OMElement;
   24   import org.apache.axis2.AxisFault;
   25   import org.apache.axis2.addressing.AddressingHelper;
   26   import org.apache.axis2.context.ConfigurationContext;
   27   import org.apache.axis2.dataretrieval.DRConstants;
   28   import org.apache.axis2.deployment.util.PhasesInfo;
   29   import org.apache.axis2.deployment.util.Utils;
   30   import org.apache.axis2.description.AxisMessage;
   31   import org.apache.axis2.description.AxisOperation;
   32   import org.apache.axis2.description.AxisOperationFactory;
   33   import org.apache.axis2.description.AxisService;
   34   import org.apache.axis2.description.InOutAxisOperation;
   35   import org.apache.axis2.description.ModuleConfiguration;
   36   import org.apache.axis2.description.ParameterInclude;
   37   import org.apache.axis2.description.PolicyInclude;
   38   import org.apache.axis2.description.WSDL2Constants;
   39   import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
   40   import org.apache.axis2.description.java2wsdl.TypeTable;
   41   import org.apache.axis2.engine.MessageReceiver;
   42   import org.apache.axis2.engine.ObjectSupplier;
   43   import org.apache.axis2.engine.ServiceLifeCycle;
   44   import org.apache.axis2.i18n.Messages;
   45   import org.apache.axis2.util.Loader;
   46   import org.apache.axis2.wsdl.WSDLConstants;
   47   import org.apache.commons.logging.Log;
   48   import org.apache.commons.logging.LogFactory;
   49   
   50   import javax.xml.namespace.QName;
   51   import javax.xml.stream.FactoryConfigurationError;
   52   import javax.xml.stream.XMLStreamException;
   53   
   54   import java.io.InputStream;
   55   import java.util.ArrayList;
   56   import java.util.HashMap;
   57   import java.util.Hashtable;
   58   import java.util.Iterator;
   59   import java.util.Map;
   60   
   61   /**
   62    * Builds a service description from OM
   63    */
   64   public class ServiceBuilder extends DescriptionBuilder {
   65   	private static final Log log = LogFactory.getLog(ServiceBuilder.class);
   66   	private AxisService service;
   67   	private HashMap wsdlServiceMap = new HashMap();
   68   
   69   	public ServiceBuilder(ConfigurationContext configCtx, AxisService service) {
   70   		this.service = service;
   71   		this.configCtx = configCtx;
   72   		this.axisConfig = this.configCtx.getAxisConfiguration();
   73   	}
   74   
   75   	public ServiceBuilder(InputStream serviceInputStream,
   76   			ConfigurationContext configCtx, AxisService service) {
   77   		super(serviceInputStream, configCtx);
   78   		this.service = service;
   79   	}
   80   
   81   	/**
   82   	 * Populates service from corresponding OM.
   83   	 * 
   84   	 * @param service_element
   85   	 *            an OMElement for the <service> tag
   86   	 * @return a filled-in AxisService, configured from the passed XML
   87   	 * @throws DeploymentException
   88   	 *             if there is a problem
   89   	 */
   90   	public AxisService populateService(OMElement service_element)
   91   			throws DeploymentException {
   92   		try {
   93   			// Determine whether service should be activated.
   94   			String serviceActivate = service_element
   95   					.getAttributeValue(new QName(ATTRIBUTE_ACTIVATE));
   96   			if (serviceActivate != null) {
   97   				if ("true".equals(serviceActivate)) {
   98   					service.setActive(true);
   99   				} else if ("false".equals(serviceActivate)) {
  100   					service.setActive(false);
  101   				}
  102   			}
  103   
  104   			// Processing service level parameters
  105   			OMAttribute serviceNameatt = service_element
  106   					.getAttribute(new QName(ATTRIBUTE_NAME));
  107   
  108   			// If the service name is explicitly specified in the services.xml
  109   			// then use that as the service name
  110   			if (serviceNameatt != null) {
  111   				if (!"".equals(serviceNameatt.getAttributeValue().trim())) {
  112   					AxisService wsdlService = (AxisService) wsdlServiceMap
  113   							.get(serviceNameatt.getAttributeValue());
  114   					if (wsdlService != null) {
  115   						wsdlService.setClassLoader(service.getClassLoader());
  116   						wsdlService.setParent(service.getAxisServiceGroup());
  117   						service = wsdlService;
  118   						service.setWsdlFound(true);
  119   						service.setCustomWsdl(true);
  120   					}
  121   					service.setName(serviceNameatt.getAttributeValue());
  122   					// To be on the safe side
  123   					if (service.getDocumentation() == null) {
  124   						service.setDocumentation(serviceNameatt
  125   								.getAttributeValue());
  126   					}
  127   				}
  128   			}
  129   
  130   			Iterator itr = service_element.getChildrenWithName(new QName(
  131   					TAG_PARAMETER));
  132   			processParameters(itr, service, service.getParent());
  133   
  134   			// If multiple services in one service group have different values
  135   			// for the PARENT_FIRST
  136   			// parameter then the final value become the value specified by the
  137   			// last service in the group
  138   			// Parameter parameter =
  139   			// service.getParameter(DeploymentClassLoader.PARENT_FIRST);
  140   			// if (parameter !=null && "false".equals(parameter.getValue())) {
  141   			// ClassLoader serviceClassLoader = service.getClassLoader();
  142   			// ((DeploymentClassLoader)serviceClassLoader).setParentFirst(false);
  143   			// }
  144   			// process service description
  145   			OMElement descriptionElement = service_element
  146   					.getFirstChildWithName(new QName(TAG_DESCRIPTION));
  147   			if (descriptionElement != null) {
  148   				OMElement descriptionValue = descriptionElement
  149   						.getFirstElement();
  150   				if (descriptionValue != null) {
  151   					service.setDocumentation(descriptionValue);
  152   				} else {
  153   					service.setDocumentation(descriptionElement.getText());
  154   				}
  155   			} else {
  156   				serviceNameatt = service_element.getAttribute(new QName(
  157   						ATTRIBUTE_NAME));
  158   
  159   				if (serviceNameatt != null) {
  160   					if (!"".equals(serviceNameatt.getAttributeValue().trim())
  161   							&& service.getDocumentation() == null) {
  162   						service.setDocumentation(serviceNameatt
  163   								.getAttributeValue());
  164   					}
  165   				}
  166   			}
  167   
  168   			if (service.getParameter("ServiceClass") == null) {
  169   				log.debug("The Service " + service.getName()
  170   						+ " does not specify a Service Class");
  171   			}
  172   
  173   			// Process WS-Addressing flag attribute
  174   			OMAttribute addressingRequiredatt = service_element
  175   					.getAttribute(new QName(ATTRIBUTE_WSADDRESSING));
  176   			if (addressingRequiredatt != null) {
  177   				String addressingRequiredString = addressingRequiredatt
  178   						.getAttributeValue();
  179   				AddressingHelper.setAddressingRequirementParemeterValue(
  180   						service, addressingRequiredString);
  181   			}
  182   
  183   			// Setting service target namespace if any
  184   			OMAttribute targetNameSpace = service_element
  185   					.getAttribute(new QName(TARGET_NAME_SPACE));
  186   
  187   			if (targetNameSpace != null) {
  188   				String nameSpeceVale = targetNameSpace.getAttributeValue();
  189   				if (nameSpeceVale != null && !"".equals(nameSpeceVale)) {
  190   					service.setTargetNamespace(nameSpeceVale);
  191   				}
  192   			} else {
  193   				if (service.getTargetNamespace() == null
  194   						|| "".equals(service.getTargetNamespace())) {
  195   					service
  196   							.setTargetNamespace(Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE);
  197   				}
  198   			}
  199   
  200   			// Processing service lifecycle attribute
  201   			OMAttribute serviceLifeCycleClass = service_element
  202   					.getAttribute(new QName(TAG_CLASS_NAME));
  203   			if (serviceLifeCycleClass != null) {
  204   				String className = serviceLifeCycleClass.getAttributeValue();
  205   				loadServiceLifeCycleClass(className);
  206   			}
  207   			// Setting schema namespece if any
  208   			OMElement schemaElement = service_element
  209   					.getFirstChildWithName(new QName(SCHEMA));
  210   			if (schemaElement != null) {
  211   				OMAttribute schemaNameSpace = schemaElement
  212   						.getAttribute(new QName(SCHEMA_NAME_SPACE));
  213   				if (schemaNameSpace != null) {
  214   					String nameSpeceVale = schemaNameSpace.getAttributeValue();
  215   					if (nameSpeceVale != null && !"".equals(nameSpeceVale)) {
  216   						service.setSchemaTargetNamespace(nameSpeceVale);
  217   					}
  218   				}
  219   				OMAttribute elementFormDefault = schemaElement
  220   						.getAttribute(new QName(SCHEMA_ELEMENT_QUALIFIED));
  221   				if (elementFormDefault != null) {
  222   					String value = elementFormDefault.getAttributeValue();
  223   					if ("true".equals(value)) {
  224   						service.setElementFormDefault(true);
  225   					} else if ("false".equals(value)) {
  226   						service.setElementFormDefault(false);
  227   					}
  228   				}
  229   
  230   				// package to namespace mapping. This will be an element that
  231   				// maps pkg names to a namespace
  232   				// when this is doing AxisService.getSchemaTargetNamespace will
  233   				// be overridden
  234   				// This will be <mapping/> with @namespace and @package
  235   				Iterator mappingIterator = schemaElement
  236   						.getChildrenWithName(new QName(MAPPING));
  237   				if (mappingIterator != null) {
  238   					Map pkg2nsMap = new Hashtable();
  239   					while (mappingIterator.hasNext()) {
  240   						OMElement mappingElement = (OMElement) mappingIterator
  241   								.next();
  242   						OMAttribute namespaceAttribute = mappingElement
  243   								.getAttribute(new QName(ATTRIBUTE_NAMESPACE));
  244   						OMAttribute packageAttribute = mappingElement
  245   								.getAttribute(new QName(ATTRIBUTE_PACKAGE));
  246   						if (namespaceAttribute != null
  247   								&& packageAttribute != null) {
  248   							String namespaceAttributeValue = namespaceAttribute
  249   									.getAttributeValue();
  250   							String packageAttributeValue = packageAttribute
  251   									.getAttributeValue();
  252   							if (namespaceAttributeValue != null
  253   									&& packageAttributeValue != null) {
  254   								pkg2nsMap.put(packageAttributeValue.trim(),
  255   										namespaceAttributeValue.trim());
  256   							} else {
  257   								log
  258   										.warn("Either value of @namespce or @packagename not available. Thus, generated will be selected.");
  259   							}
  260   						} else {
  261   							log
  262   									.warn("Either @namespce or @packagename not available. Thus, generated will be selected.");
  263   						}
  264   					}
  265   					service.setP2nMap(pkg2nsMap);
  266   
  267   				}
  268   
  269   			}
  270   
  271   			// processing Default Message receivers
  272   			OMElement messageReceiver = service_element
  273   					.getFirstChildWithName(new QName(TAG_MESSAGE_RECEIVERS));
  274   			if (messageReceiver != null) {
  275   				HashMap mrs = processMessageReceivers(service.getClassLoader(),
  276   						messageReceiver);
  277   				Iterator keys = mrs.keySet().iterator();
  278   				while (keys.hasNext()) {
  279   					String key = (String) keys.next();
  280   					service.addMessageReceiver(key, (MessageReceiver) mrs
  281   							.get(key));
  282   				}
  283   			}
  284   
  285   			// Removing exclude operations
  286   			OMElement excludeOperations = service_element
  287   					.getFirstChildWithName(new QName(TAG_EXCLUDE_OPERATIONS));
  288   			ArrayList excludeops = null;
  289   			if (excludeOperations != null) {
  290   				excludeops = processExcludeOperations(excludeOperations);
  291   			}
  292   			if (excludeops == null) {
  293   				excludeops = new ArrayList();
  294   			}
  295   			Utils.addExcludeMethods(excludeops);
  296   
  297   			// <schema targetNamespace="http://x.y.z"/>
  298   			// setting the PolicyInclude
  299   			// processing <wsp:Policy> .. </..> elements
  300   			Iterator policyElements = service_element
  301   					.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
  302   
  303   			if (policyElements != null && policyElements.hasNext()) {
  304   				processPolicyElements(policyElements, service.getPolicySubject());
  305   			}
  306   
  307   			// processing <wsp:PolicyReference> .. </..> elements
  308   			Iterator policyRefElements = service_element
  309   					.getChildrenWithName(new QName(POLICY_NS_URI,
  310   							TAG_POLICY_REF));
  311   
  312   			if (policyRefElements != null && policyRefElements.hasNext()) {
  313   				processPolicyRefElements(policyRefElements, service.getPolicySubject());
  314   			}
  315   
  316   			// processing service scope
  317   			String sessionScope = service_element.getAttributeValue(new QName(
  318   					ATTRIBUTE_SCOPE));
  319   			if (sessionScope != null) {
  320   				service.setScope(sessionScope);
  321   			}
  322   
  323   			// processing service-wide modules which required to engage globally
  324   			Iterator moduleRefs = service_element
  325   					.getChildrenWithName(new QName(TAG_MODULE));
  326   
  327   			processModuleRefs(moduleRefs);
  328   
  329   			// processing transports
  330   			OMElement transports = service_element
  331   					.getFirstChildWithName(new QName(TAG_TRANSPORTS));
  332   			if (transports != null) {
  333   				Iterator transport_itr = transports
  334   						.getChildrenWithName(new QName(TAG_TRANSPORT));
  335   				ArrayList trs = new ArrayList();
  336   				while (transport_itr.hasNext()) {
  337   					OMElement trsEle = (OMElement) transport_itr.next();
  338   					String transportName = trsEle.getText().trim();
  339   					trs.add(transportName);
  340   					if (axisConfig.getTransportIn(transportName) == null) {
  341   						throw new AxisFault("Service [ " + service.getName()
  342   								+ "] is trying to expose in a transport : "
  343   								+ transports
  344   								+ " and which is not available in Axis2");
  345   					}
  346   				}
  347   				service.setExposedTransports(trs);
  348   			}
  349   			// processing operations
  350   			Iterator operationsIterator = service_element
  351   					.getChildrenWithName(new QName(TAG_OPERATION));
  352   			ArrayList ops = processOperations(operationsIterator);
  353   
  354   			for (int i = 0; i < ops.size(); i++) {
  355   				AxisOperation operationDesc = (AxisOperation) ops.get(i);
  356   				ArrayList wsamappings = operationDesc.getWSAMappingList();
  357   				if (wsamappings == null) {
  358   					continue;
  359   				}
  360   				if (service.getOperation(operationDesc.getName()) == null) {
  361   					service.addOperation(operationDesc);
  362   				}
  363   				for (int j = 0; j < wsamappings.size(); j++) {
  364   					String mapping = (String) wsamappings.get(j);
  365   					if (mapping.length() > 0) {
  366   						service.mapActionToOperation(mapping, operationDesc);
  367   					}
  368   				}
  369   			}
  370   			String objectSupplierValue = (String) service
  371   					.getParameterValue(TAG_OBJECT_SUPPLIER);
  372   			if (objectSupplierValue != null) {
  373   				loadObjectSupplierClass(objectSupplierValue);
  374   			}
  375   			// Set the default message receiver for the operations that were
  376   			// not listed in the services.xml
  377   			setDefaultMessageReceivers();
  378   			Utils.processBeanPropertyExclude(service);
  379   			if (!service.isUseUserWSDL()) {
  380   				// Generating schema for the service if the impl class is Java
  381   				if (!service.isWsdlFound()) {
  382   					// trying to generate WSDL for the service using JAM and
  383   					// Java reflection
  384   					try {
  385   						if (generateWsdl(service)) {
  386   							Utils.fillAxisService(service, axisConfig,
  387   									excludeops, null);
  388   						} else {
  389   							ArrayList nonRpcOperations = getNonRPCMethods(service);
  390   							Utils.fillAxisService(service, axisConfig,
  391   									excludeops, nonRpcOperations);
  392   						}
  393   					} catch (Exception e) {
  394   						throw new DeploymentException(Messages.getMessage(
  395   								"errorinschemagen", e.getMessage()), e);
  396   					}
  397   				}
  398   			}
  399   			if (service.isCustomWsdl()) {
  400   				OMElement mappingElement = service_element
  401   						.getFirstChildWithName(new QName(TAG_PACKAGE2QNAME));
  402   				if (mappingElement != null) {
  403   					processTypeMappings(mappingElement);
  404   				}
  405   			}
  406   
  407   			for (int i = 0; i < excludeops.size(); i++) {
  408   				String opName = (String) excludeops.get(i);
  409   				service.removeOperation(new QName(opName));
  410   			}
  411   
  412   			// Need to call the same logic towice
  413   			setDefaultMessageReceivers();
  414   			Iterator moduleConfigs = service_element
  415   					.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
  416   			processServiceModuleConfig(moduleConfigs, service, service);
  417   
  418   			// Loading Data Locator(s) configured
  419   			OMElement dataLocatorElement = service_element
  420   					.getFirstChildWithName(new QName(
  421   							DRConstants.DATA_LOCATOR_ELEMENT));
  422   			if (dataLocatorElement != null) {
  423   				processDataLocatorConfig(dataLocatorElement, service);
  424   			}
  425   
  426   			processEndpoints(service);
  427   			processPolicyAttachments(service_element, service);
  428   			
  429   
  430   		} catch (AxisFault axisFault) {
  431   			throw new DeploymentException(axisFault);
  432   		}
  433   
  434   		return service;
  435   	}
  436   
  437   	private void setDefaultMessageReceivers() {
  438   		Iterator operations = service.getPublishedOperations().iterator();
  439   		while (operations.hasNext()) {
  440   			AxisOperation operation = (AxisOperation) operations.next();
  441   			if (operation.getMessageReceiver() == null) {
  442   				MessageReceiver messageReceiver = loadDefaultMessageReceiver(
  443   						operation.getMessageExchangePattern(), service);
  444   				if (messageReceiver == null &&
  445   				// we assume that if the MEP is ROBUST_IN_ONLY then the in-out
  446   						// MR can handle that
  447   						WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(operation
  448   								.getMessageExchangePattern())) {
  449   					messageReceiver = loadDefaultMessageReceiver(
  450   							WSDL2Constants.MEP_URI_IN_OUT, service);
  451   
  452   				}
  453   				operation.setMessageReceiver(messageReceiver);
  454   			}
  455   		}
  456   	}
  457   
  458   	private void loadObjectSupplierClass(String objectSupplierValue)
  459   			throws AxisFault {
  460   		try {
  461   			ClassLoader loader = service.getClassLoader();
  462   			Class objectSupplierImpl = Loader.loadClass(loader,
  463   					objectSupplierValue.trim());
  464   			ObjectSupplier objectSupplier = (ObjectSupplier) objectSupplierImpl
  465   					.newInstance();
  466   			service.setObjectSupplier(objectSupplier);
  467   		} catch (Exception e) {
  468   			throw AxisFault.makeFault(e);
  469   		}
  470   	}
  471   
  472   	/**
  473   	 * Process the package name to QName mapping:
  474   	 * 
  475   	 * &lt;packageMapping&gt; &lt;mapping packageName="foo.bar"
  476   	 * qname="http://foo/bar/xsd"%gt; ...... ...... &lt;/packageMapping&gt;
  477   	 * 
  478   	 * @param packageMappingElement
  479   	 *            OMElement for the packageMappingElement
  480   	 */
  481   	private void processTypeMappings(OMElement packageMappingElement) {
  482   		Iterator elementItr = packageMappingElement
  483   				.getChildrenWithName(new QName(TAG_MAPPING));
  484   		TypeTable typeTable = service.getTypeTable();
  485   		if (typeTable == null) {
  486   			typeTable = new TypeTable();
  487   		}
  488   		while (elementItr.hasNext()) {
  489   			OMElement mappingElement = (OMElement) elementItr.next();
  490   			String packageName = mappingElement.getAttributeValue(new QName(
  491   					TAG_PACKAGE_NAME));
  492   			String qName = mappingElement
  493   					.getAttributeValue(new QName(TAG_QNAME));
  494   			if (packageName == null || qName == null) {
  495   				continue;
  496   			}
  497   			Iterator keys = service.getNamespaceMap().keySet().iterator();
  498   			while (keys.hasNext()) {
  499   				String key = (String) keys.next();
  500   				if (qName.equals(service.getNamespaceMap().get(key))) {
  501   					typeTable.addComplexSchema(packageName, new QName(qName,
  502   							packageName, key));
  503   				}
  504   			}
  505   		}
  506   		service.setTypeTable(typeTable);
  507   	}
  508   
  509   	private void loadServiceLifeCycleClass(String className)
  510   			throws DeploymentException {
  511   		if (className != null) {
  512   			try {
  513   				ClassLoader loader = service.getClassLoader();
  514   				Class serviceLifeCycleClassImpl = Loader.loadClass(loader,
  515   						className);
  516   				ServiceLifeCycle serviceLifeCycle = (ServiceLifeCycle) serviceLifeCycleClassImpl
  517   						.newInstance();
  518   				serviceLifeCycle.startUp(configCtx, service);
  519   				service.setServiceLifeCycle(serviceLifeCycle);
  520   			} catch (Exception e) {
  521   				throw new DeploymentException(e.getMessage(), e);
  522   			}
  523   		}
  524   	}
  525   
  526   	private boolean generateWsdl(AxisService axisService) {
  527   		Iterator operatins = axisService.getOperations();
  528   		if (operatins.hasNext()) {
  529   			while (operatins.hasNext()) {
  530   				AxisOperation axisOperation = (AxisOperation) operatins.next();
  531   
  532   				if (axisOperation.isControlOperation()) {
  533   					continue;
  534   				}
  535   
  536   				if (axisOperation.getMessageReceiver() == null) {
  537   					continue;
  538   				}
  539   				String messageReceiverClass = axisOperation
  540   						.getMessageReceiver().getClass().getName();
  541   				if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
  542   						.equals(messageReceiverClass)
  543   						|| "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
  544   								.equals(messageReceiverClass)
  545   						|| "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
  546   								.equals(messageReceiverClass) || "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
  547   						.equals(messageReceiverClass))) {
  548   					return false;
  549   				}
  550   			}
  551   		}
  552   		return true;
  553   	}
  554   
  555   	/**
  556   	 * To get the methods which do not use RPC* MessageReceivers
  557   	 * 
  558   	 * @param axisService
  559   	 *            the AxisService to search
  560   	 * @return an ArrayList of the LOCAL PARTS of the QNames of any non-RPC
  561   	 *         operations TODO: Why not just return the AxisOperations
  562   	 *         themselves??
  563   	 */
  564   	private ArrayList getNonRPCMethods(AxisService axisService) {
  565   		ArrayList excludeOperations = new ArrayList();
  566   		Iterator operatins = axisService.getOperations();
  567   		if (operatins.hasNext()) {
  568   			while (operatins.hasNext()) {
  569   				AxisOperation axisOperation = (AxisOperation) operatins.next();
  570   				if (axisOperation.getMessageReceiver() == null) {
  571   					continue;
  572   				}
  573   				String messageReceiverClass = axisOperation
  574   						.getMessageReceiver().getClass().getName();
  575   				if (!("org.apache.axis2.rpc.receivers.RPCMessageReceiver"
  576   						.equals(messageReceiverClass)
  577   						|| "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"
  578   								.equals(messageReceiverClass)
  579   						|| "org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver"
  580   								.equals(messageReceiverClass) || "org.apache.axis2.jaxws.server.JAXWSMessageReceiver"
  581   						.equals(messageReceiverClass))) {
  582   					excludeOperations.add(axisOperation.getName()
  583   							.getLocalPart());
  584   				}
  585   			}
  586   		}
  587   		return excludeOperations;
  588   	}
  589   
  590   	/**
  591   	 * Process &lt;excludeOperation&gt; element in services.xml. Each operation
  592   	 * referenced will be removed from the AxisService.
  593   	 * 
  594   	 * @param excludeOperations
  595   	 *            the &lt;excludeOperations&gt; element from services.xml
  596   	 * @return an ArrayList of the String contents of the &lt;operation&gt;
  597   	 *         elements
  598   	 */
  599   	private ArrayList processExcludeOperations(OMElement excludeOperations) {
  600   		ArrayList exOps = new ArrayList();
  601   		Iterator excludeOp_itr = excludeOperations
  602   				.getChildrenWithName(new QName(TAG_OPERATION));
  603   		while (excludeOp_itr.hasNext()) {
  604   			OMElement opName = (OMElement) excludeOp_itr.next();
  605   			exOps.add(opName.getText().trim());
  606   		}
  607   		return exOps;
  608   	}
  609   
  610   	private void processMessages(Iterator messages, AxisOperation operation)
  611   			throws DeploymentException {
  612   		while (messages.hasNext()) {
  613   			OMElement messageElement = (OMElement) messages.next();
  614   			OMAttribute label = messageElement
  615   					.getAttribute(new QName(TAG_LABEL));
  616   
  617   			if (label == null) {
  618   				throw new DeploymentException(Messages
  619   						.getMessage("messagelabelcannotfound"));
  620   			}
  621   
  622   			AxisMessage message = operation.getMessage(label
  623   					.getAttributeValue());
  624   
  625   			Iterator parameters = messageElement.getChildrenWithName(new QName(
  626   					TAG_PARAMETER));
  627   
  628   			// processing <wsp:Policy> .. </..> elements
  629   			Iterator policyElements = messageElement
  630   					.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
  631   
  632   			if (policyElements != null) {
  633   				processPolicyElements(policyElements, message.getPolicySubject());
  634   			}
  635   
  636   			// processing <wsp:PolicyReference> .. </..> elements
  637   			Iterator policyRefElements = messageElement
  638   					.getChildrenWithName(new QName(POLICY_NS_URI,
  639   							TAG_POLICY_REF));
  640   
  641   			if (policyRefElements != null) {
  642   				processPolicyRefElements(policyRefElements, message.getPolicySubject());
  643   			}
  644   
  645   			processParameters(parameters, message, operation);
  646   
  647   		}
  648   	}
  649   
  650   	/**
  651   	 * Gets the list of modules that is required to be engaged globally.
  652   	 * 
  653   	 * @param moduleRefs
  654   	 *            <code>java.util.Iterator</code>
  655   	 * @throws DeploymentException
  656   	 *             <code>DeploymentException</code>
  657   	 */
  658   	protected void processModuleRefs(Iterator moduleRefs)
  659   			throws DeploymentException {
  660   		try {
  661   			while (moduleRefs.hasNext()) {
  662   				OMElement moduleref = (OMElement) moduleRefs.next();
  663   				OMAttribute moduleRefAttribute = moduleref
  664   						.getAttribute(new QName(TAG_REFERENCE));
  665   
  666   				if (moduleRefAttribute != null) {
  667   					String refName = moduleRefAttribute.getAttributeValue();
  668   
  669   					if (axisConfig.getModule(refName) == null) {
  670   						throw new DeploymentException(Messages.getMessage(
  671   								DeploymentErrorMsgs.MODULE_NOT_FOUND, refName));
  672   					} else {
  673   						service.addModuleref(refName);
  674   					}
  675   				}
  676   			}
  677   		} catch (AxisFault axisFault) {
  678   			throw new DeploymentException(axisFault);
  679   		}
  680   	}
  681   
  682   	protected void processOperationModuleConfig(Iterator moduleConfigs,
  683   			ParameterInclude parent, AxisOperation operation)
  684   			throws DeploymentException {
  685   		while (moduleConfigs.hasNext()) {
  686   			OMElement moduleConfig = (OMElement) moduleConfigs.next();
  687   			OMAttribute moduleName_att = moduleConfig.getAttribute(new QName(
  688   					ATTRIBUTE_NAME));
  689   
  690   			if (moduleName_att == null) {
  691   				throw new DeploymentException(Messages
  692   						.getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
  693   			} else {
  694   				String module = moduleName_att.getAttributeValue();
  695   				ModuleConfiguration moduleConfiguration = new ModuleConfiguration(
  696   						module, parent);
  697   				Iterator parameters = moduleConfig
  698   						.getChildrenWithName(new QName(TAG_PARAMETER));
  699   
  700   				processParameters(parameters, moduleConfiguration, parent);
  701   				operation.addModuleConfig(moduleConfiguration);
  702   			}
  703   		}
  704   	}
  705   
  706   	private ArrayList processOperations(Iterator operationsIterator)
  707   			throws AxisFault {
  708   		ArrayList operations = new ArrayList();
  709   		while (operationsIterator.hasNext()) {
  710   			OMElement operation = (OMElement) operationsIterator.next();
  711   			// getting operation name
  712   			OMAttribute op_name_att = operation.getAttribute(new QName(
  713   					ATTRIBUTE_NAME));
  714   			if (op_name_att == null) {
  715   				throw new DeploymentException(Messages.getMessage(Messages
  716   						.getMessage(DeploymentErrorMsgs.INVALID_OP,
  717   								"operation name missing")));
  718   			}
  719   
  720   			// setting the MEP of the operation
  721   			OMAttribute op_mep_att = operation.getAttribute(new QName(TAG_MEP));
  722   			String mepurl = null;
  723   
  724   			if (op_mep_att != null) {
  725   				mepurl = op_mep_att.getAttributeValue();
  726   			}
  727   
  728   			String opname = op_name_att.getAttributeValue();
  729   			AxisOperation op_descrip = null;
  730   
  731   			// getting the namesapce from the attribute.
  732   			OMAttribute operationNamespace = operation.getAttribute(new QName(
  733   					ATTRIBUTE_NAMESPACE));
  734   			if (operationNamespace != null) {
  735   				String namespace = operationNamespace.getAttributeValue();
  736   				op_descrip = service.getOperation(new QName(namespace, opname));
  737   			}
  738   			if (op_descrip == null) {
  739   				op_descrip = service.getOperation(new QName(opname));
  740   			}
  741   
  742   			if (op_descrip == null) {
  743   				op_descrip = service.getOperation(new QName(service
  744   						.getTargetNamespace(), opname));
  745   			}
  746   			if (op_descrip == null) {
  747   				if (mepurl == null) {
  748   					// assumed MEP is in-out
  749   					op_descrip = new InOutAxisOperation();
  750   					op_descrip.setParent(service);
  751   
  752   				} else {
  753   					op_descrip = AxisOperationFactory
  754   							.getOperationDescription(mepurl);
  755   				}
  756   				op_descrip.setName(new QName(opname));
  757   				String MEP = op_descrip.getMessageExchangePattern();
  758   				if (WSDL2Constants.MEP_URI_IN_ONLY.equals(MEP)
  759   						|| WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT.equals(MEP)
  760   						|| WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN.equals(MEP)
  761   						|| WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY.equals(MEP)
  762   						|| WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(MEP)
  763   						|| WSDL2Constants.MEP_URI_IN_OUT.equals(MEP)) {
  764   					AxisMessage inaxisMessage = op_descrip
  765   							.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
  766   					if (inaxisMessage != null) {
  767   						inaxisMessage.setName(opname
  768   								+ Java2WSDLConstants.MESSAGE_SUFFIX);
  769   					}
  770   				}
  771   
  772   				if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(MEP)
  773   						|| WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN.equals(MEP)
  774   						|| WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT.equals(MEP)
  775   						|| WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY.equals(MEP)
  776   						|| WSDL2Constants.MEP_URI_IN_OUT.equals(MEP)) {
  777   					AxisMessage outAxisMessage = op_descrip
  778   							.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
  779   					if (outAxisMessage != null) {
  780   						outAxisMessage.setName(opname
  781   								+ Java2WSDLConstants.RESPONSE);
  782   					}
  783   				}
  784   			}
  785   
  786   			// setting the PolicyInclude
  787   
  788   			// processing <wsp:Policy> .. </..> elements
  789   			Iterator policyElements = operation.getChildrenWithName(new QName(
  790   					POLICY_NS_URI, TAG_POLICY));
  791   
  792   			if (policyElements != null && policyElements.hasNext()) {
  793   				processPolicyElements(policyElements, op_descrip.getPolicySubject());
  794   			}
  795   
  796   			// processing <wsp:PolicyReference> .. </..> elements
  797   			Iterator policyRefElements = operation
  798   					.getChildrenWithName(new QName(POLICY_NS_URI,
  799   							TAG_POLICY_REF));
  800   
  801   			if (policyRefElements != null && policyRefElements.hasNext()) {
  802   				processPolicyRefElements(policyRefElements, op_descrip.getPolicySubject());
  803   			}
  804   
  805   			// Operation Parameters
  806   			Iterator parameters = operation.getChildrenWithName(new QName(
  807   					TAG_PARAMETER));
  808   			processParameters(parameters, op_descrip, service);
  809   			// To process wsamapping;
  810   			processActionMappings(operation, op_descrip);
  811   
  812   			// loading the message receivers
  813   			OMElement receiverElement = operation
  814   					.getFirstChildWithName(new QName(TAG_MESSAGE_RECEIVER));
  815   
  816   			if (receiverElement != null) {
  817   				MessageReceiver messageReceiver = loadMessageReceiver(service
  818   						.getClassLoader(), receiverElement);
  819   
  820   				op_descrip.setMessageReceiver(messageReceiver);
  821   			} else {
  822   				// setting default message receiver
  823   				MessageReceiver msgReceiver = loadDefaultMessageReceiver(
  824   						op_descrip.getMessageExchangePattern(), service);
  825   				op_descrip.setMessageReceiver(msgReceiver);
  826   			}
  827   
  828   			// Process Module Refs
  829   			Iterator modules = operation.getChildrenWithName(new QName(
  830   					TAG_MODULE));
  831   
  832   			processOperationModuleRefs(modules, op_descrip);
  833   
  834   			// processing Messages
  835   			Iterator messages = operation.getChildrenWithName(new QName(
  836   					TAG_MESSAGE));
  837   
  838   			processMessages(messages, op_descrip);
  839   
  840   			// setting Operation phase
  841   			if (axisConfig != null) {
  842   				PhasesInfo info = axisConfig.getPhasesInfo();
  843   
  844   				info.setOperationPhases(op_descrip);
  845   			}
  846   			Iterator moduleConfigs = operation.getChildrenWithName(new QName(
  847   					TAG_MODULE_CONFIG));
  848   			processOperationModuleConfig(moduleConfigs, op_descrip, op_descrip);
  849   			// adding the operation
  850   			operations.add(op_descrip);
  851   		}
  852   		return operations;
  853   	}
  854   
  855   	protected void processServiceModuleConfig(Iterator moduleConfigs,
  856   			ParameterInclude parent, AxisService service)
  857   			throws DeploymentException {
  858   		while (moduleConfigs.hasNext()) {
  859   			OMElement moduleConfig = (OMElement) moduleConfigs.next();
  860   			OMAttribute moduleName_att = moduleConfig.getAttribute(new QName(
  861   					ATTRIBUTE_NAME));
  862   
  863   			if (moduleName_att == null) {
  864   				throw new DeploymentException(Messages
  865   						.getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
  866   			} else {
  867   				String module = moduleName_att.getAttributeValue();
  868   				ModuleConfiguration moduleConfiguration = new ModuleConfiguration(
  869   						module, parent);
  870   				Iterator parameters = moduleConfig
  871   						.getChildrenWithName(new QName(TAG_PARAMETER));
  872   
  873   				processParameters(parameters, moduleConfiguration, parent);
  874   				service.addModuleConfig(moduleConfiguration);
  875   			}
  876   		}
  877   	}
  878   
  879   	/*
  880   	 * process data locator configuration for data retrieval.
  881   	 */
  882   	private void processDataLocatorConfig(OMElement dataLocatorElement,
  883   			AxisService service) {
  884   		OMAttribute serviceOverallDataLocatorclass = dataLocatorElement
  885   				.getAttribute(new QName(DRConstants.CLASS_ATTRIBUTE));
  886   		if (serviceOverallDataLocatorclass != null) {
  887   			String className = serviceOverallDataLocatorclass
  888   					.getAttributeValue();
  889   			service.addDataLocatorClassNames(DRConstants.SERVICE_LEVEL,
  890   					className);
  891   		}
  892   		Iterator iterator = dataLocatorElement.getChildrenWithName(new QName(
  893   				DRConstants.DIALECT_LOCATOR_ELEMENT));
  894   
  895   		while (iterator.hasNext()) {
  896   			OMElement locatorElement = (OMElement) iterator.next();
  897   			OMAttribute dialect = locatorElement.getAttribute(new QName(
  898   					DRConstants.DIALECT_ATTRIBUTE));
  899   			OMAttribute dialectclass = locatorElement.getAttribute(new QName(
  900   					DRConstants.CLASS_ATTRIBUTE));
  901   			service.addDataLocatorClassNames(dialect.getAttributeValue(),
  902   					dialectclass.getAttributeValue());
  903   
  904   		}
  905   
  906   	}
  907   
  908   	public void setWsdlServiceMap(HashMap wsdlServiceMap) {
  909   		this.wsdlServiceMap = wsdlServiceMap;
  910   	}
  911   
  912   	private void processEndpoints(AxisService axisService) throws AxisFault {
  913   		String endpointName = axisService.getEndpointName();
  914   		if (endpointName == null || endpointName.length() == 0) {
  915   			Utils.addEndpointsToService(axisService, service.getAxisConfiguration());
  916   		}
  917   	}
  918   	
  919   	private void processPolicyAttachments(OMElement serviceElement, AxisService service) throws DeploymentException {
  920   		Iterator attachmentElements = serviceElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_ATTACHMENT));
  921   		try {
  922   			Utils.processPolicyAttachments(attachmentElements, service);
  923   		} catch (Exception e) {
  924   			throw new DeploymentException(e);
  925   		}
  926   	}
  927   
  928   }

Save This Page
Home » axis2-1.5-src » org.apache » axis2 » deployment » [javadoc | source]