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.description;
21
22 import org.apache.axiom.om.OMElement;
23 import org.apache.axis2.AxisFault;
24 import org.apache.axis2.Constants;
25 import org.apache.axis2.addressing.AddressingHelper;
26 import org.apache.axis2.addressing.EndpointReference;
27 import org.apache.axis2.client.Options;
28 import org.apache.axis2.client.ServiceClient;
29 import org.apache.axis2.context.MessageContext;
30 import org.apache.axis2.context.ServiceContext;
31 import org.apache.axis2.dataretrieval;
32 import org.apache.axis2.deployment.DeploymentConstants;
33 import org.apache.axis2.deployment.util.ExcludeInfo;
34 import org.apache.axis2.deployment.util.PhasesInfo;
35 import org.apache.axis2.deployment.util.Utils;
36 import org.apache.axis2.description.java2wsdl;
37 import org.apache.axis2.engine;
38 import org.apache.axis2.i18n.Messages;
39 import org.apache.axis2.phaseresolver.PhaseResolver;
40 import org.apache.axis2.transport.TransportListener;
41 import org.apache.axis2.util;
42 import org.apache.axis2.util.XMLUtils;
43 import org.apache.axis2.wsdl.WSDLConstants;
44 import org.apache.commons.logging.Log;
45 import org.apache.commons.logging.LogFactory;
46 import org.apache.neethi.Policy;
47 import org.apache.ws.commons.schema.XmlSchema;
48 import org.apache.ws.commons.schema.XmlSchemaElement;
49 import org.apache.ws.commons.schema.XmlSchemaExternal;
50 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
51 import org.apache.ws.commons.schema.utils.NamespaceMap;
52 import org.apache.ws.commons.schema.utils.NamespacePrefixList;
53 import org.w3c.dom;
54 import org.xml.sax.SAXException;
55
56 import javax.wsdl;
57 import javax.wsdl.extensions.http.HTTPAddress;
58 import javax.wsdl.extensions.schema.Schema;
59 import javax.wsdl.extensions.soap.SOAPAddress;
60 import javax.wsdl.extensions.soap12.SOAP12Address;
61 import javax.wsdl.factory.WSDLFactory;
62 import javax.wsdl.xml.WSDLReader;
63 import javax.wsdl.xml.WSDLWriter;
64 import javax.xml.namespace.QName;
65 import javax.xml.parsers.ParserConfigurationException;
66 import java.io;
67 import java.lang.reflect.Method;
68 import java.net.SocketException;
69 import java.net.URL;
70 import java.security.PrivilegedAction;
71 import java.util;
72 import java.util.concurrent.CopyOnWriteArrayList;
73
74 /**
75 * Class AxisService
76 */
77 public class AxisService extends AxisDescription {
78
79 // ////////////////////////////////////////////////////////////////
80 // Standard Parameter names
81
82 /**
83 * If this param is true, and the service has exactly one AxisOperation,
84 * normal operation dispatch (via URI/soapAction/etc) will not be necessary,
85 * and we'll just default to funneling all messages to that op. This is
86 * useful for passthrough/ESB/embedded applications.
87 */
88 public static final String SUPPORT_SINGLE_OP = "supportSingleOperation";
89 // ////////////////////////////////////////////////////////////////
90
91 public static final String IMPORT_TAG = "import";
92 public static final String INCLUDE_TAG = "include";
93 public static final String SCHEMA_LOCATION = "schemaLocation";
94
95 private Map<String, AxisEndpoint> endpointMap = new HashMap<String, AxisEndpoint>();
96
97 /*
98 * This is a map between the QName of the element of a message specified in
99 * the WSDL and an Operation. It enables SOAP Body-based dispatching for
100 * doc-literal bindings.
101 */
102 private Map<QName, AxisOperation> messageElementQNameToOperationMap = new HashMap<QName, AxisOperation>();
103
104 private int nsCount = 0;
105 private static final Log log = LogFactory.getLog(AxisService.class);
106 private URL fileName;
107
108 // Maps httpLocations to corresponding operations. Used to dispatch rest
109 // messages.
110 private HashMap<String, AxisOperation> httpLocationDispatcherMap = null;
111
112 // A map of (String alias, AxisOperation operation). The aliases might
113 // include: SOAPAction,
114 // WS-Addressing action, the operation name, the AxisInputMessage name. See:
115 // - invalidOperationsAliases
116 // - mapActionToOperatoin()
117 // - getOperationByAction()
118 // REVIEW: This really should be seperate maps for the different types of
119 // aliases so they don't
120 // conflict with each other. For example, so that an identical operation
121 // name and soap action
122 // on different operatoins don't cause a collision; the following can't be
123 // routed because
124 // "foo" is not unique across different operations:
125 // operation 1: action = foo, name = bar
126 // operation 2: action = bar, name = foo
127 private HashMap<String, AxisOperation> operationsAliasesMap = null;
128
129 // Collection of aliases that are invalid for this service because they are
130 // duplicated across
131 // multiple operations under this service.
132 private List<String> invalidOperationsAliases = null;
133 // private HashMap operations = new HashMap();
134
135 // to store module ref at deploy time parsing
136 private ArrayList<String> moduleRefs = null;
137
138 // to keep the time that last update time of the service
139 private long lastupdate;
140 private HashMap<String, ModuleConfiguration> moduleConfigmap;
141 private String name;
142 private ClassLoader serviceClassLoader;
143
144 // to keep the XMLScheam getting either from WSDL or java2wsdl
145 private ArrayList<XmlSchema> schemaList;
146 // private XmlSchema schema;
147
148 // wsdl is there for this service or not (in side META-INF)
149 private boolean wsdlFound = false;
150
151 // to store the scope of the service
152 private String scope;
153
154 // to store default message receivers
155 private HashMap<String, MessageReceiver> messageReceivers;
156
157 // to set the handler chain available in phase info
158 private boolean useDefaultChains = true;
159
160 // to keep the status of the service , since service can stop at the run
161 // time
162 private boolean active = true;
163
164 private boolean elementFormDefault = true;
165
166 // to keep the service target name space
167 private String targetNamespace = Java2WSDLConstants.DEFAULT_TARGET_NAMESPACE;
168 private String targetNamespacePrefix = Java2WSDLConstants.TARGETNAMESPACE_PREFIX;
169
170 // to store the target namespace for the schema
171 private String schematargetNamespace;// = Java2WSDLConstants.AXIS2_XSD;
172 private String schematargetNamespacePrefix = Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX;
173
174 private boolean enableAllTransports = true;
175 private List<String> exposedTransports = new ArrayList<String>();
176
177 // To keep reference to ServiceLifeCycle instance , if the user has
178 // specified in services.xml
179 private ServiceLifeCycle serviceLifeCycle;
180
181 /**
182 * Keeps track whether the schema locations are adjusted
183 */
184 private boolean schemaLocationsAdjusted = false;
185
186 private boolean wsdlImportLocationAdjusted = false;
187
188 /**
189 * A table that keeps a mapping of unique xsd names (Strings) against the
190 * schema objects. This is populated in the first instance the schemas are
191 * asked for and then used to serve the subsequent requests
192 */
193 private Map schemaMappingTable = null;
194
195 /**
196 * counter variable for naming the schemas
197 */
198 private int count = 0;
199 /**
200 * A custom schema Name prefix. if set this will be used to modify the
201 * schema names
202 */
203 private String customSchemaNamePrefix = null;
204
205 /**
206 * A custom schema name suffix. will be attached to the schema file name
207 * when the files are uniquely named. A good place to add a file extension
208 * if needed
209 */
210 private String customSchemaNameSuffix = null;
211
212 // ///////////////////////////////////////
213 // WSDL related stuff ////////////////////
214 // //////////////////////////////////////
215
216 /** Map of prefix -> namespaceURI */
217 private NamespaceMap namespaceMap;
218
219 private String soapNsUri;
220 private String endpointName;
221 private String endpointURL;
222
223 private List importedNamespaces;
224
225 private boolean clientSide = false;
226
227 // To keep a ref to ObjectSupplier instance
228 private ObjectSupplier objectSupplier;
229
230 // package to namespace mapping
231 private Map p2nMap;
232
233 // to keep the exclude property details
234 private ExcludeInfo excludeInfo;
235
236 private TypeTable typeTable;
237
238 // Data Locators for WS-Mex Support
239 private HashMap dataLocators;
240 private HashMap<String, String> dataLocatorClassNames;
241 private AxisDataLocatorImpl defaultDataLocator;
242 // Define search sequence for datalocator based on Data Locator types.
243 LocatorType[] availableDataLocatorTypes = new LocatorType[] {
244 LocatorType.SERVICE_DIALECT, LocatorType.SERVICE_LEVEL,
245 LocatorType.GLOBAL_DIALECT, LocatorType.GLOBAL_LEVEL,
246 LocatorType.DEFAULT_AXIS };
247
248 // name of the binding used : use in codegeneration
249 private String bindingName;
250
251 // List of MessageContextListeners that listen for events on the MessageContext
252 private CopyOnWriteArrayList<MessageContextListener> messageContextListeners =
253 new CopyOnWriteArrayList<MessageContextListener>();
254
255 // names list keep to preserve the parameter order
256 private List operationsNameList;
257
258 private String[] eprs;
259 private boolean customWsdl = false;
260
261 private HashMap policyMap = new HashMap();
262
263 public AxisEndpoint getEndpoint(String key) {
264 return (AxisEndpoint) endpointMap.get(key);
265 }
266
267 public void addEndpoint(String key, AxisEndpoint axisEndpoint) {
268 this.endpointMap.put(key, axisEndpoint);
269 }
270
271 /**
272 * @deprecated Use AddressingHelper.getAddressingRequirementParemeterValue
273 */
274 public String getWSAddressingFlag() {
275 return AddressingHelper.getAddressingRequirementParemeterValue(this);
276 }
277
278 /**
279 * @deprecated Use AddressingHelper.setAddressingRequirementParemeterValue
280 */
281 public void setWSAddressingFlag(String ar) {
282 AddressingHelper.setAddressingRequirementParemeterValue(this, ar);
283 }
284
285 public boolean isSchemaLocationsAdjusted() {
286 return schemaLocationsAdjusted;
287 }
288
289 public void setSchemaLocationsAdjusted(boolean schemaLocationsAdjusted) {
290 this.schemaLocationsAdjusted = schemaLocationsAdjusted;
291 }
292
293 public Map getSchemaMappingTable() {
294 return schemaMappingTable;
295 }
296
297 public void setSchemaMappingTable(Map schemaMappingTable) {
298 this.schemaMappingTable = schemaMappingTable;
299 }
300
301 public String getCustomSchemaNamePrefix() {
302 return customSchemaNamePrefix;
303 }
304
305 public void setCustomSchemaNamePrefix(String customSchemaNamePrefix) {
306 this.customSchemaNamePrefix = customSchemaNamePrefix;
307 }
308
309 public String getCustomSchemaNameSuffix() {
310 return customSchemaNameSuffix;
311 }
312
313 public void setCustomSchemaNameSuffix(String customSchemaNameSuffix) {
314 this.customSchemaNameSuffix = customSchemaNameSuffix;
315 }
316
317 /**
318 * Constructor AxisService.
319 */
320 public AxisService() {
321 super();
322 this.operationsAliasesMap = new HashMap();
323 this.invalidOperationsAliases = new ArrayList();
324 moduleConfigmap = new HashMap();
325 // by default service scope is for the request
326 scope = Constants.SCOPE_REQUEST;
327 httpLocationDispatcherMap = new HashMap();
328 messageReceivers = new HashMap();
329 moduleRefs = new ArrayList();
330 schemaList = new ArrayList();
331 serviceClassLoader = (ClassLoader) org.apache.axis2.java.security.AccessController
332 .doPrivileged(new PrivilegedAction<ClassLoader>() {
333 public ClassLoader run() {
334 return Thread.currentThread().getContextClassLoader();
335 }
336 });
337 objectSupplier = new DefaultObjectSupplier();
338 dataLocators = new HashMap();
339 dataLocatorClassNames = new HashMap();
340 }
341
342 /**
343 * @return name of the port type
344 * @deprecated use AxisService#getEndpointName() instead.
345 */
346 public String getPortTypeName() {
347 return endpointName;
348 }
349
350 /**
351 * @param portTypeName
352 * @deprecated use AxisService#setEndpointName() instead
353 */
354 public void setPortTypeName(String portTypeName) {
355 this.endpointName = portTypeName;
356 }
357
358 public String getBindingName() {
359 return bindingName;
360 }
361
362 public void setBindingName(String bindingName) {
363 this.bindingName = bindingName;
364 }
365
366 /**
367 * get the SOAPVersion
368 */
369 public String getSoapNsUri() {
370 return soapNsUri;
371 }
372
373 public void setSoapNsUri(String soapNsUri) {
374 this.soapNsUri = soapNsUri;
375 }
376
377 /**
378 * get the endpointName
379 */
380 public String getEndpointName() {
381 return endpointName;
382 }
383
384 public void setEndpointName(String endpoint) {
385 this.endpointName = endpoint;
386 }
387
388 /**
389 * Constructor AxisService.
390 */
391 public AxisService(String name) {
392 this();
393 this.name = name;
394 }
395
396 public void addMessageReceiver(String mepURI,
397 MessageReceiver messageReceiver) {
398 if (WSDL2Constants.MEP_URI_IN_ONLY.equals(mepURI)
399 || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY
400 .equals(mepURI)
401 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY
402 .equals(mepURI)) {
403 messageReceivers.put(WSDL2Constants.MEP_URI_IN_ONLY,
404 messageReceiver);
405 messageReceivers.put(
406 WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY,
407 messageReceiver);
408 messageReceivers.put(
409 WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY,
410 messageReceiver);
411 } else if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(mepURI)
412 || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_ONLY
413 .equals(mepURI)
414 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_ONLY
415 .equals(mepURI)) {
416 messageReceivers.put(WSDL2Constants.MEP_URI_OUT_ONLY,
417 messageReceiver);
418 messageReceivers.put(
419 WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_ONLY,
420 messageReceiver);
421 messageReceivers.put(
422 WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_ONLY,
423 messageReceiver);
424 } else if (WSDL2Constants.MEP_URI_IN_OUT.equals(mepURI)
425 || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT
426 .equals(mepURI)
427 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT
428 .equals(mepURI)) {
429 messageReceivers
430 .put(WSDL2Constants.MEP_URI_IN_OUT, messageReceiver);
431 messageReceivers.put(
432 WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT,
433 messageReceiver);
434 messageReceivers.put(
435 WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT,
436 messageReceiver);
437 } else if (WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT.equals(mepURI)
438 || WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OPTIONAL_OUT
439 .equals(mepURI)
440 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OPTIONAL_OUT
441 .equals(mepURI)) {
442 messageReceivers.put(WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT,
443 messageReceiver);
444 messageReceivers.put(
445 WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OPTIONAL_OUT,
446 messageReceiver);
447 messageReceivers
448 .put(
449 WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OPTIONAL_OUT,
450 messageReceiver);
451 } else if (WSDL2Constants.MEP_URI_OUT_IN.equals(mepURI)
452 || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_IN
453 .equals(mepURI)
454 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_IN
455 .equals(mepURI)) {
456 messageReceivers
457 .put(WSDL2Constants.MEP_URI_OUT_IN, messageReceiver);
458 messageReceivers.put(
459 WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_IN,
460 messageReceiver);
461 messageReceivers.put(
462 WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_IN,
463 messageReceiver);
464 } else if (WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN.equals(mepURI)
465 || WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_OPTIONAL_IN
466 .equals(mepURI)
467 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_OPTIONAL_IN
468 .equals(mepURI)) {
469 messageReceivers.put(WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN,
470 messageReceiver);
471 messageReceivers.put(
472 WSDLConstants.WSDL20_2006Constants.MEP_URI_OUT_OPTIONAL_IN,
473 messageReceiver);
474 messageReceivers
475 .put(
476 WSDLConstants.WSDL20_2004_Constants.MEP_URI_OUT_OPTIONAL_IN,
477 messageReceiver);
478 } else if (WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY.equals(mepURI)
479 || WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_OUT_ONLY
480 .equals(mepURI)
481 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_OUT_ONLY
482 .equals(mepURI)) {
483 messageReceivers.put(WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY,
484 messageReceiver);
485 messageReceivers.put(
486 WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_OUT_ONLY,
487 messageReceiver);
488 messageReceivers
489 .put(
490 WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_OUT_ONLY,
491 messageReceiver);
492 } else if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(mepURI)
493 || WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY
494 .equals(mepURI)
495 || WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY
496 .equals(mepURI)) {
497 messageReceivers.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
498 messageReceiver);
499 messageReceivers.put(
500 WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY,
501 messageReceiver);
502 messageReceivers.put(
503 WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY,
504 messageReceiver);
505 } else {
506 messageReceivers.put(mepURI, messageReceiver);
507 }
508 }
509
510 public MessageReceiver getMessageReceiver(String mepURL) {
511 return (MessageReceiver) messageReceivers.get(mepURL);
512 }
513
514 /**
515 * Adds module configuration , if there is moduleConfig tag in service.
516 *
517 * @param moduleConfiguration
518 */
519 public void addModuleConfig(ModuleConfiguration moduleConfiguration) {
520 moduleConfigmap.put(moduleConfiguration.getModuleName(),
521 moduleConfiguration);
522 }
523
524 /**
525 * Add any control operations defined by a Module to this service.
526 *
527 * @param module
528 * the AxisModule which has just been engaged
529 * @throws AxisFault
530 * if a problem occurs
531 */
532 void addModuleOperations(AxisModule module) throws AxisFault {
533 HashMap<QName, AxisOperation> map = module.getOperations();
534 Collection<AxisOperation> col = map.values();
535 PhaseResolver phaseResolver = new PhaseResolver(getAxisConfiguration());
536 for (Iterator<AxisOperation> iterator = col.iterator(); iterator.hasNext();) {
537 AxisOperation axisOperation = copyOperation((AxisOperation) iterator
538 .next());
539 if (this.getOperation(axisOperation.getName()) == null) {
540 ArrayList<String> wsamappings = axisOperation.getWSAMappingList();
541 if (wsamappings != null) {
542 for (int j = 0, size = wsamappings.size(); j < size; j++) {
543 String mapping = (String) wsamappings.get(j);
544 mapActionToOperation(mapping, axisOperation);
545 }
546 }
547 // If we've set the "expose" parameter for this operation, it's
548 // normal (non-
549 // control) and therefore it will appear in generated WSDL. If
550 // we haven't,
551 // it's a control operation and will be ignored at WSDL-gen
552 // time.
553 if (axisOperation
554 .isParameterTrue(DeploymentConstants.TAG_EXPOSE)) {
555 axisOperation.setControlOperation(false);
556 } else {
557 axisOperation.setControlOperation(true);
558 }
559
560 phaseResolver.engageModuleToOperation(axisOperation, module);
561
562 this.addOperation(axisOperation);
563 }
564 }
565 }
566
567 public void addModuleref(String moduleref) {
568 moduleRefs.add(moduleref);
569 }
570
571 /*
572 * (non-Javadoc)
573 *
574 * @see org.apache.axis2.description.AxisService#addOperation(org.apache.axis2.description.AxisOperation)
575 */
576
577 /**
578 * Method addOperation.
579 *
580 * @param axisOperation
581 */
582 public void addOperation(AxisOperation axisOperation) {
583 axisOperation.setParent(this);
584
585 if (log.isDebugEnabled()) {
586 if (axisOperation.getName().equals(ServiceClient.ANON_OUT_ONLY_OP)
587 || (axisOperation.getName().equals(ServiceClient.ANON_OUT_ONLY_OP))
588 || (axisOperation.getName().equals(ServiceClient.ANON_OUT_ONLY_OP))) {
589 log.debug("Client-defined operation name matches default operation name. "
590 + "this may cause interoperability issues. Name is: " + axisOperation.getName().toString());
591 }
592 }
593
594 Iterator<AxisModule> modules = getEngagedModules().iterator();
595
596 while (modules.hasNext()) {
597 AxisModule module = (AxisModule) modules.next();
598 try {
599 axisOperation.engageModule(module);
600 } catch (AxisFault axisFault) {
601 log.info(Messages.getMessage("modulealredyengagetoservice",
602 module.getName()));
603 }
604 }
605 if (axisOperation.getMessageReceiver() == null) {
606 axisOperation.setMessageReceiver(loadDefaultMessageReceiver(
607 axisOperation.getMessageExchangePattern(), this));
608 }
609 if (axisOperation.getInputAction() == null) {
610 axisOperation.setSoapAction("urn:"
611 + axisOperation.getName().getLocalPart());
612 }
613
614 if (axisOperation.getOutputAction() == null) {
615 axisOperation.setOutputAction("urn:"
616 + axisOperation.getName().getLocalPart()
617 + Java2WSDLConstants.RESPONSE);
618 }
619 addChild(axisOperation);
620
621 String operationName = axisOperation.getName().getLocalPart();
622
623 /*
624 * Some times name of the operation can be different from the name of
625 * the first child of the SOAPBody. This will put the correct mapping
626 * associating that name with the operation. This will be useful
627 * especially for the SOAPBodyBasedDispatcher
628 */
629
630 Iterator axisMessageIter = axisOperation.getChildren();
631
632 while (axisMessageIter.hasNext()) {
633 AxisMessage axisMessage = (AxisMessage) axisMessageIter.next();
634 String messageName = axisMessage.getName();
635 if (messageName != null && !messageName.equals(operationName)) {
636 mapActionToOperation(messageName, axisOperation);
637 }
638 }
639
640 mapActionToOperation(operationName, axisOperation);
641
642 String action = axisOperation.getInputAction();
643 if (action.length() > 0) {
644 mapActionToOperation(action, axisOperation);
645 }
646
647 ArrayList<String> wsamappings = axisOperation.getWSAMappingList();
648 if (wsamappings != null) {
649 for (int j = 0, size = wsamappings.size(); j < size; j++) {
650 String mapping = (String) wsamappings.get(j);
651 mapActionToOperation(mapping, axisOperation);
652 }
653 }
654
655 if (axisOperation.getMessageReceiver() == null) {
656 axisOperation.setMessageReceiver(loadDefaultMessageReceiver(
657 axisOperation.getMessageExchangePattern(), this));
658 }
659 }
660
661 private MessageReceiver loadDefaultMessageReceiver(String mepURL,
662 AxisService service) {
663 MessageReceiver messageReceiver;
664 if (mepURL == null) {
665 mepURL = WSDL2Constants.MEP_URI_IN_OUT;
666 }
667 if (service != null) {
668 messageReceiver = service.getMessageReceiver(mepURL);
669 if (messageReceiver != null) {
670 return messageReceiver;
671 }
672 }
673 if (getAxisConfiguration() != null) {
674 return getAxisConfiguration().getMessageReceiver(mepURL);
675 }
676 return null;
677 }
678
679 /**
680 * Gets a copy from module operation.
681 *
682 * @param axisOperation
683 * @return Returns AxisOperation.
684 * @throws AxisFault
685 */
686 private AxisOperation copyOperation(AxisOperation axisOperation)
687 throws AxisFault {
688 AxisOperation operation = AxisOperationFactory
689 .getOperationDescription(axisOperation
690 .getMessageExchangePattern());
691
692 operation.setMessageReceiver(axisOperation.getMessageReceiver());
693 operation.setName(axisOperation.getName());
694
695 Iterator<Parameter> parameters = axisOperation.getParameters().iterator();
696
697 while (parameters.hasNext()) {
698 Parameter parameter = (Parameter) parameters.next();
699
700 operation.addParameter(parameter);
701 }
702
703 PolicyInclude policyInclude = new PolicyInclude(operation);
704 PolicyInclude axisOperationPolicyInclude = axisOperation
705 .getPolicyInclude();
706
707 if (axisOperationPolicyInclude != null) {
708 Policy policy = axisOperationPolicyInclude.getPolicy();
709 if (policy != null) {
710 policyInclude.setPolicy(axisOperationPolicyInclude.getPolicy());
711 }
712 }
713 operation.setPolicyInclude(policyInclude);
714
715 operation.setWsamappingList(axisOperation.getWSAMappingList());
716 operation.setRemainingPhasesInFlow(axisOperation
717 .getRemainingPhasesInFlow());
718 operation.setPhasesInFaultFlow(axisOperation.getPhasesInFaultFlow());
719 operation.setPhasesOutFaultFlow(axisOperation.getPhasesOutFaultFlow());
720 operation.setPhasesOutFlow(axisOperation.getPhasesOutFlow());
721
722 operation.setOutputAction(axisOperation.getOutputAction());
723 String[] faultActionNames = axisOperation.getFaultActionNames();
724 for (int i = 0; i < faultActionNames.length; i++) {
725 operation.addFaultAction(faultActionNames[i], axisOperation
726 .getFaultAction(faultActionNames[i]));
727 }
728
729 return operation;
730 }
731
732 /*
733 * (non-Javadoc)
734 *
735 * @see org.apache.axis2.description.AxisService#addToengagedModules(javax.xml.namespace.QName)
736 */
737
738 /**
739 * Engages a module. It is required to use this method.
740 *
741 * @param axisModule
742 * @param engager
743 */
744 public void onEngage(AxisModule axisModule, AxisDescription engager)
745 throws AxisFault {
746 // adding module operations
747 addModuleOperations(axisModule);
748
749 Iterator<AxisOperation> operations = getOperations();
750 while (operations.hasNext()) {
751 AxisOperation axisOperation = (AxisOperation) operations.next();
752 axisOperation.engageModule(axisModule, engager);
753 }
754 }
755
756 /**
757 * Maps an alias (such as a SOAPAction, WSA action, or an operation name) to
758 * the given AxisOperation. This is used by dispatching (both SOAPAction-
759 * and WSAddressing- based dispatching) to figure out which operation a
760 * given message is for. Some notes on restrictions of "action" - A null or
761 * empty action will be ignored - An action that is a duplicate and
762 * references an idential operation is allowed - An acton that is a
763 * duplicate and references a different operation is NOT allowed. In this
764 * case, the action for the original operation is removed from the alias
765 * table, thus removing the ability to route based on this action. This is
766 * necessary to prevent mis-directing incoming message to the wrong
767 * operation based on SOAPAction.
768 *
769 * Note that an alias could be a SOAPAction, WS-Addressing Action, the
770 * operation name, or some other alias.
771 *
772 * @see #getOperationByAction(String)
773 *
774 * @param action
775 * the alias key
776 * @param axisOperation
777 * the operation to map to
778 */
779 public void mapActionToOperation(String action, AxisOperation axisOperation) {
780 if (action == null || "".equals(action)) {
781 if (log.isDebugEnabled()) {
782 log
783 .debug("mapActionToOperation: A null or empty action cannot be used to map to an operation.");
784 }
785 return;
786 }
787 if (log.isDebugEnabled()) {
788 log
789 .debug("mapActionToOperation: Mapping Action to Operation: action: "
790 + action
791 + "; operation: "
792 + axisOperation
793 + "named: " + axisOperation.getName());
794 }
795
796 // First check if this action has already been flagged as invalid
797 // because it is a duplicate.
798 if (invalidOperationsAliases.contains(action)) {
799 // This SOAPAction has already been determined to be invalid; log a
800 // message
801 // and do not add it to the operation alias map.
802 if (log.isDebugEnabled()) {
803 log
804 .debug("mapActionToOperation: The action: "
805 + action
806 + " can not be used for operation: "
807 + axisOperation
808 + " with operation name: "
809 + axisOperation.getName()
810 + " because that SOAPAction is not unique for this service.");
811 }
812 return;
813 }
814
815 // Check if the action is currently mapping to an operation.
816 AxisOperation currentlyMappedOperation = getOperationByAction(action);
817 if (currentlyMappedOperation != null) {
818 if (currentlyMappedOperation == axisOperation) {
819 // This maps to the same operation, then it is already in the
820 // alias table, so
821 // just silently ignore this mapping request.
822 if (log.isDebugEnabled()) {
823 log
824 .debug("mapActionToOperation: This operation is already mapped to this action: "
825 + action
826 + "; AxisOperation: "
827 + currentlyMappedOperation
828 + " named: "
829 + currentlyMappedOperation.getName());
830 }
831 } else {
832 // This action is already mapped, but it is to a different
833 // operation. Remove
834 // the action mapping from the alias table and add it to the
835 // list of invalid mappings
836 operationsAliasesMap.remove(action);
837 invalidOperationsAliases.add(action);
838 if (log.isDebugEnabled()) {
839 log
840 .debug("mapActionToOperation: The action is already mapped to a different "
841 + "operation. The mapping of the action to any operations will be "
842 + "removed. Action: "
843 + action
844 + "; original operation: "
845 + currentlyMappedOperation
846 + " named "
847 + currentlyMappedOperation.getName()
848 + "; new operation: "
849 + axisOperation
850 + " named " + axisOperation.getName());
851 }
852 }
853 } else {
854 operationsAliasesMap.put(action, axisOperation);
855 // Adding operation name to the mapping table
856 // operationsAliasesMap.put(axisOperation.getName().getLocalPart(),
857 // axisOperation);
858 }
859 }
860
861 /**
862 * Maps an constant string in the whttp:location to the given operation.
863 * This is used by RequestURIOperationDispatcher based dispatching to figure
864 * out which operation it is that a given message is for.
865 *
866 * @param string
867 * the constant drawn from whttp:location
868 * @param axisOperation
869 * the operation to map to
870 */
871 public void addHttpLocationDispatcherString(String string,
872 AxisOperation axisOperation) {
873 httpLocationDispatcherMap.put(string, axisOperation);
874 }
875
876 public void printSchema(OutputStream out) throws AxisFault {
877 for (int i = 0; i < schemaList.size(); i++) {
878 XmlSchema schema = addNameSpaces(i);
879 schema.write(out);
880 }
881 }
882
883 public XmlSchema getSchema(int index) {
884 return addNameSpaces(index);
885 }
886
887 /**
888 * Release the list of schema objects. <p/> In some environments, this can
889 * provide significant relief of memory consumption in the java heap, as
890 * long as the need for the schema list has completed.
891 */
892 public void releaseSchemaList() {
893 if (schemaList != null) {
894 // release the schema list
895 schemaList.clear();
896 }
897
898 if (log.isDebugEnabled()) {
899 log.debug("releaseSchemaList: schema list has been released.");
900 }
901 }
902
903 private XmlSchema addNameSpaces(int i) {
904 XmlSchema schema = (XmlSchema) schemaList.get(i);
905 NamespaceMap map = (NamespaceMap) namespaceMap.clone();
906 NamespacePrefixList namespaceContext = schema.getNamespaceContext();
907 String prefixes[] = namespaceContext.getDeclaredPrefixes();
908 for (int j = 0; j < prefixes.length; j++) {
909 String prefix = prefixes[j];
910 map.add(prefix, namespaceContext.getNamespaceURI(prefix));
911 }
912 schema.setNamespaceContext(map);
913 return schema;
914 }
915
916 public void setEPRs(String[] eprs) {
917 this.eprs = eprs;
918 }
919
920 public String[] getEPRs() {
921 if (eprs != null && eprs.length != 0) {
922 return eprs;
923 }
924 eprs = calculateEPRs();
925 return eprs;
926 }
927
928 private String[] calculateEPRs() {
929 try {
930 String requestIP = org.apache.axis2.util.Utils.getIpAddress(getAxisConfiguration());
931 return calculateEPRs(requestIP);
932 } catch (SocketException e) {
933 log.error("Cannot get local IP address", e);
934 }
935 return new String[0];
936 }
937
938 private String[] calculateEPRs(String requestIP) {
939 AxisConfiguration axisConfig = getAxisConfiguration();
940 if (axisConfig == null) {
941 return null;
942 }
943 ArrayList<String> eprList = new ArrayList<String>();
944 if (enableAllTransports) {
945 for (Iterator<TransportInDescription> transports = axisConfig.getTransportsIn().values()
946 .iterator(); transports.hasNext();) {
947 TransportInDescription transportIn = (TransportInDescription) transports
948 .next();
949 TransportListener listener = transportIn.getReceiver();
950 if (listener != null) {
951 try {
952 EndpointReference[] eprsForService = listener
953 .getEPRsForService(this.name, requestIP);
954 if (eprsForService != null) {
955 for (int i = 0; i < eprsForService.length; i++) {
956 EndpointReference endpointReference = eprsForService[i];
957 if (endpointReference != null) {
958 String address = endpointReference
959 .getAddress();
960 if (address != null) {
961 eprList.add(address);
962 }
963 }
964 }
965 }
966 } catch (AxisFault axisFault) {
967 log.warn(axisFault.getMessage());
968 }
969 }
970 }
971 } else {
972 List<String> trs = this.exposedTransports;
973 for (int i = 0; i < trs.size(); i++) {
974 String trsName = (String) trs.get(i);
975 TransportInDescription transportIn = axisConfig
976 .getTransportIn(trsName);
977 if (transportIn != null) {
978 TransportListener listener = transportIn.getReceiver();
979 if (listener != null) {
980 try {
981 EndpointReference[] eprsForService = listener
982 .getEPRsForService(this.name, requestIP);
983 if (eprsForService != null) {
984 for (int j = 0; j < eprsForService.length; j++) {
985 EndpointReference endpointReference = eprsForService[j];
986 if (endpointReference != null) {
987 String address = endpointReference
988 .getAddress();
989 if (address != null) {
990 eprList.add(address);
991 }
992 }
993 }
994 }
995 } catch (AxisFault axisFault) {
996 log.warn(axisFault.getMessage());
997 }
998 }
999 }
1000 }
1001 }
1002 eprs = (String[]) eprList.toArray(new String[eprList.size()]);
1003 return eprs;
1004 }
1005
1006 private void printDefinitionObject(Definition definition, OutputStream out,
1007 String requestIP) throws AxisFault, WSDLException {
1008 if (isModifyUserWSDLPortAddress()) {
1009 setPortAddress(definition, requestIP);
1010 }
1011 if (!wsdlImportLocationAdjusted) {
1012 changeImportAndIncludeLocations(definition);
1013 wsdlImportLocationAdjusted = true;
1014 }
1015 WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
1016 writer.writeWSDL(definition, out);
1017 }
1018
1019 public void printUserWSDL(OutputStream out, String wsdlName)
1020 throws AxisFault {
1021 Definition definition = null;
1022 // first find the correct wsdl definition
1023 Parameter wsdlParameter = getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
1024 if (wsdlParameter != null) {
1025 definition = (Definition) wsdlParameter.getValue();
1026 }
1027
1028 if (definition != null) {
1029 try {
1030 printDefinitionObject(getWSDLDefinition(definition, wsdlName),
1031 out, null);
1032 } catch (WSDLException e) {
1033 throw AxisFault.makeFault(e);
1034 }
1035 } else {
1036 printWSDLError(out);
1037 }
1038
1039 }
1040
1041 /**
1042 * find the defintion object for given name
1043 *
1044 * @param parentDefinition
1045 * @param name
1046 * @return wsdl definition
1047 */
1048 private Definition getWSDLDefinition(Definition parentDefinition,
1049 String name) {
1050
1051 if (name == null)
1052 return parentDefinition;
1053
1054 Definition importedDefinition = null;
1055 Iterator iter = parentDefinition.getImports().values().iterator();
1056 Vector values = null;
1057 Import wsdlImport = null;
1058 for (; iter.hasNext();) {
1059 values = (Vector) iter.next();
1060 for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) {
1061 wsdlImport = (Import) valuesIter.next();
1062 if (wsdlImport.getLocationURI().endsWith(name)) {
1063 importedDefinition = wsdlImport.getDefinition();
1064 break;
1065 } else {
1066 importedDefinition = getWSDLDefinition(wsdlImport
1067 .getDefinition(), name);
1068 }
1069 if (importedDefinition != null) {
1070 break;
1071 }
1072 }
1073 if (importedDefinition != null) {
1074 break;
1075 }
1076 }
1077 return importedDefinition;
1078 }
1079
1080 /**
1081 * this procesdue recursively adjust the wsdl imports locations and the
1082 * schmea import and include locations.
1083 *
1084 * @param definition
1085 */
1086 private void changeImportAndIncludeLocations(Definition definition) throws AxisFault {
1087
1088 // adjust the schema locations in types section
1089 Types types = definition.getTypes();
1090 if (types != null) {
1091 List extensibilityElements = types.getExtensibilityElements();
1092 Object extensibilityElement = null;
1093 Schema schema = null;
1094 for (Iterator iter = extensibilityElements.iterator(); iter.hasNext();) {
1095 extensibilityElement = iter.next();
1096 if (extensibilityElement instanceof Schema) {
1097 schema = (Schema) extensibilityElement;
1098 changeLocations(schema.getElement());
1099 }
1100 }
1101 }
1102
1103 Iterator iter = definition.getImports().values().iterator();
1104 Vector values = null;
1105 Import wsdlImport = null;
1106 String originalImprotString = null;
1107 for (; iter.hasNext();) {
1108 values = (Vector) iter.next();
1109 for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) {
1110 wsdlImport = (Import) valuesIter.next();
1111 originalImprotString = wsdlImport.getLocationURI();
1112 if (originalImprotString.indexOf("://") == -1 && originalImprotString.indexOf("?wsdl=") == -1){
1113 wsdlImport.setLocationURI(this.getServiceEPR() + "?wsdl=" + originalImprotString);
1114 }
1115 changeImportAndIncludeLocations(wsdlImport.getDefinition());
1116 }
1117 }
1118
1119 }
1120
1121 /**
1122 * change the schema Location in the elemment
1123 *
1124 * @param element
1125 */
1126
1127 private void changeLocations(Element element) throws AxisFault {
1128 NodeList nodeList = element.getChildNodes();
1129 String tagName;
1130 for (int i = 0; i < nodeList.getLength(); i++) {
1131 tagName = nodeList.item(i).getLocalName();
1132 if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) {
1133 processImport(nodeList.item(i));
1134 }
1135 }
1136 }
1137
1138 private void updateSchemaLocation(XmlSchema schema) throws AxisFault {
1139 XmlSchemaObjectCollection includes = schema.getIncludes();
1140 for (int j = 0; j < includes.getCount(); j++) {
1141 Object item = includes.getItem(j);
1142 if (item instanceof XmlSchemaExternal) {
1143 XmlSchemaExternal xmlSchemaExternal = (XmlSchemaExternal) item;
1144 XmlSchema s = xmlSchemaExternal.getSchema();
1145 updateSchemaLocation(s, xmlSchemaExternal);
1146 }
1147 }
1148 }
1149
1150 private void updateSchemaLocation(XmlSchema s, XmlSchemaExternal xmlSchemaExternal) throws AxisFault {
1151 if (s != null) {
1152 String schemaLocation = xmlSchemaExternal.getSchemaLocation();
1153
1154 if (schemaLocation.indexOf("://") == -1 && schemaLocation.indexOf("?xsd=") == -1) {
1155 String newscheamlocation = this.getServiceEPR() + "?xsd=" + schemaLocation;
1156 xmlSchemaExternal.setSchemaLocation(newscheamlocation);
1157 }
1158 }
1159 }
1160
1161 private void processImport(Node importNode) throws AxisFault {
1162 NamedNodeMap nodeMap = importNode.getAttributes();
1163 Node attribute;
1164 String attributeValue;
1165 for (int i = 0; i < nodeMap.getLength(); i++) {
1166 attribute = nodeMap.item(i);
1167 if (attribute.getNodeName().equals("schemaLocation")) {
1168 attributeValue = attribute.getNodeValue();
1169 if (attributeValue.indexOf("://") == -1 && attributeValue.indexOf("?xsd=") == -1) {
1170 attribute.setNodeValue(this.getServiceEPR() + "?xsd=" + attributeValue);
1171 }
1172 }
1173 }
1174 }
1175
1176 private String getServiceEPR() {
1177 String serviceEPR = null;
1178 Parameter parameter = this.getParameter(Constants.Configuration.GENERATE_ABSOLUTE_LOCATION_URIS);
1179 if ((parameter != null) && JavaUtils.isTrueExplicitly(parameter.getValue())) {
1180 String[] eprs = this.getEPRs();
1181 for (int i = 0; i < eprs.length; i++) {
1182 if ((eprs[i] != null) && (eprs[i].startsWith("http:"))){
1183 serviceEPR = eprs[i];
1184 break;
1185 }
1186 }
1187 if (serviceEPR == null){
1188 serviceEPR = eprs[0];
1189 }
1190 } else {
1191 serviceEPR = this.name;
1192 }
1193 if (serviceEPR.endsWith("/")){
1194 serviceEPR = serviceEPR.substring(0, serviceEPR.lastIndexOf("/"));
1195 }
1196 return serviceEPR;
1197 }
1198
1199 /**
1200 * Produces a XSD for this AxisService and prints it to the specified
1201 * OutputStream.
1202 *
1203 * @param out
1204 * destination stream.
1205 * @param xsd
1206 * schema name
1207 * @return -1 implies not found, 0 implies redirect to root, 1 implies
1208 * found/printed a schema
1209 * @throws IOException
1210 */
1211 public int printXSD(OutputStream out, String xsd) throws IOException {
1212
1213 // If we find a SchemaSupplier, use that
1214 SchemaSupplier supplier = (SchemaSupplier) getParameterValue("SchemaSupplier");
1215 if (supplier != null) {
1216 XmlSchema schema = supplier.getSchema(this, xsd);
1217 if (schema != null) {
1218 updateSchemaLocation(schema);
1219 schema.write(new OutputStreamWriter(out, "UTF8"));
1220 out.flush();
1221 out.close();
1222 return 1;
1223 }
1224 }
1225
1226 // call the populator
1227 populateSchemaMappings();
1228 Map schemaMappingtable = getSchemaMappingTable();
1229 ArrayList<XmlSchema> schemas = getSchema();
1230
1231 // a name is present - try to pump the requested schema
1232 if (!"".equals(xsd)) {
1233 XmlSchema schema = (XmlSchema) schemaMappingtable.get(xsd);
1234 if (schema == null) {
1235 int dotIndex = xsd.indexOf('.');
1236 if (dotIndex > 0) {
1237 String schemaKey = xsd.substring(0, dotIndex);
1238 schema = (XmlSchema) schemaMappingtable.get(schemaKey);
1239 }
1240 }
1241 if (schema != null) {
1242 // schema is there - pump it outs
1243 schema.write(new OutputStreamWriter(out, "UTF8"));
1244 out.flush();
1245 out.close();
1246 } else {
1247 // make sure we are only serving .xsd files and ignore requests with
1248 // ".." in the name.
1249 if (xsd.endsWith(".xsd") && xsd.indexOf("..") == -1) {
1250 InputStream in = getClassLoader().getResourceAsStream(
1251 DeploymentConstants.META_INF + "/" + xsd);
1252 if (in != null) {
1253 IOUtils.copy(in, out, true);
1254 } else {
1255 // Can't find the schema
1256 return -1;
1257 }
1258 } else {
1259 // bad schema request
1260 return -1;
1261 }
1262 }
1263 } else if (schemas.size() > 1) {
1264 // multiple schemas are present and the user specified
1265 // no name - in this case we cannot possibly pump a schema
1266 // so redirect to the service root
1267 return 0;
1268 } else {
1269 // user specified no name and there is only one schema
1270 // so pump that out
1271 ArrayList<XmlSchema> list = getSchema();
1272 if (list.size() > 0) {
1273 XmlSchema schema = getSchema(0);
1274 if (schema != null) {
1275 schema.write(new OutputStreamWriter(out, "UTF8"));
1276 out.flush();
1277 out.close();
1278 }
1279 } else {
1280 String xsdNotFound = "<error>"
1281 + "<description>Unable to access schema for this service</description>"
1282 + "</error>";
1283 out.write(xsdNotFound.getBytes());
1284 out.flush();
1285 out.close();
1286 }
1287 }
1288 return 1;
1289 }
1290
1291 /**
1292 * Produces a WSDL for this AxisService and prints it to the specified
1293 * OutputStream.
1294 *
1295 * @param out
1296 * destination stream. The WSDL will be sent here.
1297 * @param requestIP
1298 * the hostname the WSDL request was directed at. This should be
1299 * the address that appears in the generated WSDL.
1300 * @throws AxisFault
1301 * if an error occurs
1302 */
1303 public void printWSDL(OutputStream out, String requestIP) throws AxisFault {
1304 // If we're looking for pre-existing WSDL, use that.
1305 if (isUseUserWSDL()) {
1306 printUserWSDL(out, null);
1307 return;
1308 }
1309
1310 // If we find a WSDLSupplier, use that
1311 WSDLSupplier supplier = (WSDLSupplier) getParameterValue("WSDLSupplier");
1312 if (supplier != null) {
1313 try {
1314 Definition definition = supplier.getWSDL(this);
1315 if (definition != null) {
1316 changeImportAndIncludeLocations(definition);
1317 printDefinitionObject(getWSDLDefinition(definition, null),
1318 out, requestIP);
1319 }
1320 } catch (Exception e) {
1321 printWSDLError(out, e);
1322 }
1323 return;
1324 }
1325
1326 // Otherwise, generate WSDL ourselves
1327 String[] eprArray = requestIP == null ? new String[] { this.endpointName }
1328 : calculateEPRs(requestIP);
1329 getWSDL(out, eprArray);
1330 }
1331
1332 /**
1333 * Print the WSDL with a default URL. This will be called only during
1334 * codegen time.
1335 *
1336 * @param out
1337 * @throws AxisFault
1338 */
1339 public void printWSDL(OutputStream out) throws AxisFault {
1340 printWSDL(out, null);
1341 }
1342
1343 private AxisEndpoint getAxisEndpoint(String port) {
1344 // if service has a single endpoint, this will cause the [serviceName] address
1345 // to be used in wsdl instead of the [serviceName].[endpointName]
1346 if (endpointMap.size() == 1 && endpointMap.containsKey(getEndpointName())) {
1347 return null;
1348 } else {
1349 return (AxisEndpoint)endpointMap.get(port);
1350 }
1351 }
1352
1353 private void setPortAddress(Definition definition, String requestIP)
1354 throws AxisFault {
1355 Iterator serviceItr = definition.getServices().values().iterator();
1356 while (serviceItr.hasNext()) {
1357 Service serviceElement = (Service) serviceItr.next();
1358 Iterator portItr = serviceElement.getPorts().values().iterator();
1359 while (portItr.hasNext()) {
1360 Port port = (Port) portItr.next();
1361 AxisEndpoint endpoint = getAxisEndpoint(port.getName());
1362 List list = port.getExtensibilityElements();
1363 for (int i = 0; i < list.size(); i++) {
1364 Object extensibilityEle = list.get(i);
1365 if (extensibilityEle instanceof SOAPAddress) {
1366 SOAPAddress soapAddress = (SOAPAddress) extensibilityEle;
1367 String existingAddress = soapAddress.getLocationURI();
1368 if (existingAddress == null
1369 || existingAddress
1370 .equals("REPLACE_WITH_ACTUAL_URL")) {
1371 if (endpoint != null) {
1372 ((SOAPAddress) extensibilityEle)
1373 .setLocationURI(endpoint
1374 .calculateEndpointURL());
1375 } else {
1376 ((SOAPAddress) extensibilityEle)
1377 .setLocationURI(getEPRs()[0]);
1378 }
1379 } else {
1380 if (requestIP == null) {
1381 if (endpoint != null) {
1382 ((SOAPAddress) extensibilityEle)
1383 .setLocationURI(endpoint
1384 .calculateEndpointURL());
1385 } else {
1386 ((SOAPAddress) extensibilityEle)
1387 .setLocationURI(getLocationURI(
1388 getEPRs(), existingAddress));
1389 }
1390 } else {
1391 if (endpoint != null) {
1392 ((SOAPAddress) extensibilityEle)
1393 .setLocationURI(endpoint
1394 .calculateEndpointURL());
1395 } else {
1396 ((SOAPAddress) extensibilityEle)
1397 .setLocationURI(getLocationURI(
1398 calculateEPRs(requestIP),
1399 existingAddress));
1400 }
1401 }
1402 }
1403 } else if (extensibilityEle instanceof SOAP12Address) {
1404 SOAP12Address soapAddress = (SOAP12Address) extensibilityEle;
1405 String exsistingAddress = soapAddress.getLocationURI();
1406 if (requestIP == null) {
1407 if (endpoint != null) {
1408 ((SOAP12Address) extensibilityEle)
1409 .setLocationURI(endpoint
1410 .calculateEndpointURL());
1411
1412 } else {
1413 ((SOAP12Address) extensibilityEle)
1414 .setLocationURI(getLocationURI(
1415 getEPRs(), exsistingAddress));
1416 }
1417 } else {
1418 if (endpoint != null) {
1419 ((SOAP12Address) extensibilityEle)
1420 .setLocationURI(endpoint
1421 .calculateEndpointURL());
1422 } else {
1423 ((SOAP12Address) extensibilityEle)
1424 .setLocationURI(getLocationURI(
1425 calculateEPRs(requestIP),
1426 exsistingAddress));
1427
1428 }
1429 }
1430 } else if (extensibilityEle instanceof HTTPAddress) {
1431 HTTPAddress httpAddress = (HTTPAddress) extensibilityEle;
1432 String exsistingAddress = httpAddress.getLocationURI();
1433 if (requestIP == null) {
1434 if (endpoint != null) {
1435 ((HTTPAddress) extensibilityEle)
1436 .setLocationURI(endpoint
1437 .calculateEndpointURL());
1438 } else {
1439 ((HTTPAddress) extensibilityEle)
1440 .setLocationURI(getLocationURI(
1441 getEPRs(), exsistingAddress));
1442 }
1443 } else {
1444 if (endpoint != null) {
1445 ((HTTPAddress) extensibilityEle)
1446 .setLocationURI(endpoint
1447 .calculateEndpointURL());
1448 } else {
1449 ((HTTPAddress) extensibilityEle)
1450 .setLocationURI(getLocationURI(
1451 calculateEPRs(requestIP),
1452 exsistingAddress));
1453 }
1454 }
1455 }
1456 // TODO : change the Endpoint refrence addess as well.
1457 }
1458 }
1459 }
1460 }
1461
1462 /**
1463 * this method returns the new IP address corresponding to the already
1464 * existing ip
1465 *
1466 * @param eprs
1467 * @param epr
1468 * @return corresponding Ip address
1469 */
1470 private String getLocationURI(String[] eprs, String epr) throws AxisFault {
1471 String returnIP = null;
1472 if (epr != null) {
1473 if (epr.indexOf(":") > -1) {
1474 String existingProtocol = epr.substring(0, epr.indexOf(":"))
1475 .trim();
1476 String eprProtocol;
1477 for (int i = 0; i < eprs.length; i++) {
1478 eprProtocol = eprs[i].substring(0, eprs[i].indexOf(":"))
1479 .trim();
1480 if (eprProtocol.equals(existingProtocol)) {
1481 returnIP = eprs[i];
1482 break;
1483 }
1484 }
1485 if (returnIP != null) {
1486 return returnIP;
1487 } else {
1488 throw new AxisFault(
1489 "Server does not have an epr for the wsdl epr==>"
1490 + epr);
1491 }
1492 } else {
1493 throw new AxisFault("invalid epr is given epr ==> " + epr);
1494 }
1495 } else {
1496 throw new AxisFault("No epr is given in the wsdl port");
1497 }
1498 }
1499
1500 private void getWSDL(OutputStream out, String[] serviceURL)
1501 throws AxisFault {
1502 // Retrieve WSDL using the same data retrieval path for GetMetadata
1503 // request.
1504 DataRetrievalRequest request = new DataRetrievalRequest();
1505 request.putDialect(DRConstants.SPEC.DIALECT_TYPE_WSDL);
1506 request.putOutputForm(OutputForm.INLINE_FORM);
1507
1508 MessageContext context = new MessageContext();
1509 context.setAxisService(this);
1510 context.setTo(new EndpointReference(serviceURL[0]));
1511
1512 Data[] result = getData(request, context);
1513 OMElement wsdlElement;
1514 if (result != null && result.length > 0) {
1515 wsdlElement = (OMElement) (result[0].getData());
1516 try {
1517 XMLPrettyPrinter.prettify(wsdlElement, out);
1518 out.flush();
1519 out.close();
1520 } catch (Exception e) {
1521 throw AxisFault.makeFault(e);
1522 }
1523 }
1524 }
1525
1526 private void printWSDLError(OutputStream out) throws AxisFault {
1527 printWSDLError(out, null);
1528 }
1529
1530 private void printWSDLError(OutputStream out, Exception e) throws AxisFault {
1531 try {
1532 String wsdlntfound = "<error>"
1533 + "<description>Unable to generate WSDL 1.1 for this service</description>"
1534 + "<reason>If you wish Axis2 to automatically generate the WSDL 1.1, then please "
1535 + "set useOriginalwsdl as false in your services.xml</reason>";
1536 out.write(wsdlntfound.getBytes());
1537 if (e != null) {
1538 PrintWriter pw = new PrintWriter(out);
1539 e.printStackTrace(pw);
1540 pw.flush();
1541 }
1542 out.write("</error>".getBytes());
1543 out.flush();
1544 out.close();
1545 } catch (IOException ex) {
1546 throw AxisFault.makeFault(ex);
1547 }
1548 }
1549
1550 /**
1551 * Print the WSDL2.0 with a default URL. This will be called only during
1552 * codegen time.
1553 *
1554 * @param out
1555 * @throws AxisFault
1556 */
1557 public void printWSDL2(OutputStream out) throws AxisFault {
1558 printWSDL2(out, null);
1559 }
1560
1561 public void printWSDL2(OutputStream out, String requestIP) throws AxisFault {
1562 AxisService2WSDL20 axisService2WSDL2 = new AxisService2WSDL20(this);
1563 try {
1564 if (requestIP != null) {
1565 axisService2WSDL2.setEPRs(calculateEPRs(requestIP));
1566 }
1567 OMElement wsdlElement = axisService2WSDL2.generateOM();
1568 wsdlElement.serialize(out);
1569 out.flush();
1570 out.close();
1571 } catch (Exception e) {
1572 throw AxisFault.makeFault(e);
1573 }
1574 }
1575
1576 /**
1577 * Produces a WSDL2 for this AxisService and prints it to the specified
1578 * OutputStream.
1579 *
1580 * @param out
1581 * destination stream.
1582 * @param wsdl
1583 * wsdl name
1584 * @return -1 implies not found, 0 implies redirect to root, 1 implies
1585 * found/printed wsdl
1586 * @throws IOException
1587 */
1588 public int printWSDL2(OutputStream out, String requestIP, String wsdl)
1589 throws IOException, AxisFault {
1590 // a name is present - try to pump the requested wsdl file
1591 if (!"".equals(wsdl)) {
1592 // make sure we are only serving .wsdl files and ignore requests with
1593 // ".." in the name.
1594 if (wsdl.endsWith(".wsdl") && wsdl.indexOf("..") == -1) {
1595 InputStream in = getClassLoader().getResourceAsStream(
1596 DeploymentConstants.META_INF + "/" + wsdl);
1597 if (in != null) {
1598 IOUtils.copy(in, out, true);
1599 } else {
1600 // can't find the wsdl
1601 return -1;
1602 }
1603 } else {
1604 // bad wsdl2 request
1605 return -1;
1606 }
1607 } else {
1608 printWSDL2(out, requestIP);
1609 }
1610
1611 return 1;
1612 }
1613
1614 /**
1615 * Gets the description about the service which is specified in
1616 * services.xml.
1617 *
1618 * @return Returns String.
1619 * @deprecated Use getDocumentation() instead
1620 */
1621 public String getServiceDescription() {
1622 return getDocumentation();
1623 }
1624
1625 /**
1626 * Method getClassLoader.
1627 *
1628 * @return Returns ClassLoader.
1629 */
1630 public ClassLoader getClassLoader() {
1631 return this.serviceClassLoader;
1632 }
1633
1634 /**
1635 * Gets the control operation which are added by module like RM.
1636 */
1637 public ArrayList<AxisOperation> getControlOperations() {
1638 Iterator<AxisOperation> op_itr = getOperations();
1639 ArrayList<AxisOperation> operationList = new ArrayList<AxisOperation>();
1640
1641 while (op_itr.hasNext()) {
1642 AxisOperation operation = (AxisOperation) op_itr.next();
1643
1644 if (operation.isControlOperation()) {
1645 operationList.add(operation);
1646 }
1647 }
1648
1649 return operationList;
1650 }
1651
1652 public URL getFileName() {
1653 return fileName;
1654 }
1655
1656 /**
1657 * @deprecated please use getLastUpdate
1658 * @return
1659 */
1660 public long getLastupdate() {
1661 return lastupdate;
1662 }
1663
1664 public long getLastUpdate() {
1665 return lastupdate;
1666 }
1667
1668 public ModuleConfiguration getModuleConfig(String moduleName) {
1669 return (ModuleConfiguration) moduleConfigmap.get(moduleName);
1670 }
1671
1672 public ArrayList<String> getModules() {
1673 return moduleRefs;
1674 }
1675
1676 public String getName() {
1677 return name;
1678 }
1679
1680 /**
1681 * Method getOperation.
1682 *
1683 * @param operationName
1684 * @return Returns AxisOperation.
1685 */
1686 public AxisOperation getOperation(QName operationName) {
1687 if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
1688 log.debug("Get operation for " + operationName);
1689
1690 AxisOperation axisOperation = (AxisOperation) getChild(operationName);
1691
1692 if (axisOperation == null) {
1693 axisOperation = (AxisOperation) getChild(new QName(
1694 getTargetNamespace(), operationName.getLocalPart()));
1695
1696 if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
1697 log.debug("Target namespace: " + getTargetNamespace());
1698 }
1699
1700 if (axisOperation == null) {
1701 axisOperation = (AxisOperation) operationsAliasesMap
1702 .get(operationName.getLocalPart());
1703
1704 if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
1705 log.debug("Operations aliases map: " + operationsAliasesMap);
1706 }
1707
1708 //The operation may be associated with a namespace other than the
1709 //target namespace, e.g. if the operation is from an imported wsdl.
1710 if (axisOperation == null) {
1711 List namespaces = getImportedNamespaces();
1712
1713 if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
1714 log.debug("Imported namespaces: " + namespaces);
1715
1716 if (namespaces != null) {
1717 Iterator iterator = namespaces.iterator();
1718
1719 while (iterator.hasNext()) {
1720 String namespace = (String) iterator.next();
1721 axisOperation = (AxisOperation) getChild(new QName(
1722 namespace, operationName.getLocalPart()));
1723
1724 if (axisOperation != null)
1725 break;
1726 }
1727 }
1728 }
1729
1730 if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
1731 log.debug("Found axis operation: " + axisOperation);
1732
1733 return axisOperation;
1734 }
1735
1736 /**
1737 * Returns the AxisOperation which has been mapped to the given alias.
1738 *
1739 * @see #mapActionToOperation(String, AxisOperation)
1740 *
1741 * @param action
1742 * the alias key
1743 * @return Returns the corresponding AxisOperation or null if it isn't
1744 * found.
1745 */
1746 public AxisOperation getOperationByAction(String action) {
1747 return (AxisOperation) operationsAliasesMap.get(action);
1748 }
1749
1750 /**
1751 * Returns the operation given a SOAP Action. This method should be called
1752 * if only one Endpoint is defined for this Service. If more than one
1753 * Endpoint exists, one of them will be picked. If more than one Operation
1754 * is found with the given SOAP Action; null will be returned. If no
1755 * particular Operation is found with the given SOAP Action; null will be
1756 * returned. If the action is in the list of invaliad aliases, which means
1757 * it did not uniquely identify an operation, a null will be returned.
1758 *
1759 * @param soapAction
1760 * SOAP Action defined for the particular Operation
1761 * @return Returns an AxisOperation if a unique Operation can be found with
1762 * the given SOAP Action otherwise will return null.
1763 */
1764 public AxisOperation getOperationBySOAPAction(String soapAction) {
1765
1766 // Check for illegal soapActions
1767 if ((soapAction == null) || soapAction.length() == 0) {
1768 if (log.isDebugEnabled()) {
1769 log.debug("getOperationBySOAPAction: " + soapAction
1770 + " is null or ''. Returning null.");
1771 }
1772 return null;
1773 }
1774
1775 // If the action maps to an alais that is not unique, then it can't be
1776 // used to map to
1777 // an operation.
1778 if (invalidOperationsAliases.contains(soapAction)) {
1779 if (log.isDebugEnabled()) {
1780 log.debug("getOperationBySOAPAction: " + soapAction
1781 + " is an invalid operation alias. Returning null.");
1782 }
1783 return null;
1784 }
1785
1786 // Get the operation from the action->operation map
1787 AxisOperation operation = (AxisOperation) operationsAliasesMap
1788 .get(soapAction);
1789
1790 if (operation != null) {
1791 if (log.isDebugEnabled()) {
1792 log.debug("getOperationBySOAPAction: Operation (" + operation
1793 + "," + operation.getName() + ") for soapAction: "
1794 + soapAction + " found in action map.");
1795 }
1796 return operation;
1797 }
1798
1799 // The final fallback is to check the operations for a matching name.
1800
1801 Iterator children = getChildren();
1802 // I could not find any spec statement that explicitly forbids using a
1803 // short name in the SOAPAction header or wsa:Action element,
1804 // so I believe this to be valid. There may be customers using the
1805 // shortname as the SOAPAction in their client code that would
1806 // also require this support.
1807 while (children.hasNext() && (operation == null)) {
1808 AxisOperation op = (AxisOperation) children.next();
1809 if (op.getName().getLocalPart().equals(soapAction)) {
1810 operation = op;
1811 }
1812 }
1813
1814 if (operation != null) {
1815 if (log.isDebugEnabled()) {
1816 log.debug("getOperationBySOAPAction: Operation (" + operation
1817 + "," + operation.getName() + ") for soapAction: "
1818 + soapAction + " found as child.");
1819 }
1820 }
1821
1822 return operation;
1823 }
1824
1825 /**
1826 * Method getOperations.
1827 *
1828 * @return Returns HashMap
1829 */
1830 public Iterator<AxisOperation> getOperations() {
1831 return (Iterator<AxisOperation>) getChildren();
1832 }
1833
1834 /*
1835 * (non-Javadoc)
1836 *
1837 * @see org.apache.axis2.description.ParameterInclude#getParameter(java.lang.String)
1838 */
1839
1840 /**
1841 * Gets only the published operations.
1842 */
1843 public ArrayList<AxisOperation> getPublishedOperations() {
1844 Iterator<AxisOperation> op_itr = getOperations();
1845 ArrayList<AxisOperation> operationList = new ArrayList<AxisOperation>();
1846
1847 while (op_itr.hasNext()) {
1848 AxisOperation operation = (AxisOperation) op_itr.next();
1849
1850 if (!operation.isControlOperation()) {
1851 operationList.add(operation);
1852 }
1853 }
1854
1855 return operationList;
1856 }
1857
1858 /**
1859 * Sets the description about the service which is specified in services.xml
1860 *
1861 * @param documentation
1862 * @deprecated Use setDocumentation() instead
1863 */
1864 public void setServiceDescription(String documentation) {
1865 setDocumentation(documentation);
1866 }
1867
1868 /**
1869 * Method setClassLoader.
1870 *
1871 * @param classLoader
1872 */
1873 public void setClassLoader(ClassLoader classLoader) {
1874 this.serviceClassLoader = classLoader;
1875 }
1876
1877 public void setFileName(URL fileName) {
1878 this.fileName = fileName;
1879 }
1880
1881 /**
1882 * Sets the current time as last update time of the service.
1883 * @deprecated please use setLastUpdate
1884 */
1885 public void setLastupdate() {
1886 lastupdate = new Date().getTime();
1887 }
1888
1889 /**
1890 * Sets the current time as last update time of the service.
1891 */
1892 public void setLastUpdate() {
1893 lastupdate = new Date().getTime();
1894 }
1895
1896 public void setName(String name) {
1897 this.name = name;
1898 }
1899
1900 public ArrayList<XmlSchema> getSchema() {
1901 return schemaList;
1902 }
1903
1904 public void addSchema(XmlSchema schema) {
1905 if (schema != null) {
1906 schemaList.add(schema);
1907 if (schema.getTargetNamespace() != null) {
1908 addSchemaNameSpace(schema);
1909 }
1910 }
1911 }
1912
1913 public void addSchema(Collection<XmlSchema> schemas) {
1914 Iterator<XmlSchema> iterator = schemas.iterator();
1915 while (iterator.hasNext()) {
1916 XmlSchema schema = (XmlSchema) iterator.next();
1917 schemaList.add(schema);
1918 addSchemaNameSpace(schema);
1919 }
1920 }
1921
1922 public boolean isWsdlFound() {
1923 return wsdlFound;
1924 }
1925
1926 public void setWsdlFound(boolean wsdlFound) {
1927 this.wsdlFound = wsdlFound;
1928 }
1929
1930 public String getScope() {
1931 return scope;
1932 }
1933
1934 /**
1935 * @param scope -
1936 * Available scopes : Constants.SCOPE_APPLICATION
1937 * Constants.SCOPE_TRANSPORT_SESSION Constants.SCOPE_SOAP_SESSION
1938 * Constants.SCOPE_REQUEST.equals
1939 */
1940 public void setScope(String scope) {
1941 if (Constants.SCOPE_APPLICATION.equals(scope)
1942 || Constants.SCOPE_TRANSPORT_SESSION.equals(scope)
1943 || Constants.SCOPE_SOAP_SESSION.equals(scope)
1944 || Constants.SCOPE_REQUEST.equals(scope)) {
1945 this.scope = scope;
1946 }
1947 }
1948
1949 public boolean isUseDefaultChains() {
1950 return useDefaultChains;
1951 }
1952
1953 public void setUseDefaultChains(boolean useDefaultChains) {
1954 this.useDefaultChains = useDefaultChains;
1955 }
1956
1957 public Object getKey() {
1958 return this.name;
1959 }
1960
1961 public boolean isActive() {
1962 return active;
1963 }
1964
1965 public void setActive(boolean active) {
1966 this.active = active;
1967 }
1968
1969 /**
1970 * @deprecated please use getSchemaTargetNamespace
1971 * @return
1972 */
1973 public String getSchematargetNamespace() {
1974 return schematargetNamespace;
1975 }
1976
1977 public String getSchemaTargetNamespace() {
1978 return schematargetNamespace;
1979 }
1980
1981 public void setSchemaTargetNamespace(String schematargetNamespace) {
1982 this.schematargetNamespace = schematargetNamespace;
1983 }
1984
1985 public String getSchemaTargetNamespacePrefix() {
1986 return schematargetNamespacePrefix;
1987 }
1988
1989 /**
1990 * @deprecated please use setSchemaTargetNamespacePrefix
1991 * @param schematargetNamespacePrefix
1992 */
1993 public void setSchematargetNamespacePrefix(
1994 String schematargetNamespacePrefix) {
1995 this.schematargetNamespacePrefix = schematargetNamespacePrefix;
1996 }
1997
1998 public void setSchemaTargetNamespacePrefix(
1999 String schematargetNamespacePrefix) {
2000 this.schematargetNamespacePrefix = schematargetNamespacePrefix;
2001 }
2002
2003 public String getTargetNamespace() {
2004 return targetNamespace;
2005 }
2006
2007 public void setTargetNamespace(String targetNamespace) {
2008 this.targetNamespace = targetNamespace;
2009 }
2010
2011 public String getTargetNamespacePrefix() {
2012 return targetNamespacePrefix;
2013 }
2014
2015 public void setTargetNamespacePrefix(String targetNamespacePrefix) {
2016 this.targetNamespacePrefix = targetNamespacePrefix;
2017 }
2018
2019 public XmlSchemaElement getSchemaElement(QName elementQName) {
2020 XmlSchemaElement element;
2021 for (int i = 0; i < schemaList.size(); i++) {
2022 XmlSchema schema = (XmlSchema) schemaList.get(i);
2023 if (schema != null) {
2024 element = schema.getElementByName(elementQName);
2025 if (element != null) {
2026 return element;
2027 }
2028 }
2029 }
2030 return null;
2031 }
2032
2033 public boolean isEnableAllTransports() {
2034 return enableAllTransports;
2035 }
2036
2037 /**
2038 * To eneble service to be expose in all the transport
2039 *
2040 * @param enableAllTransports
2041 */
2042 public void setEnableAllTransports(boolean enableAllTransports) {
2043 this.enableAllTransports = enableAllTransports;
2044 eprs = calculateEPRs();
2045 }
2046
2047 public List<String> getExposedTransports() {
2048 return this.exposedTransports;
2049 }
2050
2051 public void setExposedTransports(List transports) {
2052 enableAllTransports = false;
2053 this.exposedTransports = transports;
2054 eprs = null; // Do not remove this. We need to force EPR
2055 // recalculation.
2056 }
2057
2058 public void addExposedTransport(String transport) {
2059 enableAllTransports = false;
2060 if (!this.exposedTransports.contains(transport)) {
2061 this.exposedTransports.add(transport);
2062 try {
2063 eprs = calculateEPRs();
2064 } catch (Exception e) {
2065 eprs = null;
2066 }
2067 }
2068 }
2069
2070 public void removeExposedTransport(String transport) {
2071 enableAllTransports = false;
2072 this.exposedTransports.remove(transport);
2073 try {
2074 eprs = calculateEPRs();
2075 } catch (Exception e) {
2076 eprs = null;
2077 }
2078 }
2079
2080 public boolean isExposedTransport(String transport) {
2081 return exposedTransports.contains(transport);
2082 }
2083
2084 public void onDisengage(AxisModule module) throws AxisFault {
2085 removeModuleOperations(module);
2086 for (Iterator operations = getChildren(); operations.hasNext();) {
2087 AxisOperation axisOperation = (AxisOperation) operations.next();
2088 axisOperation.disengageModule(module);
2089 }
2090 AxisConfiguration config = getAxisConfiguration();
2091 if (!config.isEngaged(module.getName())) {
2092 PhaseResolver phaseResolver = new PhaseResolver(config);
2093 phaseResolver.disengageModuleFromGlobalChains(module);
2094 }
2095 }
2096
2097 /**
2098 * Remove any operations which were added by a given module.
2099 *
2100 * @param module
2101 * the module in question
2102 */
2103 private void removeModuleOperations(AxisModule module) {
2104 HashMap<QName, AxisOperation> moduleOperations = module.getOperations();
2105 if (moduleOperations != null) {
2106 for (Iterator<AxisOperation> modOpsIter = moduleOperations.values().iterator(); modOpsIter
2107 .hasNext();) {
2108 AxisOperation operation = (AxisOperation) modOpsIter.next();
2109 removeOperation(operation.getName());
2110 }
2111 }
2112 }
2113
2114 // #######################################################################################
2115 // APIs to create AxisService
2116
2117 //
2118
2119 /**
2120 * To create a AxisService for a given WSDL and the created client is most
2121 * suitable for client side invocation not for server side invocation. Since
2122 * all the soap action and wsa action is added to operations
2123 *
2124 * @param wsdlURL
2125 * location of the WSDL
2126 * @param wsdlServiceName
2127 * name of the service to be invoke , if it is null then the
2128 * first one will be selected if there are more than one
2129 * @param portName
2130 * name of the port , if there are more than one , if it is null
2131 * then the first one in the iterator will be selected
2132 * @param options
2133 * Service client options, to set the target EPR
2134 * @return AxisService , the created service will be return
2135 */
2136 public static AxisService createClientSideAxisService(URL wsdlURL,
2137 QName wsdlServiceName, String portName, Options options)
2138 throws AxisFault {
2139 try {
2140 InputStream in = wsdlURL.openConnection().getInputStream();
2141 Document doc = XMLUtils.newDocument(in);
2142 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
2143 reader.setFeature("javax.wsdl.importDocuments", true);
2144 Definition wsdlDefinition = reader.readWSDL(getBaseURI(wsdlURL
2145 .toString()), doc);
2146 if (wsdlDefinition != null) {
2147 wsdlDefinition.setDocumentBaseURI(getDocumentURI(wsdlURL
2148 .toString()));
2149 }
2150 return createClientSideAxisService(wsdlDefinition, wsdlServiceName,
2151 portName, options);
2152 } catch (IOException e) {
2153 log.error(e.getMessage(), e);
2154 throw AxisFault.makeFault(e);
2155 } catch (ParserConfigurationException e) {
2156 log.error(e.getMessage(), e);
2157 throw AxisFault.makeFault(e);
2158 } catch (SAXException e) {
2159 log.error(e.getMessage(), e);
2160 throw AxisFault.makeFault(e);
2161 } catch (WSDLException e) {
2162 log.error(e.getMessage(), e);
2163 throw AxisFault.makeFault(e);
2164 }
2165 }
2166
2167 private static String getBaseURI(String currentURI) {
2168 try {
2169 File file = new File(currentURI);
2170 if (file.exists()) {
2171 return file.getCanonicalFile().getParentFile().toURI()
2172 .toString();
2173 }
2174 String uriFragment = currentURI.substring(0, currentURI
2175 .lastIndexOf("/"));
2176 return uriFragment + (uriFragment.endsWith("/") ? "" : "/");
2177 } catch (IOException e) {
2178 return null;
2179 }
2180 }
2181
2182 private static String getDocumentURI(String currentURI) {
2183 try {
2184 File file = new File(currentURI);
2185 return file.getCanonicalFile().toURI().toString();
2186 } catch (IOException e) {
2187 return null;
2188 }
2189 }
2190
2191 public static AxisService createClientSideAxisService(
2192 Definition wsdlDefinition, QName wsdlServiceName, String portName,
2193 Options options) throws AxisFault {
2194 WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(
2195 wsdlDefinition, wsdlServiceName, portName);
2196 serviceBuilder.setServerSide(false);
2197 AxisService axisService = serviceBuilder.populateService();
2198 AxisEndpoint axisEndpoint = (AxisEndpoint) axisService.getEndpoints()
2199 .get(axisService.getEndpointName());
2200 options.setTo(new EndpointReference(axisEndpoint.getEndpointURL()));
2201 if (axisEndpoint != null) {
2202 options.setSoapVersionURI((String) axisEndpoint.getBinding()
2203 .getProperty(WSDL2Constants.ATTR_WSOAP_VERSION));
2204 }
2205 return axisService;
2206 }
2207
2208 /**
2209 * To create an AxisService using given service impl class name first
2210 * generate schema corresponding to the given java class , next for each
2211 * methods AxisOperation will be created. If the method is in-out it will
2212 * uses RPCMessageReceiver else RPCInOnlyMessageReceiver <p/> Note : Inorder
2213 * to work this properly RPCMessageReceiver should be available in the class
2214 * path otherewise operation can not continue
2215 *
2216 * @param implClass
2217 * Service implementation class
2218 * @param axisConfig
2219 * Current AxisConfiguration
2220 * @return return created AxisSrevice the creted service , it can either be
2221 * null or valid service
2222 */
2223 public static AxisService createService(String implClass,
2224 AxisConfiguration axisConfig) throws AxisFault {
2225
2226 try {
2227 HashMap<String, MessageReceiver> messageReciverMap = new HashMap<String, MessageReceiver>();
2228 Class inOnlyMessageReceiver = Loader
2229 .loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
2230 MessageReceiver messageReceiver = (MessageReceiver) inOnlyMessageReceiver
2231 .newInstance();
2232 messageReciverMap.put(WSDL2Constants.MEP_URI_IN_ONLY,
2233 messageReceiver);
2234 Class inoutMessageReceiver = Loader
2235 .loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
2236 MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver
2237 .newInstance();
2238 messageReciverMap.put(WSDL2Constants.MEP_URI_IN_OUT,
2239 inOutmessageReceiver);
2240 messageReciverMap.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
2241 inOutmessageReceiver);
2242
2243 return createService(implClass, axisConfig, messageReciverMap,
2244 null, null, axisConfig.getSystemClassLoader());
2245 } catch (Exception e) {
2246 throw AxisFault.makeFault(e);
2247 }
2248 }
2249
2250 /**
2251 * messageReceiverClassMap will hold the MessageReceivers for given meps.
2252 * Key will be the mep and value will be the instance of the MessageReceiver
2253 * class. Ex: Map mrMap = new HashMap();
2254 * mrMap.put("http://www.w3.org/2004/08/wsdl/in-only",
2255 * RPCInOnlyMessageReceiver.class.newInstance());
2256 * mrMap.put("http://www.w3.org/2004/08/wsdl/in-out",
2257 * RPCMessageReceiver.class.newInstance());
2258 *
2259 * @param implClass
2260 * @param axisConfiguration
2261 * @param messageReceiverClassMap
2262 * @param targetNamespace
2263 * @param schemaNamespace
2264 * @throws AxisFault
2265 */
2266 public static AxisService createService(String implClass,
2267 AxisConfiguration axisConfiguration, Map messageReceiverClassMap,
2268 String targetNamespace, String schemaNamespace, ClassLoader loader)
2269 throws AxisFault {
2270 int index = implClass.lastIndexOf(".");
2271 String serviceName;
2272 if (index > 0) {
2273 serviceName = implClass.substring(index + 1, implClass.length());
2274 } else {
2275 serviceName = implClass;
2276 }
2277
2278 SchemaGenerator schemaGenerator;
2279 ArrayList excludeOpeartion = new ArrayList();
2280 AxisService service = new AxisService();
2281 service.setParent(axisConfiguration);
2282 service.setName(serviceName);
2283
2284 try {
2285 Parameter generateBare = service
2286 .getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
2287 if (generateBare != null && "true".equals(generateBare.getValue())) {
2288 schemaGenerator = new DocLitBareSchemaGenerator(loader,
2289 implClass, schemaNamespace,
2290 Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX, service);
2291 } else {
2292 schemaGenerator = new DefaultSchemaGenerator(loader, implClass,
2293 schemaNamespace,
2294 Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX, service);
2295 }
2296 schemaGenerator
2297 .setElementFormDefault(Java2WSDLConstants.FORM_DEFAULT_UNQUALIFIED);
2298 Utils.addExcludeMethods(excludeOpeartion);
2299 schemaGenerator.setExcludeMethods(excludeOpeartion);
2300 } catch (Exception e) {
2301 throw AxisFault.makeFault(e);
2302 }
2303
2304 return createService(implClass, serviceName, axisConfiguration,
2305 messageReceiverClassMap, targetNamespace, loader,
2306 schemaGenerator, service);
2307 }
2308
2309 /**
2310 * messageReceiverClassMap will hold the MessageReceivers for given meps.
2311 * Key will be the mep and value will be the instance of the MessageReceiver
2312 * class. Ex: Map mrMap = new HashMap();
2313 * mrMap.put("http://www.w3.org/2004/08/wsdl/in-only",
2314 * RPCInOnlyMessageReceiver.class.newInstance());
2315 * mrMap.put("http://www.w3.org/2004/08/wsdl/in-out",
2316 * RPCMessageReceiver.class.newInstance());
2317 *
2318 * @param implClass
2319 * @param axisConfiguration
2320 * @param messageReceiverClassMap
2321 * @param targetNamespace
2322 * @throws AxisFault
2323 */
2324 public static AxisService createService(String implClass,
2325 String serviceName, AxisConfiguration axisConfiguration,
2326 Map<String, MessageReceiver> messageReceiverClassMap, String targetNamespace,
2327 ClassLoader loader, SchemaGenerator schemaGenerator,
2328 AxisService axisService) throws AxisFault {
2329 Parameter parameter = new Parameter(Constants.SERVICE_CLASS, implClass);
2330 OMElement paraElement = Utils.getParameter(Constants.SERVICE_CLASS,
2331 implClass, false);
2332 parameter.setParameterElement(paraElement);
2333 axisService.setUseDefaultChains(false);
2334 axisService.addParameter(parameter);
2335 axisService.setName(serviceName);
2336 axisService.setClassLoader(loader);
2337
2338 NamespaceMap map = new NamespaceMap();
2339 map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX,
2340 Java2WSDLConstants.AXIS2_XSD);
2341 map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX,
2342 Java2WSDLConstants.URI_2001_SCHEMA_XSD);
2343 axisService.setNamespaceMap(map);
2344 Utils.processBeanPropertyExclude(axisService);
2345 axisService.setElementFormDefault(false);
2346 try {
2347 axisService.addSchema(schemaGenerator.generateSchema());
2348 } catch (Exception e) {
2349 throw AxisFault.makeFault(e);
2350 }
2351 axisService.setSchemaTargetNamespace(schemaGenerator
2352 .getSchemaTargetNameSpace());
2353 axisService.setTypeTable(schemaGenerator.getTypeTable());
2354 if (targetNamespace == null) {
2355 targetNamespace = schemaGenerator.getSchemaTargetNameSpace();
2356 }
2357 if (targetNamespace != null && !"".equals(targetNamespace)) {
2358 axisService.setTargetNamespace(targetNamespace);
2359 }
2360 Method[] method = schemaGenerator.getMethods();
2361 PhasesInfo pinfo = axisConfiguration.getPhasesInfo();
2362 for (int i = 0; i < method.length; i++) {
2363 Method jmethod = method[i];
2364 AxisOperation operation = axisService.getOperation(new QName(
2365 jmethod.getName()));
2366 String mep = operation.getMessageExchangePattern();
2367 MessageReceiver mr;
2368 if (messageReceiverClassMap != null) {
2369
2370 if (messageReceiverClassMap.get(mep) != null) {
2371 Object obj = messageReceiverClassMap.get(mep);
2372 if (obj instanceof MessageReceiver) {
2373 mr = (MessageReceiver) obj;
2374 operation.setMessageReceiver(mr);
2375 } else {
2376 log
2377 .error("Object is not an instance of MessageReceiver, thus, default MessageReceiver has been set");
2378 mr = axisConfiguration.getMessageReceiver(operation
2379 .getMessageExchangePattern());
2380 operation.setMessageReceiver(mr);
2381 }
2382 } else {
2383 log
2384 .error("Required MessageReceiver couldn't be found, thus, default MessageReceiver has been used");
2385 mr = axisConfiguration.getMessageReceiver(operation
2386 .getMessageExchangePattern());
2387 operation.setMessageReceiver(mr);
2388 }
2389 } else {
2390 log
2391 .error("MessageRecevierClassMap couldn't be found, thus, default MessageReceiver has been used");
2392 mr = axisConfiguration.getMessageReceiver(operation
2393 .getMessageExchangePattern());
2394 operation.setMessageReceiver(mr);
2395 }
2396 pinfo.setOperationPhases(operation);
2397 axisService.addOperation(operation);
2398 }
2399
2400 String endpointName = axisService.getEndpointName();
2401 if ((endpointName == null || endpointName.length() == 0)
2402 && axisService.getAxisConfiguration() != null) {
2403 Utils.addEndpointsToService(axisService, axisService.getAxisConfiguration());
2404 }
2405
2406 return axisService;
2407
2408 }
2409
2410 public void removeOperation(QName opName) {
2411 AxisOperation operation = getOperation(opName);
2412 if (operation != null) {
2413 removeChild(opName);
2414 ArrayList<String> mappingList = operation.getWSAMappingList();
2415 if (mappingList != null) {
2416 for (int i = 0; i < mappingList.size(); i++) {
2417 String actionMapping = (String) mappingList.get(i);
2418 operationsAliasesMap.remove(actionMapping);
2419 }
2420 }
2421 operationsAliasesMap.remove(operation.getName().getLocalPart());
2422 }
2423 }
2424
2425 /**
2426 * Get the namespace map for this service.
2427 *
2428 * @return a Map of prefix (String) to namespace URI (String)
2429 * @deprecated please use getNamespaceMap()
2430 */
2431 public Map<String, String> getNameSpacesMap() {
2432 return namespaceMap;
2433 }
2434
2435 /**
2436 * Get the namespace map for this service.
2437 *
2438 * @return a Map of prefix (String) to namespace URI (String)
2439 */
2440 public Map getNamespaceMap() {
2441 return namespaceMap;
2442 }
2443
2444 /**
2445 * Get the namespaces associated with imported WSDLs
2446 *
2447 * @return a <code>List</code> of namespace URIs (String)
2448 */
2449 public List getImportedNamespaces() {
2450 return importedNamespaces;
2451 }
2452
2453 /**
2454 * Set the namespaces associated with imported WSDLs
2455 *
2456 * @param importedNamespaces
2457 */
2458 public void setImportedNamespaces(List importedNamespaces) {
2459 this.importedNamespaces = importedNamespaces;
2460 }
2461
2462 /**
2463 * @deprecated please use setNamespaceMap
2464 * @param nameSpacesMap
2465 */
2466 public void setNameSpacesMap(NamespaceMap nameSpacesMap) {
2467 this.namespaceMap = nameSpacesMap;
2468 }
2469
2470 public void setNamespaceMap(NamespaceMap namespaceMap) {
2471 this.namespaceMap = namespaceMap;
2472 }
2473
2474 private void addSchemaNameSpace(XmlSchema schema) {
2475 String targetNameSpace = schema.getTargetNamespace();
2476 String prefix = schema.getNamespaceContext().getPrefix(targetNameSpace);
2477
2478 if (namespaceMap == null) {
2479 namespaceMap = new NamespaceMap();
2480 }
2481
2482 if (!namespaceMap.values().contains(targetNameSpace)) {
2483 // i.e this target namespace not exists in the namesapce map
2484 // find a non exists prefix to add this target namesapce
2485 while ((prefix == null) || namespaceMap.keySet().contains(prefix)) {
2486 prefix = "ns" + nsCount++;
2487 }
2488 namespaceMap.put(prefix, targetNameSpace);
2489 }
2490
2491 }
2492
2493 public Map populateSchemaMappings() {
2494 // when calling from other than codegen. i.e from deployment
2495 // engine we don't have to override the absolute http locations.
2496 return populateSchemaMappings(false);
2497 }
2498
2499 /**
2500 * runs the schema mappings if it has not been run previously it is best
2501 * that this logic be in the axis service since one can call the axis
2502 * service to populate the schema mappings
2503 */
2504 public Map populateSchemaMappings(boolean overrideAbsoluteAddress) {
2505
2506 // populate the axis service with the necessary schema references
2507 ArrayList schema = this.schemaList;
2508 Map changedSchemaLocations = null;
2509 if (!this.schemaLocationsAdjusted) {
2510 Hashtable nameTable = new Hashtable();
2511 Hashtable sourceURIToNewLocationMap = new Hashtable();
2512 // calculate unique names for the schemas
2513 calculateSchemaNames(schema, nameTable, sourceURIToNewLocationMap,
2514 overrideAbsoluteAddress);
2515 // adjust the schema locations as per the calculated names
2516 changedSchemaLocations = adjustSchemaNames(schema, nameTable,
2517 sourceURIToNewLocationMap);
2518 // reverse the nametable so that there is a mapping from the
2519 // name to the schemaObject
2520 setSchemaMappingTable(swapMappingTable(nameTable));
2521 setSchemaLocationsAdjusted(true);
2522 }
2523 return changedSchemaLocations;
2524 }
2525
2526 /**
2527 * run 1 -calcualte unique names
2528 *
2529 * @param schemas
2530 */
2531 private void calculateSchemaNames(List schemas, Hashtable nameTable,
2532 Hashtable sourceURIToNewLocationMap, boolean overrideAbsoluteAddress) {
2533 // first traversal - fill the hashtable
2534 for (int i = 0; i < schemas.size(); i++) {
2535 XmlSchema schema = (XmlSchema) schemas.get(i);
2536 XmlSchemaObjectCollection includes = schema.getIncludes();
2537
2538 for (int j = 0; j < includes.getCount(); j++) {
2539 Object item = includes.getItem(j);
2540 XmlSchema s;
2541 if (item instanceof XmlSchemaExternal) {
2542 XmlSchemaExternal externalSchema = (XmlSchemaExternal) item;
2543 s = externalSchema.getSchema();
2544
2545 if (s != null
2546 && getScheamLocationWithDot(
2547 sourceURIToNewLocationMap, s) == null) {
2548 // insert the name into the table
2549 insertIntoNameTable(nameTable, s,
2550 sourceURIToNewLocationMap,
2551 overrideAbsoluteAddress);
2552 // recursively call the same procedure
2553 calculateSchemaNames(Arrays
2554 .asList(new XmlSchema[] { s }), nameTable,
2555 sourceURIToNewLocationMap,
2556 overrideAbsoluteAddress);
2557 }
2558 }
2559 }
2560 }
2561 }
2562
2563 /**
2564 * A quick private sub routine to insert the names
2565 *
2566 * @param nameTable
2567 * @param s
2568 */
2569 private void insertIntoNameTable(Hashtable nameTable, XmlSchema s,
2570 Hashtable sourceURIToNewLocationMap, boolean overrideAbsoluteAddress) {
2571 String sourceURI = s.getSourceURI();
2572 // check whether the sourece uri is an absolute one and are
2573 // we allowed to override it.
2574 // if the absolute uri overriding is not allowed the use the
2575 // original sourceURI as new one
2576 if (sourceURI.startsWith("http") && !overrideAbsoluteAddress) {
2577 nameTable.put(s, sourceURI);
2578 sourceURIToNewLocationMap.put(sourceURI, sourceURI);
2579 } else {
2580 String newURI = sourceURI.substring(sourceURI.lastIndexOf('/') + 1);
2581 if (newURI.endsWith(".xsd")) {
2582 // remove the .xsd extention
2583 newURI = newURI.substring(0, newURI.lastIndexOf("."));
2584 } else {
2585 newURI = "xsd" + count++;
2586 }
2587
2588 newURI = customSchemaNameSuffix != null ? newURI
2589 + customSchemaNameSuffix : newURI;
2590 // make it unique
2591 while (nameTable.containsValue(newURI)) {
2592 newURI = newURI + count++;
2593 }
2594
2595 nameTable.put(s, newURI);
2596 sourceURIToNewLocationMap.put(sourceURI, newURI);
2597 }
2598
2599 }
2600
2601 /**
2602 * Run 2 - adjust the names
2603 */
2604 private Map adjustSchemaNames(List schemas, Hashtable nameTable,
2605 Hashtable sourceURIToNewLocationMap) {
2606 Hashtable importedSchemas = new Hashtable();
2607 // process the schemas in the main schema list
2608 for (int i = 0; i < schemas.size(); i++) {
2609 adjustSchemaName((XmlSchema) schemas.get(i), nameTable,
2610 importedSchemas, sourceURIToNewLocationMap);
2611 }
2612 // process all the rest in the name table
2613 Enumeration nameTableKeys = nameTable.keys();
2614 while (nameTableKeys.hasMoreElements()) {
2615 adjustSchemaName((XmlSchema) nameTableKeys.nextElement(),
2616 nameTable, importedSchemas, sourceURIToNewLocationMap);
2617
2618 }
2619 return importedSchemas;
2620 }
2621
2622 /**
2623 * Adjust a single schema
2624 *
2625 * @param parentSchema
2626 * @param nameTable
2627 */
2628 private void adjustSchemaName(XmlSchema parentSchema, Hashtable nameTable,
2629 Hashtable importedScheams, Hashtable sourceURIToNewLocationMap) {
2630 XmlSchemaObjectCollection includes = parentSchema.getIncludes();
2631 for (int j = 0; j < includes.getCount(); j++) {
2632 Object item = includes.getItem(j);
2633 if (item instanceof XmlSchemaExternal) {
2634 XmlSchemaExternal xmlSchemaExternal = (XmlSchemaExternal) item;
2635 XmlSchema s = xmlSchemaExternal.getSchema();
2636 adjustSchemaLocation(s, xmlSchemaExternal, nameTable,
2637 importedScheams, sourceURIToNewLocationMap);
2638 }
2639 }
2640
2641 }
2642
2643 /**
2644 * Adjusts a given schema location
2645 *
2646 * @param s
2647 * @param xmlSchemaExternal
2648 * @param nameTable
2649 */
2650 private void adjustSchemaLocation(XmlSchema s,
2651 XmlSchemaExternal xmlSchemaExternal, Hashtable nameTable,
2652 Hashtable importedScheams, Hashtable sourceURIToNewLocationMap) {
2653 if (s != null) {
2654 String schemaLocation = xmlSchemaExternal.getSchemaLocation();
2655
2656 String newscheamlocation = customSchemaNamePrefix == null ?
2657 // use the default mode
2658 (this.getServiceEPR() + "?xsd=" + getScheamLocationWithDot(
2659 sourceURIToNewLocationMap, s))
2660 :
2661 // custom prefix is present - add the custom prefix
2662 (customSchemaNamePrefix + getScheamLocationWithDot(
2663 sourceURIToNewLocationMap, s));
2664 xmlSchemaExternal.setSchemaLocation(newscheamlocation);
2665 importedScheams.put(schemaLocation, newscheamlocation);
2666 }
2667 }
2668
2669 private Object getScheamLocationWithDot(
2670 Hashtable sourceURIToNewLocationMap, XmlSchema s) {
2671 String o = (String) sourceURIToNewLocationMap.get(s.getSourceURI());
2672 if (o != null && o.indexOf(".") < 0) {
2673 return o + ".xsd";
2674 }
2675 return o;
2676 }
2677
2678 /**
2679 * Swap the key,value pairs
2680 *
2681 * @param originalTable
2682 */
2683 private Map swapMappingTable(Map originalTable) {
2684 HashMap swappedTable = new HashMap(originalTable.size());
2685 Iterator keys = originalTable.keySet().iterator();
2686 Object key;
2687 while (keys.hasNext()) {
2688 key = keys.next();
2689 swappedTable.put(originalTable.get(key), key);
2690 }
2691
2692 return swappedTable;
2693 }
2694
2695 public boolean isClientSide() {
2696 return clientSide;
2697 }
2698
2699 public void setClientSide(boolean clientSide) {
2700 this.clientSide = clientSide;
2701 }
2702
2703 public boolean isElementFormDefault() {
2704 return elementFormDefault;
2705 }
2706
2707 public void setElementFormDefault(boolean elementFormDefault) {
2708 this.elementFormDefault = elementFormDefault;
2709 }
2710
2711 /**
2712 * User can set a parameter in services.xml saying he want to show the
2713 * original wsdl that he put into META-INF once someone ask for ?wsdl so if
2714 * you want to use your own wsdl then add following parameter into
2715 * services.xml <parameter name="useOriginalwsdl">true</parameter>
2716 */
2717 public boolean isUseUserWSDL() {
2718 Parameter parameter = getParameter("useOriginalwsdl");
2719 if (parameter != null) {
2720 String value = (String) parameter.getValue();
2721 if ("true".equals(value)) {
2722 return true;
2723 }
2724 }
2725 return false;
2726 }
2727
2728 /**
2729 * By default the port address in user WSDLs is modified, set the following
2730 * parameter to override this behaviour <parameter
2731 * name="modifyUserWSDLPortAddress">false</parameter>
2732 */
2733 public boolean isModifyUserWSDLPortAddress() {
2734 Parameter parameter = getParameter("modifyUserWSDLPortAddress");
2735 if (parameter != null) {
2736 String value = (String) parameter.getValue();
2737 if ("false".equals(value)) {
2738 return false;
2739 }
2740 }
2741 return true;
2742 }
2743
2744 public ServiceLifeCycle getServiceLifeCycle() {
2745 return serviceLifeCycle;
2746 }
2747
2748 public void setServiceLifeCycle(ServiceLifeCycle serviceLifeCycle) {
2749 this.serviceLifeCycle = serviceLifeCycle;
2750 }
2751
2752 public Map getP2nMap() {
2753 return p2nMap;
2754 }
2755
2756 public void setP2nMap(Map p2nMap) {
2757 this.p2nMap = p2nMap;
2758 }
2759
2760 public ObjectSupplier getObjectSupplier() {
2761 return objectSupplier;
2762 }
2763
2764 public void setObjectSupplier(ObjectSupplier objectSupplier) {
2765 this.objectSupplier = objectSupplier;
2766 }
2767
2768 public TypeTable getTypeTable() {
2769 return typeTable;
2770 }
2771
2772 public void setTypeTable(TypeTable typeTable) {
2773 this.typeTable = typeTable;
2774 }
2775
2776 /**
2777 * Find a data locator from the available data locators (both configured and
2778 * default ones) to retrieve Metadata or data specified in the request.
2779 *
2780 * @param request
2781 * an {@link DataRetrievalRequest} object
2782 * @param msgContext
2783 * message context
2784 * @return array of {@link Data} object for the request.
2785 * @throws AxisFault
2786 */
2787
2788 public Data[] getData(DataRetrievalRequest request,
2789 MessageContext msgContext) throws AxisFault {
2790
2791 Data[] data;
2792 String dialect = request.getDialect();
2793 AxisDataLocator dataLocator = null;
2794 int nextDataLocatorIndex = 0;
2795 int totalLocators = availableDataLocatorTypes.length;
2796 for (int i = 0; i < totalLocators; i++) {
2797 dataLocator = getDataLocator(availableDataLocatorTypes[i], dialect);
2798 if (dataLocator != null) {
2799 nextDataLocatorIndex = i + 1;
2800 break;
2801 }
2802 }
2803
2804 if (dataLocator == null) {
2805 return null;
2806 }
2807
2808 data = dataLocator.getData(request, msgContext);
2809 // Null means Data Locator not understood request. Automatically find
2810 // Data Locator in the hierarchy to process the request.
2811 if (data == null) {
2812 if (nextDataLocatorIndex < totalLocators) {
2813 data = bubbleupDataLocators(nextDataLocatorIndex, request,
2814 msgContext);
2815 }
2816
2817 }
2818 return data;
2819 }
2820
2821 /*
2822 * To search the next Data Locator from the available Data Locators that
2823 * understood the data retrieval request.
2824 */
2825 private Data[] bubbleupDataLocators(int nextIndex,
2826 DataRetrievalRequest request, MessageContext msgContext)
2827 throws AxisFault {
2828 Data[] data = null;
2829 if (nextIndex < availableDataLocatorTypes.length) {
2830 AxisDataLocator dataLocator = getDataLocator(
2831 availableDataLocatorTypes[nextIndex], request.getDialect());
2832 nextIndex++;
2833 if (dataLocator != null) {
2834 data = dataLocator.getData(request, msgContext);
2835 if (data == null) {
2836 data = bubbleupDataLocators(nextIndex, request, msgContext);
2837 } else {
2838 return data;
2839 }
2840
2841 } else {
2842 data = bubbleupDataLocators(nextIndex, request, msgContext);
2843 }
2844
2845 }
2846 return data;
2847 }
2848
2849 /**
2850 * Save data Locator configured at service level for this Axis Service
2851 *
2852 * @param dialect-
2853 * an absolute URI represents the Dialect i.e. WSDL, Policy,
2854 * Schema or "ServiceLevel" for non-dialect service level data
2855 * locator.
2856 * @param dataLocatorClassName -
2857 * class name of the Data Locator configured to support data
2858 * retrieval for the specified dialect.
2859 */
2860 public void addDataLocatorClassNames(String dialect,
2861 String dataLocatorClassName) {
2862 dataLocatorClassNames.put(dialect, dataLocatorClassName);
2863 }
2864
2865 /*
2866 * Get data locator instance based on the LocatorType and dialect.
2867 */
2868 public AxisDataLocator getDataLocator(LocatorType locatorType,
2869 String dialect) throws AxisFault {
2870 AxisDataLocator locator;
2871 if (locatorType == LocatorType.SERVICE_DIALECT) {
2872 locator = getServiceDataLocator(dialect);
2873 } else if (locatorType == LocatorType.SERVICE_LEVEL) {
2874 locator = getServiceDataLocator(DRConstants.SERVICE_LEVEL);
2875 } else if (locatorType == LocatorType.GLOBAL_DIALECT) {
2876 locator = getGlobalDataLocator(dialect);
2877 } else if (locatorType == LocatorType.GLOBAL_LEVEL) {
2878 locator = getGlobalDataLocator(DRConstants.GLOBAL_LEVEL);
2879 } else if (locatorType == LocatorType.DEFAULT_AXIS) {
2880 locator = getDefaultDataLocator();
2881 } else {
2882 locator = getDefaultDataLocator();
2883 }
2884
2885 return locator;
2886 }
2887
2888 // Return default Axis2 Data Locator
2889 private AxisDataLocator getDefaultDataLocator()
2890 throws DataRetrievalException {
2891
2892 if (defaultDataLocator == null) {
2893 defaultDataLocator = new AxisDataLocatorImpl(this);
2894 }
2895
2896 defaultDataLocator.loadServiceData();
2897
2898 return defaultDataLocator;
2899 }
2900
2901 /*
2902 * Checks if service level data locator configured for specified dialect.
2903 * Returns an instance of the data locator if exists, and null otherwise.
2904 */
2905 private AxisDataLocator getServiceDataLocator(String dialect)
2906 throws AxisFault {
2907 AxisDataLocator locator;
2908 locator = (AxisDataLocator) dataLocators.get(dialect);
2909 if (locator == null) {
2910 String className = (String) dataLocatorClassNames.get(dialect);
2911 if (className != null) {
2912 locator = loadDataLocator(className);
2913 dataLocators.put(dialect, locator);
2914 }
2915
2916 }
2917
2918 return locator;
2919
2920 }
2921
2922 /*
2923 * Checks if global level data locator configured for specified dialect.
2924 * @param dialect- an absolute URI represents the Dialect i.e. WSDL, Policy,
2925 * Schema or "GlobalLevel" for non-dialect Global level data locator.
2926 * Returns an instance of the data locator if exists, and null otherwise.
2927 */
2928
2929 public AxisDataLocator getGlobalDataLocator(String dialect)
2930 throws AxisFault {
2931 AxisConfiguration axisConfig = getAxisConfiguration();
2932 AxisDataLocator locator = null;
2933 if (axisConfig != null) {
2934 locator = axisConfig.getDataLocator(dialect);
2935 if (locator == null) {
2936 String className = axisConfig.getDataLocatorClassName(dialect);
2937 if (className != null) {
2938 locator = loadDataLocator(className);
2939 axisConfig.addDataLocator(dialect, locator);
2940 }
2941 }
2942 }
2943
2944 return locator;
2945
2946 }
2947
2948 protected AxisDataLocator loadDataLocator(String className)
2949 throws AxisFault {
2950
2951 AxisDataLocator locator;
2952
2953 try {
2954 Class dataLocator;
2955 dataLocator = Class.forName(className, true, serviceClassLoader);
2956 locator = (AxisDataLocator) dataLocator.newInstance();
2957 } catch (ClassNotFoundException e) {
2958 throw AxisFault.makeFault(e);
2959 } catch (IllegalAccessException e) {
2960 throw AxisFault.makeFault(e);
2961 } catch (InstantiationException e) {
2962 throw AxisFault.makeFault(e);
2963
2964 }
2965
2966 return locator;
2967 }
2968
2969 /**
2970 * Set the map of WSDL message element QNames to AxisOperations for this
2971 * service. This map is used during SOAP Body-based routing for
2972 * document/literal bare services to match the first child element of the
2973 * SOAP Body element to an operation. (Routing for RPC and document/literal
2974 * wrapped services occurs via the operationsAliasesMap.) <p/> From section
2975 * 4.7.6 of the WS-I BP 1.1: the "operation signature" is "the fully
2976 * qualified name of the child element of SOAP body of the SOAP input
2977 * message described by an operation in a WSDL binding," and thus this map
2978 * must be from a QName to an operation.
2979 *
2980 * @param messageElementQNameToOperationMap
2981 * The map from WSDL message element QNames to AxisOperations.
2982 */
2983 public void setMessageElementQNameToOperationMap(
2984 Map messageElementQNameToOperationMap) {
2985 this.messageElementQNameToOperationMap = messageElementQNameToOperationMap;
2986 }
2987
2988 /**
2989 * Look up an AxisOperation for this service based off of an element QName
2990 * from a WSDL message element.
2991 *
2992 * @param messageElementQName
2993 * The QName to search for.
2994 * @return The AxisOperation registered to the QName or null if no match was
2995 * found.
2996 * @see #setMessageElementQNameToOperationMap(Map)
2997 */
2998 public AxisOperation getOperationByMessageElementQName(
2999 QName messageElementQName) {
3000 return (AxisOperation) messageElementQNameToOperationMap
3001 .get(messageElementQName);
3002 }
3003
3004 /**
3005 * Add an entry to the map between element QNames in WSDL messages and
3006 * AxisOperations for this service.
3007 *
3008 * @param messageElementQName
3009 * The QName of the element on the input message that maps to the
3010 * given operation.
3011 * @param operation
3012 * The AxisOperation to be mapped to.
3013 * @see #setMessageElementQNameToOperationMap(Map)
3014 */
3015 public void addMessageElementQNameToOperationMapping(
3016 QName messageElementQName, AxisOperation operation) {
3017 // when setting an operation we have to set it only if the
3018 // messegeElementQName does not
3019 // exists in the map.
3020 // does exists means there are two or more operations which has the same
3021 // input element (in doc/literal
3022 // this is possible. In this case better to set it as null without
3023 // giving
3024 // a random operation.
3025 if (messageElementQNameToOperationMap.containsKey(messageElementQName)
3026 && messageElementQNameToOperationMap.get(messageElementQName) != operation) {
3027 messageElementQNameToOperationMap.put(messageElementQName, null);
3028 } else {
3029 messageElementQNameToOperationMap.put(messageElementQName,
3030 operation);
3031 }
3032
3033 }
3034
3035 // @deprecated - use getEndpointURL in axisEndpoint
3036 public String getEndpointURL() {
3037 return endpointURL;
3038 }
3039
3040 // @deprecated - use setEndpointURL in axisEndpoint
3041 public void setEndpointURL(String endpointURL) {
3042 this.endpointURL = endpointURL;
3043 }
3044
3045 // TODO : Explain what goes in this map!
3046 public Map<String, AxisEndpoint> getEndpoints() {
3047 return endpointMap;
3048 }
3049
3050 public boolean isCustomWsdl() {
3051 return customWsdl;
3052 }
3053
3054 public void setCustomWsdl(boolean customWsdl) {
3055 this.customWsdl = customWsdl;
3056 }
3057
3058 public List getOperationsNameList() {
3059 return operationsNameList;
3060 }
3061
3062 public void setOperationsNameList(List operationsNameList) {
3063 this.operationsNameList = operationsNameList;
3064 }
3065
3066 public AxisServiceGroup getAxisServiceGroup() {
3067 return (AxisServiceGroup) parent;
3068 }
3069
3070 public void setParent(AxisServiceGroup parent) {
3071 this.parent = parent;
3072 }
3073
3074 public String toString() {
3075 return getName();
3076 }
3077
3078 public ExcludeInfo getExcludeInfo() {
3079 return excludeInfo;
3080 }
3081
3082 public void setExcludeInfo(ExcludeInfo excludeInfo) {
3083 this.excludeInfo = excludeInfo;
3084 }
3085
3086 public void registerPolicy(String key, Policy policy) {
3087 policyMap.put(key, policy);
3088 }
3089
3090 public Policy lookupPolicy(String key) {
3091 return (Policy) policyMap.get(key);
3092 }
3093
3094 /**
3095 * Add a ServiceContextListener
3096 * @param scl
3097 */
3098 public void addMessageContextListener(MessageContextListener scl) {
3099 messageContextListeners.add(scl);
3100 }
3101
3102 /**
3103 * Remove a ServiceContextListener
3104 * @param scl
3105 */
3106 public void removeMessageContextListener(MessageContextListener scl) {
3107 messageContextListeners.remove(scl);
3108 }
3109
3110 /**
3111 * @param cls Class of ServiceContextListener
3112 * @return true if ServiceContextLister is in the list
3113 */
3114 public boolean hasMessageContextListener(Class cls) {
3115 for (int i=0; i<messageContextListeners.size(); i++) {
3116 if (messageContextListeners.get(i).getClass() == cls) {
3117 return true;
3118 }
3119 }
3120 return false;
3121 }
3122
3123 /**
3124 * Signal an Attach ServiceContext Event
3125 * @param sc ServiceContext
3126 * @param mc MessageContext
3127 */
3128 public void attachServiceContextEvent(ServiceContext sc, MessageContext mc) {
3129 for (int i=0; i<messageContextListeners.size(); i++) {
3130 messageContextListeners.get(i).attachServiceContextEvent(sc, mc);
3131 }
3132 }
3133
3134 /**
3135 * Signal an Attach Envelope Event
3136 * @param mc MessageContext
3137 */
3138 public void attachEnvelopeEvent(MessageContext mc) {
3139 for (int i=0; i<messageContextListeners.size(); i++) {
3140 messageContextListeners.get(i).attachEnvelopeEvent(mc);
3141 }
3142 }
3143 }