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
21 package org.apache.axis2.deployment;
22
23 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
24 import org.apache.axiom.om.OMAttribute;
25 import org.apache.axiom.om.OMElement;
26 import org.apache.axiom.soap.RolePlayer;
27 import org.apache.axis2.AxisFault;
28 import org.apache.axis2.Constants;
29 import org.apache.axis2.transaction.TransactionConfiguration;
30 import org.apache.axis2.builder.ApplicationXMLBuilder;
31 import org.apache.axis2.builder.Builder;
32 import org.apache.axis2.builder.MIMEBuilder;
33 import org.apache.axis2.builder.MTOMBuilder;
34 import org.apache.axis2.builder.SOAPBuilder;
35 import org.apache.axis2.builder.XFormURLEncodedBuilder;
36 import org.apache.axis2.dataretrieval.DRConstants;
37 import org.apache.axis2.deployment.util.PhasesInfo;
38 import org.apache.axis2.deployment.util.Utils;
39 import org.apache.axis2.description;
40 import org.apache.axis2.engine.AxisConfiguration;
41 import org.apache.axis2.engine.AxisObserver;
42 import org.apache.axis2.engine.MessageReceiver;
43 import org.apache.axis2.engine.Phase;
44 import org.apache.axis2.i18n.Messages;
45 import org.apache.axis2.phaseresolver.PhaseException;
46 import org.apache.axis2.transport.MessageFormatter;
47 import org.apache.axis2.transport.TransportListener;
48 import org.apache.axis2.transport.TransportSender;
49 import org.apache.axis2.util.JavaUtils;
50 import org.apache.axis2.util.Loader;
51 import org.apache.axis2.util.TargetResolver;
52 import org.apache.axis2.util.ThreadContextMigrator;
53 import org.apache.axis2.util.ThreadContextMigratorUtil;
54 import org.apache.commons.logging.Log;
55 import org.apache.commons.logging.LogFactory;
56
57 import javax.xml.namespace.QName;
58 import javax.xml.stream.XMLStreamException;
59 import java.io.InputStream;
60 import java.security.PrivilegedActionException;
61 import java.security.PrivilegedExceptionAction;
62 import java.util.ArrayList;
63 import java.util.Collections;
64 import java.util.HashMap;
65 import java.util.Iterator;
66 import java.util.List;
67 import java.util.Map;
68
69 public class AxisConfigBuilder extends DescriptionBuilder {
70
71 protected static final Log log = LogFactory.getLog(AxisConfigBuilder.class);
72 private DeploymentEngine deploymentEngine;
73
74 public AxisConfigBuilder(InputStream serviceInputStream,
75 AxisConfiguration axisConfiguration,
76 DeploymentEngine deploymentEngine) {
77 super(serviceInputStream, axisConfiguration);
78 this.deploymentEngine = deploymentEngine;
79 }
80
81
82 public AxisConfigBuilder(AxisConfiguration axisConfiguration) {
83 this.axisConfig = axisConfiguration;
84 }
85
86 public void populateConfig() throws DeploymentException {
87 try {
88 OMElement config_element = buildOM();
89
90 if (!TAG_AXISCONFIG.equals(config_element.getLocalName())) {
91 throw new DeploymentException(Messages.getMessage("badelementfound", TAG_AXISCONFIG,
92 config_element.getLocalName()));
93 }
94 // processing Parameters
95 // Processing service level parameters
96 Iterator itr = config_element.getChildrenWithName(new QName(TAG_PARAMETER));
97
98 processParameters(itr, axisConfig, axisConfig);
99
100 // process MessageReceiver
101 OMElement messageReceiver =
102 config_element.getFirstChildWithName(new QName(TAG_MESSAGE_RECEIVERS));
103 if (messageReceiver != null) {
104 HashMap mrs = processMessageReceivers(messageReceiver);
105 Iterator keys = mrs.keySet().iterator();
106 while (keys.hasNext()) {
107 String key = (String) keys.next();
108 axisConfig.addMessageReceiver(key, (MessageReceiver) mrs.get(key));
109 }
110 }
111 // Process Module refs
112 Iterator moduleitr =
113 config_element.getChildrenWithName(new QName(DeploymentConstants.TAG_MODULE));
114
115 processModuleRefs(moduleitr, axisConfig);
116
117 // Processing Transport Senders
118 Iterator trs_senders =
119 config_element.getChildrenWithName(new QName(TAG_TRANSPORT_SENDER));
120
121 processTransportSenders(trs_senders);
122
123 // Processing Transport Receivers
124 Iterator trs_Reivers =
125 config_element.getChildrenWithName(new QName(TAG_TRANSPORT_RECEIVER));
126
127 processTransportReceivers(trs_Reivers);
128
129 // Process TargetResolvers
130 OMElement targetResolvers =
131 config_element.getFirstChildWithName(new QName(TAG_TARGET_RESOLVERS));
132 processTargetResolvers(axisConfig, targetResolvers);
133
134 // Process ThreadContextMigrators
135 OMElement threadContextMigrators =
136 config_element.getFirstChildWithName(new QName(TAG_THREAD_CONTEXT_MIGRATORS));
137 processThreadContextMigrators(axisConfig, threadContextMigrators);
138
139 // Process Observers
140 Iterator obs_ittr = config_element.getChildrenWithName(new QName(TAG_LISTENER));
141
142 processObservers(obs_ittr);
143
144 // Processing Phase orders
145 Iterator phaseorders = config_element.getChildrenWithName(new QName(TAG_PHASE_ORDER));
146
147 processPhaseOrders(phaseorders);
148
149 Iterator moduleConfigs =
150 config_element.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
151
152 processModuleConfig(moduleConfigs, axisConfig, axisConfig);
153
154 // processing <wsp:Policy> .. </..> elements
155 Iterator policyElements = config_element.getChildrenWithName(new QName(POLICY_NS_URI,
156 TAG_POLICY));
157
158 if (policyElements != null && policyElements.hasNext()) {
159 processPolicyElements(policyElements,
160 axisConfig.getPolicySubject());
161 }
162
163 // processing <wsp:PolicyReference> .. </..> elements
164 Iterator policyRefElements = config_element.getChildrenWithName(new QName(POLICY_NS_URI,
165 TAG_POLICY_REF));
166
167 if (policyRefElements != null && policyRefElements.hasNext()) {
168 processPolicyRefElements(policyElements,
169 axisConfig.getPolicySubject());
170 }
171
172 //to process default module versions
173 OMElement defaultModuleVerionElement = config_element.getFirstChildWithName(new QName(
174 TAG_DEFAULT_MODULE_VERSION));
175 if (defaultModuleVerionElement != null) {
176 processDefaultModuleVersions(defaultModuleVerionElement);
177 }
178
179 OMElement clusterElement = config_element
180 .getFirstChildWithName(new QName(TAG_CLUSTER));
181 if (clusterElement != null) {
182 ClusterBuilder clusterBuilder = new ClusterBuilder(axisConfig);
183 clusterBuilder.buildCluster(clusterElement);
184 }
185
186 //Add jta transaction configuration
187 OMElement transactionElement = config_element
188 .getFirstChildWithName(new QName(TAG_TRANSACTION));
189 if (transactionElement != null) {
190 ParameterInclude transactionParameters = new ParameterIncludeImpl();
191 Iterator parameters = transactionElement.getChildrenWithName(new QName(TAG_PARAMETER));
192 processParameters(parameters, transactionParameters, null);
193 TransactionConfiguration txcfg = new TransactionConfiguration(transactionParameters);
194
195 OMAttribute timeoutAttribute = transactionElement.getAttribute(new QName(TAG_TIMEOUT));
196 if(timeoutAttribute != null) {
197 txcfg.setTransactionTimeout(Integer.parseInt(timeoutAttribute.getAttributeValue()));
198 }
199
200 axisConfig.setTransactionConfig(txcfg);
201 }
202
203
204 /*
205 * Add Axis2 default builders if they are not overidden by the config
206 */
207 axisConfig.addMessageBuilder("multipart/related", new MIMEBuilder());
208 axisConfig.addMessageBuilder("application/soap+xml", new SOAPBuilder());
209 axisConfig.addMessageBuilder("text/xml", new SOAPBuilder());
210 axisConfig.addMessageBuilder("application/xop+xml", new MTOMBuilder());
211 axisConfig.addMessageBuilder("application/xml", new ApplicationXMLBuilder());
212 axisConfig.addMessageBuilder("application/x-www-form-urlencoded",
213 new XFormURLEncodedBuilder());
214 // process MessageBuilders
215 OMElement messageBuildersElement =
216 config_element.getFirstChildWithName(new QName(TAG_MESSAGE_BUILDERS));
217 if (messageBuildersElement != null) {
218 HashMap builderSelector = processMessageBuilders(messageBuildersElement);
219 Iterator keys = builderSelector.keySet().iterator();
220 while (keys.hasNext()) {
221 String key = (String) keys.next();
222 axisConfig.addMessageBuilder(key, (Builder) builderSelector.get(key));
223 }
224 }
225
226
227 //process dataLocator configuration
228 OMElement dataLocatorElement =
229 config_element
230 .getFirstChildWithName(new QName(DRConstants.DATA_LOCATOR_ELEMENT));
231
232 if (dataLocatorElement != null) {
233 processDataLocatorConfig(dataLocatorElement);
234 }
235
236 // process roleplayer configuration
237 OMElement rolePlayerElement =
238 config_element
239 .getFirstChildWithName(new QName(Constants.SOAP_ROLE_CONFIGURATION_ELEMENT));
240
241 if (rolePlayerElement != null) {
242 processSOAPRoleConfig(axisConfig, rolePlayerElement);
243 }
244
245 // process MessageFormatters
246 OMElement messageFormattersElement =
247 config_element.getFirstChildWithName(new QName(TAG_MESSAGE_FORMATTERS));
248 if (messageFormattersElement != null) {
249 HashMap messageFormatters = processMessageFormatters(messageFormattersElement);
250 Iterator keys = messageFormatters.keySet().iterator();
251 while (keys.hasNext()) {
252 String key = (String) keys.next();
253 axisConfig.addMessageFormatter(key,
254 (MessageFormatter) messageFormatters.get(key));
255 }
256 }
257 //Processing deployers.
258 Iterator deployerItr = config_element.getChildrenWithName(new QName(DEPLOYER));
259 if (deployerItr != null) {
260 processDeployers(deployerItr);
261 }
262
263 //process Attachments Lifecycle manager configuration
264 OMElement attachmentsLifecycleManagerElement =
265 config_element
266 .getFirstChildWithName(new QName(ATTACHMENTS_LIFECYCLE_MANAGER));
267
268 if (attachmentsLifecycleManagerElement != null) {
269 processAttachmentsLifecycleManager(axisConfig, attachmentsLifecycleManagerElement);
270 }
271 } catch (XMLStreamException e) {
272 throw new DeploymentException(e);
273 }
274 }
275
276 private void processTargetResolvers(AxisConfiguration axisConfig, OMElement targetResolvers) {
277 if (targetResolvers != null) {
278 Iterator iterator = targetResolvers.getChildrenWithName(new QName(TAG_TARGET_RESOLVER));
279 while (iterator.hasNext()) {
280 OMElement targetResolver = (OMElement) iterator.next();
281 OMAttribute classNameAttribute =
282 targetResolver.getAttribute(new QName(TAG_CLASS_NAME));
283 String className = classNameAttribute.getAttributeValue();
284 try {
285 Class classInstance = Loader.loadClass(className);
286 TargetResolver tr = (TargetResolver) classInstance.newInstance();
287 axisConfig.addTargetResolver(tr);
288 } catch (Exception e) {
289 if (log.isTraceEnabled()) {
290 log.trace(
291 "processTargetResolvers: Exception thrown initialising TargetResolver: " +
292 e.getMessage());
293 }
294 }
295 }
296 }
297 }
298
299 private void processThreadContextMigrators(AxisConfiguration axisConfig, OMElement targetResolvers) {
300 if (targetResolvers != null) {
301 Iterator iterator = targetResolvers.getChildrenWithName(new QName(TAG_THREAD_CONTEXT_MIGRATOR));
302 while (iterator.hasNext()) {
303 OMElement threadContextMigrator = (OMElement) iterator.next();
304 OMAttribute listIdAttribute =
305 threadContextMigrator.getAttribute(new QName(TAG_LIST_ID));
306 String listId = listIdAttribute.getAttributeValue();
307 OMAttribute classNameAttribute =
308 threadContextMigrator.getAttribute(new QName(TAG_CLASS_NAME));
309 String className = classNameAttribute.getAttributeValue();
310 try {
311 Class clazz = Loader.loadClass(className);
312 ThreadContextMigrator migrator = (ThreadContextMigrator) clazz.newInstance();
313 ThreadContextMigratorUtil.addThreadContextMigrator(axisConfig, listId, migrator);
314 } catch (UnsupportedClassVersionError e){
315 log.info("Disabled - " + className + " - " + e.getMessage());
316 } catch (Exception e) {
317 if (log.isTraceEnabled()) {
318 log.trace(
319 "processThreadContextMigrators: Exception thrown initialising ThreadContextMigrator: " +
320 e.getMessage());
321 }
322 }
323 }
324 }
325 }
326
327 private void processAttachmentsLifecycleManager(AxisConfiguration axisConfig, OMElement element) {
328 String className = element.getAttributeValue(new QName(TAG_CLASS_NAME));
329 try {
330 Class classInstance = Loader.loadClass(className);
331 LifecycleManager manager = (LifecycleManager) classInstance.newInstance();
332 axisConfig.addParameter(DeploymentConstants.ATTACHMENTS_LIFECYCLE_MANAGER, manager);
333 } catch (Exception e) {
334 if (log.isTraceEnabled()) {
335 log.trace(
336 "processAttachmentsLifecycleManager: Exception thrown initialising LifecycleManager: " +
337 e.getMessage());
338 }
339 }
340 }
341
342 private void processSOAPRoleConfig(AxisConfiguration axisConfig, OMElement soaproleconfigElement) {
343 if (soaproleconfigElement != null) {
344 final boolean isUltimateReceiever = JavaUtils.isTrue(soaproleconfigElement.getAttributeValue(new QName(Constants.SOAP_ROLE_IS_ULTIMATE_RECEIVER_ATTRIBUTE)), true);
345 ArrayList roles = new ArrayList();
346 Iterator iterator = soaproleconfigElement.getChildrenWithName(new QName(Constants.SOAP_ROLE_ELEMENT));
347 while (iterator.hasNext()) {
348 OMElement roleElement = (OMElement) iterator.next();
349 roles.add(roleElement.getText());
350 }
351 final List unmodifiableRoles = Collections.unmodifiableList(roles);
352 try{
353 RolePlayer rolePlayer = new RolePlayer(){
354 public List getRoles() {
355 return unmodifiableRoles;
356 }
357 public boolean isUltimateDestination() {
358 return isUltimateReceiever;
359 }
360 };
361 axisConfig.addParameter("rolePlayer", rolePlayer);
362 } catch (AxisFault e) {
363 if (log.isTraceEnabled()) {
364 log.trace(
365 "processTargetResolvers: Exception thrown initialising TargetResolver: " +
366 e.getMessage());
367 }
368 }
369 }
370 }
371
372 private void processDeployers(Iterator deployerItr) {
373 HashMap extensionToDeployerMappingMap = new HashMap();
374 Map<String, Map<String, Deployer>> deployers = new HashMap<String, Map<String, Deployer>>();
375 while (deployerItr.hasNext()) {
376 OMElement element = (OMElement) deployerItr.next();
377 String directory = element.getAttributeValue(new QName(DIRECTORY));
378 if (directory == null) {
379 log.error("Deployer missing 'directory' attribute : " + element.toString());
380 continue;
381 }
382
383 String extension = element.getAttributeValue(new QName(EXTENSION));
384 if (extension == null) {
385 log.error("Deployer missing 'extension' attribute : " + element.toString());
386 continue;
387 }
388
389 // A leading dot is redundant, so strip it. So we allow either ".foo" or "foo", either
390 // of which will result in extension="foo"
391 if (extension.charAt(0) == '.') extension = extension.substring(1);
392
393 String deployerClassName = element.getAttributeValue(new QName(TAG_CLASS_NAME));
394 Deployer deployer;
395 try {
396 Class deployerClass = Loader.loadClass(deployerClassName);
397 deployer = (Deployer) deployerClass.newInstance();
398 } catch (UnsupportedClassVersionError ex) {
399 log.info("Disabled - " + deployerClassName + " - " + ex.getMessage());
400 continue;
401 } catch (Exception e) {
402 log.info("Unable to instantiate deployer " + deployerClassName);
403 log.debug(e.getMessage(), e);
404 continue;
405 }
406 deployer.setDirectory(directory);
407 deployer.setExtension(extension);
408
409 Map<String, Deployer> extensionMap = deployers.get(directory);
410 if (extensionMap == null) {
411 extensionMap = new HashMap<String, Deployer>();
412 deployers.put(directory, extensionMap);
413 }
414 extensionMap.put(extension, deployer);
415 extensionToDeployerMappingMap.put(extension, deployer);
416 }
417 if (deploymentEngine != null) {
418 deploymentEngine.setExtensionToDeployerMappingMap(extensionToDeployerMappingMap);
419 deploymentEngine.setDeployers(deployers);
420 }
421 }
422
423 protected void processModuleConfig(Iterator moduleConfigs, ParameterInclude parent,
424 AxisConfiguration config)
425 throws DeploymentException {
426 while (moduleConfigs.hasNext()) {
427 OMElement moduleConfig = (OMElement) moduleConfigs.next();
428 OMAttribute moduleName_att = moduleConfig.getAttribute(new QName(ATTRIBUTE_NAME));
429
430 if (moduleName_att == null) {
431 throw new DeploymentException(
432 Messages.getMessage(DeploymentErrorMsgs.INVALID_MODULE_CONFIG));
433 } else {
434 String module = moduleName_att.getAttributeValue();
435 ModuleConfiguration moduleConfiguration =
436 new ModuleConfiguration(module, parent);
437 Iterator parameters = moduleConfig.getChildrenWithName(new QName(TAG_PARAMETER));
438
439 processParameters(parameters, moduleConfiguration, parent);
440 config.addModuleConfig(moduleConfiguration);
441 }
442 }
443 }
444
445 /**
446 * Update the list of modules that is required to be engaged globally.
447 */
448 protected void processModuleRefs(Iterator moduleRefs, AxisConfiguration config) {
449 while (moduleRefs.hasNext()) {
450 OMElement moduleref = (OMElement) moduleRefs.next();
451 OMAttribute moduleRefAttribute = moduleref.getAttribute(new QName(TAG_REFERENCE));
452 String refName = moduleRefAttribute.getAttributeValue();
453 axisConfig.addGlobalModuleRef(refName);
454 }
455 }
456
457 /**
458 * Processes AxisObservers.
459 *
460 * @param oservers
461 */
462 private void processObservers(Iterator oservers) {
463 while (oservers.hasNext()) {
464 try {
465 OMElement observerelement = (OMElement) oservers.next();
466 AxisObserver observer;
467 OMAttribute trsClas = observerelement.getAttribute(new QName(TAG_CLASS_NAME));
468 if (trsClas == null) {
469 log.info(Messages.getMessage(DeploymentErrorMsgs.OBSERVER_ERROR));
470 return;
471 }
472 final String clasName = trsClas.getAttributeValue();
473
474 Class observerclass;
475 try {
476 observerclass = (Class) org.apache.axis2.java.security.AccessController
477 .doPrivileged(new PrivilegedExceptionAction() {
478 public Object run() throws ClassNotFoundException {
479 return Loader.loadClass(clasName);
480 }
481 });
482 } catch (PrivilegedActionException e) {
483 throw (ClassNotFoundException) e.getException();
484 }
485 observer = (AxisObserver) observerclass.newInstance();
486 // processing Parameters
487 // Processing service level parameters
488 Iterator itr = observerelement.getChildrenWithName(new QName(TAG_PARAMETER));
489 processParameters(itr, observer, axisConfig);
490 // initialization
491 try {
492 observer.init(axisConfig);
493 } catch (Throwable e) {
494 //Observer init may throw runtime exception , but we can stil
495 // start Axis2
496 log.info(e.getMessage());
497 }
498 axisConfig.addObservers(observer);
499 } catch (Exception e) {
500 log.info(e.getMessage());
501 }
502 }
503 }
504
505 private ArrayList processPhaseList(OMElement phaseOrders) throws DeploymentException {
506 ArrayList phaselist = new ArrayList();
507 Iterator phases = phaseOrders.getChildrenWithName(new QName(TAG_PHASE));
508
509 while (phases.hasNext()) {
510 OMElement phaseelement = (OMElement) phases.next();
511 String phaseName =
512 phaseelement.getAttribute(new QName(ATTRIBUTE_NAME)).getAttributeValue();
513 String phaseClass = phaseelement.getAttributeValue(new QName(TAG_CLASS_NAME));
514 Phase phase;
515
516 try {
517 phase = getPhase(phaseClass);
518 } catch (Exception e) {
519 throw new DeploymentException(
520 Messages.getMessage("phaseclassnotfound", phaseClass, e.getMessage()));
521 }
522
523 phase.setName(phaseName);
524
525 Iterator handlers = phaseelement.getChildrenWithName(new QName(TAG_HANDLER));
526
527 while (handlers.hasNext()) {
528 OMElement omElement = (OMElement) handlers.next();
529 HandlerDescription handler = processHandler(omElement, axisConfig, phaseName);
530
531 handler.getRules().setPhaseName(phaseName);
532 try {
533 if (Utils.loadHandler(axisConfig.getSystemClassLoader(), handler)) {
534 try {
535 phase.addHandler(handler);
536 } catch (PhaseException e) {
537 throw new DeploymentException(e);
538 }
539 }
540 } catch (UnsupportedClassVersionError e) {
541 log.info("Disabled - " + handler + " - " + e.getMessage());
542 }
543 }
544
545 phaselist.add(phase);
546 }
547
548 return phaselist;
549 }
550
551 /**
552 * Processes all the phase orders which are defined in axis2.xml.
553 *
554 * @param phaserders
555 */
556 private void processPhaseOrders(Iterator phaserders) throws DeploymentException {
557 PhasesInfo info = axisConfig.getPhasesInfo();
558
559 while (phaserders.hasNext()) {
560 OMElement phaseOrders = (OMElement) phaserders.next();
561 String flowType = phaseOrders.getAttribute(new QName(TAG_TYPE)).getAttributeValue();
562
563 if (TAG_FLOW_IN.equals(flowType)) {
564 info.setINPhases(processPhaseList(phaseOrders));
565 } else if (TAG_FLOW_IN_FAULT.equals(flowType)) {
566 info.setIN_FaultPhases(processPhaseList(phaseOrders));
567 } else if (TAG_FLOW_OUT.equals(flowType)) {
568 info.setOUTPhases(processPhaseList(phaseOrders));
569 } else if (TAG_FLOW_OUT_FAULT.equals(flowType)) {
570 info.setOUT_FaultPhases(processPhaseList(phaseOrders));
571 }
572 }
573 }
574
575 private void processDefaultModuleVersions(OMElement defaultVersions)
576 throws DeploymentException {
577 Iterator moduleVersions = defaultVersions.getChildrenWithName(new QName(TAG_MODULE));
578 while (moduleVersions.hasNext()) {
579 OMElement omElement = (OMElement) moduleVersions.next();
580 String name = omElement.getAttributeValue(new QName(ATTRIBUTE_NAME));
581 if (name == null) {
582 throw new DeploymentException(Messages.getMessage("modulenamecannotbenull"));
583 }
584 String version =
585 omElement.getAttributeValue(new QName(ATTRIBUTE_DEFAULT_VERSION));
586 if (version == null) {
587 throw new DeploymentException(Messages.getMessage("moduleversioncannotbenull"));
588 }
589 axisConfig.addDefaultModuleVersion(name, version);
590 }
591 }
592
593 public ArrayList processTransportReceivers(Iterator trs_senders) throws DeploymentException {
594 ArrayList transportReceivers = new ArrayList();
595 while (trs_senders.hasNext()) {
596 TransportInDescription transportIN;
597 OMElement transport = (OMElement) trs_senders.next();
598 // getting transport Name
599 OMAttribute trsName = transport.getAttribute(new QName(ATTRIBUTE_NAME));
600 if (trsName != null) {
601 String name = trsName.getAttributeValue();
602 transportIN = new TransportInDescription(name);
603 // transport impl class
604 OMAttribute trsClas = transport.getAttribute(new QName(TAG_CLASS_NAME));
605 if (trsClas != null) {
606 try {
607 String clasName = trsClas.getAttributeValue();
608 Class receiverClass;
609 receiverClass = Loader.loadClass(clasName);
610
611 TransportListener receiver =
612 (TransportListener) receiverClass.newInstance();
613 transportIN.setReceiver(receiver);
614 } catch (NoClassDefFoundError e) {
615 if(deploymentEngine != null){
616 throw new DeploymentException(e);
617 } else {
618 // Called from createDefaultConfigurationContext in ConfigurationContextFactory
619 // Please don't throw an exception.
620 log.debug(Messages.getMessage("classnotfound", trsClas.getAttributeValue()));
621 }
622 } catch (ClassNotFoundException e) {
623 throw new DeploymentException(e);
624 } catch (IllegalAccessException e) {
625 throw new DeploymentException(e);
626 } catch (InstantiationException e) {
627 throw new DeploymentException(e);
628 }
629 }
630 try {
631 Iterator itr = transport.getChildrenWithName(new QName(TAG_PARAMETER));
632 processParameters(itr, transportIN, axisConfig);
633 // adding to axis2 config
634 axisConfig.addTransportIn(transportIN);
635 transportReceivers.add(transportIN);
636 } catch (AxisFault axisFault) {
637 throw new DeploymentException(axisFault);
638 }
639 }
640 }
641 return transportReceivers;
642 }
643
644 public void processTransportSenders(Iterator trs_senders) throws DeploymentException {
645 while (trs_senders.hasNext()) {
646 TransportOutDescription transportout;
647 OMElement transport = (OMElement) trs_senders.next();
648
649 // getting transport Name
650 OMAttribute trsName = transport.getAttribute(new QName(ATTRIBUTE_NAME));
651
652 if (trsName != null) {
653 String name = trsName.getAttributeValue();
654
655 transportout = new TransportOutDescription(name);
656
657 // transport impl class
658 OMAttribute trsClas = transport.getAttribute(new QName(TAG_CLASS_NAME));
659
660 if (trsClas == null) {
661 throw new DeploymentException(
662 Messages.getMessage(DeploymentErrorMsgs.TRANSPORT_SENDER_ERROR, name));
663 }
664
665 String clasName = trsClas.getAttributeValue();
666 Class sender;
667
668 try {
669 sender = Loader.loadClass(clasName);
670
671 TransportSender transportSender = (TransportSender) sender.newInstance();
672
673 transportout.setSender(transportSender);
674
675 // process Parameters
676 // processing Parameters
677 // Processing service level parameters
678 Iterator itr = transport.getChildrenWithName(new QName(TAG_PARAMETER));
679
680 processParameters(itr, transportout, axisConfig);
681 // adding to axis2 config
682 axisConfig.addTransportOut(transportout);
683 } catch (NoClassDefFoundError e) {
684 if(deploymentEngine != null){
685 log.debug(Messages.getMessage("errorinloadingts", clasName), e);
686 throw new DeploymentException(e);
687 } else {
688 // Called from createDefaultConfigurationContext in ConfigurationContextFactory
689 // Please don't throw an exception.
690 log.debug(Messages.getMessage("classnotfound", trsClas.getAttributeValue()));
691 }
692 } catch (ClassNotFoundException e) {
693 log.debug(Messages.getMessage("errorinloadingts", clasName), e);
694 throw new DeploymentException(e);
695 } catch (IllegalAccessException e) {
696 log.debug(Messages.getMessage("errorinloadingts", clasName), e);
697 throw new DeploymentException(e);
698 } catch (InstantiationException e) {
699 log.debug(Messages.getMessage("errorinloadingts", clasName), e);
700 throw new DeploymentException(e);
701 } catch (AxisFault axisFault) {
702 log.debug(Messages.getMessage("errorinloadingts", clasName), axisFault);
703 throw new DeploymentException(axisFault);
704 }
705 }
706 }
707 }
708
709 /*
710 * process data locator configuration for data retrieval.
711 */
712 private void processDataLocatorConfig(OMElement dataLocatorElement) {
713 OMAttribute serviceOverallDataLocatorclass = dataLocatorElement
714 .getAttribute(new QName(DRConstants.CLASS_ATTRIBUTE));
715 if (serviceOverallDataLocatorclass != null) {
716 String className = serviceOverallDataLocatorclass
717 .getAttributeValue();
718 axisConfig.addDataLocatorClassNames(DRConstants.GLOBAL_LEVEL,
719 className);
720 }
721 Iterator iterator = dataLocatorElement.getChildrenWithName(new QName(
722 DRConstants.DIALECT_LOCATOR_ELEMENT));
723
724 while (iterator.hasNext()) {
725 OMElement locatorElement = (OMElement) iterator.next();
726 OMAttribute dialect = locatorElement.getAttribute(new QName(
727 DRConstants.DIALECT_ATTRIBUTE));
728 OMAttribute dialectclass = locatorElement.getAttribute(new QName(
729 DRConstants.CLASS_ATTRIBUTE));
730 axisConfig.addDataLocatorClassNames(dialect.getAttributeValue(),
731 dialectclass.getAttributeValue());
732
733 }
734 }
735
736 protected HashMap processMessageFormatters(OMElement messageFormattersElement)
737 throws DeploymentException {
738 try {
739 return super.processMessageFormatters(messageFormattersElement);
740 } catch (NoClassDefFoundError e) {
741 if (deploymentEngine != null) {
742 throw new DeploymentException(e);
743 } else {
744 // Called from createDefaultConfigurationContext in ConfigurationContextFactory
745 // Please don't throw an exception.
746 return new HashMap();
747 }
748 }
749 }
750
751 protected HashMap processMessageBuilders(OMElement messageBuildersElement)
752 throws DeploymentException {
753 try {
754 return super.processMessageBuilders(messageBuildersElement);
755 } catch (NoClassDefFoundError e) {
756 if (deploymentEngine != null) {
757 throw new DeploymentException(e);
758 } else {
759 // Called from createDefaultConfigurationContext in ConfigurationContextFactory
760 // Please don't throw an exception.
761 return new HashMap();
762 }
763 }
764 }
765
766 private Phase getPhase(String className)
767 throws ClassNotFoundException, IllegalAccessException, InstantiationException {
768 if (className == null) {
769 return new Phase();
770 }
771 Class phaseClass = Loader.loadClass(axisConfig.getSystemClassLoader(), className);
772 return (Phase) phaseClass.newInstance();
773 }
774 }