KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > soap > apacheaxis > WSIFOperation_ApacheAxis


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.providers.soap.apacheaxis;
59
60 import java.rmi.RemoteException JavaDoc;
61 import java.util.ArrayList JavaDoc;
62 import java.util.Arrays JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Iterator JavaDoc;
65 import java.util.List JavaDoc;
66 import java.util.Map JavaDoc;
67 import java.util.Vector JavaDoc;
68
69 import javax.jms.TextMessage JavaDoc;
70 import javax.wsdl.Binding;
71 import javax.wsdl.BindingFault;
72 import javax.wsdl.BindingInput;
73 import javax.wsdl.BindingOperation;
74 import javax.wsdl.BindingOutput;
75 import javax.wsdl.Definition;
76 import javax.wsdl.Input;
77 import javax.wsdl.Operation;
78 import javax.wsdl.Output;
79 import javax.wsdl.Part;
80 import javax.wsdl.extensions.mime.MIMEContent;
81 import javax.wsdl.extensions.mime.MIMEMimeXml;
82 import javax.wsdl.extensions.mime.MIMEMultipartRelated;
83 import javax.wsdl.extensions.mime.MIMEPart;
84 import javax.wsdl.extensions.soap.SOAPBody;
85 import javax.wsdl.extensions.soap.SOAPFault;
86 import javax.wsdl.extensions.soap.SOAPHeader;
87 import javax.wsdl.extensions.soap.SOAPHeaderFault;
88 import javax.wsdl.extensions.soap.SOAPOperation;
89 import javax.xml.namespace.QName JavaDoc;
90 import javax.xml.rpc.ParameterMode JavaDoc;
91 import javax.xml.soap.SOAPException JavaDoc;
92
93 import org.apache.axis.AxisEngine;
94 import org.apache.axis.AxisFault;
95 import org.apache.axis.Message;
96 import org.apache.axis.MessageContext;
97 import org.apache.axis.attachments.AttachmentPart;
98 import org.apache.axis.client.Call;
99 import org.apache.axis.client.Service;
100 import org.apache.axis.client.Transport;
101 import org.apache.axis.encoding.DeserializerFactory;
102 import org.apache.axis.encoding.SerializerFactory;
103 import org.apache.axis.encoding.SimpleType;
104 import org.apache.axis.encoding.TypeMapping;
105 import org.apache.axis.encoding.TypeMappingRegistry;
106 import org.apache.axis.encoding.ser.ArrayDeserializerFactory;
107 import org.apache.axis.encoding.ser.ArraySerializerFactory;
108 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
109 import org.apache.axis.encoding.ser.BeanSerializerFactory;
110 import org.apache.axis.encoding.ser.SimpleDeserializerFactory;
111 import org.apache.axis.encoding.ser.SimpleSerializerFactory;
112 import org.apache.axis.message.RPCElement;
113 import org.apache.axis.message.RPCParam;
114 import org.apache.axis.message.SOAPBodyElement;
115 import org.apache.axis.message.SOAPEnvelope;
116 import org.apache.axis.message.SOAPFaultElement;
117 import org.apache.axis.message.SOAPHeaderElement;
118 import org.apache.wsif.WSIFConstants;
119 import org.apache.wsif.WSIFCorrelationId;
120 import org.apache.wsif.WSIFException;
121 import org.apache.wsif.WSIFMessage;
122 import org.apache.wsif.WSIFPort;
123 import org.apache.wsif.WSIFResponseHandler;
124 import org.apache.wsif.base.WSIFDefaultOperation;
125 import org.apache.wsif.logging.Trc;
126 import org.apache.wsif.providers.WSIFDynamicTypeMap;
127 import org.apache.wsif.providers.WSIFDynamicTypeMapping;
128 import org.apache.wsif.util.TypeSerializerInfo;
129 import org.apache.wsif.util.WSIFUtils;
130 import org.apache.wsif.util.jms.WSIFJMSDestination;
131 import org.apache.wsif.wsdl.extensions.jms.JMSProperty;
132 import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue;
133 import org.w3c.dom.Element JavaDoc;
134 import org.w3c.dom.Node JavaDoc;
135 import org.w3c.dom.NodeList JavaDoc;
136 import org.xml.sax.SAXException JavaDoc;
137
138 import com.ibm.wsdl.extensions.mime.MIMEConstants;
139
140 /**
141  * The WSIFOperation class for invoking WSDL operations using Apache AXIS.
142  *
143  * @author Mark Whitlock <whitlock@apache.org>
144  * @author Ant Elder <ant.elder@uk.ibm.com>
145  */

146 public class WSIFOperation_ApacheAxis extends WSIFDefaultOperation {
147
148     private static final long serialVersionUID = 2L;
149
150     transient protected WSIFPort_ApacheAxis wsifPort;
151     
152     transient protected Operation portTypeOperation;
153     transient protected BindingOperation bindingOperation;
154     transient protected SOAPOperation soapOperation;
155     
156     transient protected List JavaDoc inputSOAPParts;
157     transient protected List JavaDoc inputUnwrappedSOAPParts;
158     transient protected List JavaDoc inputMIMEParts;
159     transient protected Part inputSOAPHeader;
160     transient protected Part inputSOAPHeaderFault;
161
162     protected List JavaDoc outputSOAPParts;
163     protected List JavaDoc outputUnwrappedSOAPParts;
164     protected List JavaDoc outputMIMEParts;
165     protected Part outputSOAPHeader;
166     protected Part outputSOAPHeaderFault;
167
168     transient protected String JavaDoc inputEncodingStyle;
169     transient protected String JavaDoc inputNamespace;
170     transient protected String JavaDoc soapActionURI;
171
172     transient protected HashMap JavaDoc responseMessageParameters;
173
174     // for async operation
175
transient protected boolean asyncOperation;
176     transient protected WSIFCorrelationId asyncRequestID;
177
178     // everything other than what is needed to process async response should be transient
179
protected WSIFResponseHandler responseHandler;
180     protected String JavaDoc outputEncodingStyle;
181     protected WSIFDynamicTypeMap typeMap;
182     protected String JavaDoc operationStyle;
183     
184     /**
185      * Construct a new WSIFOperation
186      */

187     public WSIFOperation_ApacheAxis(
188         WSIFPort_ApacheAxis wsifPort,
189         Operation portTypeOperation,
190         WSIFDynamicTypeMap typeMap)
191         throws WSIFException {
192         Trc.entry(this, wsifPort, portTypeOperation, typeMap);
193
194         /* Note: if you change anything here make sure you consider
195          * the impact to the constructor, copy and prepare methods
196          * and to if any instance variables are transient
197          */

198
199         this.wsifPort = wsifPort;
200         this.portTypeOperation = portTypeOperation;
201         this.typeMap = typeMap;
202
203         this.bindingOperation = getBindingOperation(portTypeOperation);
204
205         this.inputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI;
206         this.outputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI;
207
208         if (Trc.ON) {
209             Trc.exit(deep());
210         }
211     }
212
213     /**
214      * Create a new copy of this object. This is not a clone, since
215      * it does not copy the referenced objects as well.
216      * The intention here is to copy anything that the prepare method
217      * has done so that WSIFOperation instances can be cached by the
218      * WSIFPort and safely reused with minimum overhead.
219      * @deprecated why was this ever made public??? It should only
220      * ever be used by the WSIFPort!!!
221      */

222     public WSIFOperation_ApacheAxis copy() throws WSIFException {
223         Trc.entry(this);
224
225         /* Note: if you change anything here make sure you consider
226          * the impact to the constructor, copy and prepare methods
227          * and to if any instance variables are transient
228          */

229
230         WSIFOperation_ApacheAxis op =
231             new WSIFOperation_ApacheAxis(wsifPort, portTypeOperation, typeMap);
232
233         op.inputSOAPParts = inputSOAPParts;
234         op.inputUnwrappedSOAPParts = inputUnwrappedSOAPParts;
235         op.inputMIMEParts = inputMIMEParts;
236         op.inputSOAPHeader = inputSOAPHeader;
237         op.inputSOAPHeaderFault = inputSOAPHeaderFault;
238
239         op.outputSOAPParts = outputSOAPParts;
240         op.outputUnwrappedSOAPParts = outputUnwrappedSOAPParts;
241         op.outputMIMEParts = outputMIMEParts;
242         op.outputSOAPHeader = outputSOAPHeader;
243         op.outputSOAPHeaderFault = outputSOAPHeaderFault;
244
245         op.soapOperation = soapOperation;
246
247         op.setSoapActionURI(getSoapActionURI());
248         op.setInputNamespace(getInputNamespace());
249         op.setInputEncodingStyle(getInputEncodingStyle());
250         op.setOutputEncodingStyle(getOutputEncodingStyle());
251         op.setAsyncOperation(isAsyncOperation());
252         op.setResponseHandler(getResponseHandler());
253         op.setInputJmsProperties(getInputJmsProperties());
254         op.setOutputJmsProperties(getOutputJmsProperties());
255         op.setInputJmsPropertyValues(getInputJmsPropertyValues());
256         op.setOperationStyle(getOperationStyle());
257
258         if (Trc.ON)
259             Trc.exit(op.deep());
260         return op;
261     }
262
263     /**
264      * Initialises instance variables relating to the WSDL soap:operation element
265      * The soap:operation WSDL element has the form:
266      * <soap:operation soapAction="uri"? style="rpc|document"?>?
267      */

268     private void parseSoapOperation() throws WSIFException {
269
270         this.soapOperation = wsifPort.getSOAPOperation(bindingOperation);
271         this.soapActionURI = soapOperation.getSoapActionURI();
272         this.operationStyle = soapOperation.getStyle();
273
274         if (operationStyle == null || operationStyle.length() < 1) {
275             operationStyle = wsifPort.getBindingStyle();
276         } else if (!WSIFAXISConstants.VALID_STYLES.contains(operationStyle)) {
277             throw new WSIFException(
278                 "unsupported style "
279                     + operationStyle
280                     + " for operation "
281                     + portTypeOperation.getName());
282         }
283         if (operationStyle == null || operationStyle.length() < 1) {
284             operationStyle = WSIFAXISConstants.STYLE_DOCUMENT;
285         }
286     }
287
288     /**
289      * Initialises instance variables relating to the WSDL binding:input element
290      * The WSDL binding input has the form:
291      * <input>
292      * <soap:body parts="nmtokens"? use="literal|encoded"
293      * encodingStyle="uri-list"? namespace="uri"?>
294      * <soap:header message="qname" part="nmtoken" use="literal|encoded"
295      * encodingStyle="uri-list"? namespace="uri"?>*
296      * <soap:headerfault message="qname"
297      * part="nmtoken" use="literal|encoded"
298      * encodingStyle="uri-list"? namespace="uri"?/>*
299      * <soap:header>
300      * </input>
301      */

302     private void parseBindingInput() throws WSIFException {
303         BindingInput bindinginput = bindingOperation.getBindingInput();
304         List JavaDoc inExtElems = bindinginput.getExtensibilityElements();
305         
306         SOAPBody inSoapBody =
307             (SOAPBody) wsifPort.getExtElem(
308                 bindinginput,
309                 javax.wsdl.extensions.soap.SOAPBody.class,
310                 inExtElems);
311         if (inSoapBody != null) {
312             this.inputSOAPParts = parseSoapBody(inSoapBody, true);
313         }
314
315         MIMEMultipartRelated inMimeMultipart =
316             (MIMEMultipartRelated) wsifPort.getExtElem(
317                 bindinginput,
318                 MIMEMultipartRelated.class,
319                 inExtElems);
320
321         if (inSoapBody != null && inMimeMultipart != null) {
322             throw new WSIFException(
323                 "In a binding operation that contains a mime:multipartRelated, "
324                     + "a soap:body was found that was not in a mime:part. "
325                     + "OperationName="
326                     + getName());
327         }
328         if (inSoapBody == null && inMimeMultipart == null) {
329             throw new WSIFException(
330                 "binding operation input must contain either a soap:body " +
331                 "or a mime:multipartRelated element. "
332                     + "OperationName="
333                     + getName());
334         }
335
336         if (inMimeMultipart != null) {
337             parseMimeMultipart(inMimeMultipart, true);
338         }
339
340         MIMEMimeXml inMimeMimeXml =
341             (MIMEMimeXml) wsifPort.getExtElem(
342                 bindinginput,
343                 MIMEMimeXml.class,
344                 inExtElems);
345         if (inMimeMimeXml != null)
346             throw new WSIFException(
347                 "WSIF does not support mime:mimeXml. Operation="
348                     + getName());
349
350         parseSOAPHeaderElement(bindinginput);
351
352         List JavaDoc inJmsProps =
353             wsifPort.getExtElems(
354                 bindinginput,
355                 JMSProperty.class,
356                 bindinginput.getExtensibilityElements());
357         if (inJmsProps != null && inJmsProps.size() > 0) {
358             if (wsifPort.isTransportJMS())
359                 setInputJmsProperties(inJmsProps);
360             else
361                 throw new WSIFException("jms:property found in non-jms binding");
362         }
363
364         List JavaDoc inJmsPropVals =
365             wsifPort.getExtElems(
366                 bindinginput,
367                 JMSPropertyValue.class,
368                 bindinginput.getExtensibilityElements());
369         if (inJmsPropVals != null && inJmsPropVals.size() > 0) {
370             if (wsifPort.isTransportJMS())
371                 addInputJmsPropertyValues(inJmsPropVals);
372             else
373                 throw new WSIFException("jms:propertyValue found in non-jms binding");
374         }
375     }
376
377     /**
378      * Initialises instance variables relating to the WSDL binding:output element
379      * The WSDL binding output has the form:
380      * <output>
381      * <soap:body parts="nmtokens"? use="literal|encoded"
382      * encodingStyle="uri-list"? namespace="uri"?>
383      * <soap:header message="qname" part="nmtoken" use="literal|encoded"
384      * encodingStyle="uri-list"? namespace="uri"?>*
385      * <soap:headerfault message="qname"
386      * part="nmtoken" use="literal|encoded"
387      * encodingStyle="uri-list"? namespace="uri"?/>*
388      * <soap:header>
389      * </output>
390      */

391     private void parseBindingOutput() throws WSIFException {
392         BindingOutput bindingoutput = bindingOperation.getBindingOutput();
393         if (bindingoutput != null) {
394             List JavaDoc outExtElems = bindingoutput.getExtensibilityElements();
395             SOAPBody outSoapBody =
396                 (SOAPBody) wsifPort.getExtElem(
397                     bindingoutput,
398                     javax.wsdl.extensions.soap.SOAPBody.class,
399                     outExtElems);
400             if (outSoapBody != null) {
401                 this.outputSOAPParts = parseSoapBody(outSoapBody, false);
402             }
403
404             MIMEMultipartRelated outMimeMultipart =
405                 (MIMEMultipartRelated) wsifPort.getExtElem(
406                     bindingoutput,
407                     MIMEMultipartRelated.class,
408                     outExtElems);
409
410             if (outSoapBody != null && outMimeMultipart != null) {
411                 throw new WSIFException(
412                     "In a binding operation that contains a mime:multipartRelated, "
413                         + "a soap:body was found that was not in a mime:part. "
414                         + "OperationName="
415                         + getName());
416             }
417             if (outSoapBody == null && outMimeMultipart == null) {
418                 throw new WSIFException(
419                     "binding operation output must contain either a soap:body " +
420                     "or a mime:multipartRelated element. " +
421                     "OperationName=" +
422                     getName());
423             }
424
425             if (outMimeMultipart != null) {
426                 parseMimeMultipart(outMimeMultipart, false);
427             }
428
429             MIMEMimeXml outMimeMimeXml =
430                 (MIMEMimeXml) wsifPort.getExtElem(
431                     bindingoutput,
432                     MIMEMimeXml.class,
433                     outExtElems);
434             if (outMimeMimeXml != null) {
435                 throw new WSIFException(
436                     "WSIF does not support mime:mimeXml. Operation=" +
437                     getName());
438             }
439
440             parseSOAPHeaderElement(bindingoutput);
441
442             for (Iterator JavaDoc iterator1 =
443                 bindingOperation.getBindingFaults().values().iterator();
444                 iterator1.hasNext();
445                 ) {
446                 BindingFault bindingfault = (BindingFault) iterator1.next();
447                 SOAPFault soapfault =
448                     (SOAPFault) wsifPort.getExtElem(
449                         bindingfault,
450                         javax.wsdl.extensions.soap.SOAPFault.class,
451                         bindingfault.getExtensibilityElements());
452             }
453
454             List JavaDoc outJmsProps =
455                 wsifPort.getExtElems(
456                     bindingoutput,
457                     JMSProperty.class,
458                     outExtElems);
459             if (outJmsProps != null && outJmsProps.size() > 0) {
460                 if (wsifPort.isTransportJMS()) {
461                     setOutputJmsProperties(outJmsProps);
462                 } else {
463                     throw new WSIFException("jms:properties found in non-jms binding");
464                 }
465             }
466         }
467     }
468
469     /**
470      * Parses any SOAP header elements in the binding input or output.
471      * The WSDL soap:header element has the form:
472      * <soap:header message="qname" part="nmtoken" use="literal|encoded"
473      * encodingStyle="uri-list"? namespace="uri"?>*
474      * <soap:headerfault message="qname" part="nmtoken" use="literal|encoded"
475      * encodingStyle="uri-list"? namespace="uri"?/>*
476      * <soap:header>
477      */

478     private void parseSOAPHeaderElement(Object JavaDoc element) throws WSIFException {
479
480         List JavaDoc extensabilityElements;
481         if (element instanceof BindingInput) {
482             extensabilityElements =
483                 ((BindingInput) element).getExtensibilityElements();
484         } else if (element instanceof BindingOutput) {
485             extensabilityElements =
486                 ((BindingOutput) element).getExtensibilityElements();
487         } else {
488             throw new WSIFException(
489                 "internal error, unexpected object: " + element);
490         }
491
492         Part soapHeaderPart = null;
493         Part soapHeaderFaultPart = null;
494
495         SOAPHeader soapHeader =
496             (SOAPHeader) wsifPort.getExtElem(
497                 element,
498                 javax.wsdl.extensions.soap.SOAPHeader.class,
499                 extensabilityElements);
500         if (soapHeader != null) {
501             QName JavaDoc messageName = soapHeader.getMessage();
502             if (messageName == null) {
503                 throw new WSIFException(
504                     "no message attribute on soap:header: " + soapHeader);
505             }
506             String JavaDoc messagePart = soapHeader.getPart();
507             if (messagePart == null) {
508                 throw new WSIFException(
509                     "no part attribute on soap:header: " + soapHeader);
510             }
511             soapHeaderPart = getPart(messageName, messagePart);
512             if (soapHeaderPart == null) {
513                 throw new WSIFException(
514                     "non existent part specified on soap:header: "
515                         + soapHeader);
516             }
517
518             SOAPHeaderFault soapHeaderFault =
519                 (SOAPHeaderFault) wsifPort.getExtElem(
520                     soapHeader,
521                     javax.wsdl.extensions.soap.SOAPHeaderFault.class,
522                     extensabilityElements);
523             if (soapHeaderFault != null) {
524                 messageName = soapHeader.getMessage();
525                 if (messageName == null) {
526                     throw new WSIFException(
527                         "no message attribute on soap:header: " + soapHeader);
528                 }
529                 messagePart = soapHeader.getPart();
530                 if (messagePart == null) {
531                     throw new WSIFException(
532                         "no part attribute on soap:header: " + soapHeader);
533                 }
534                 soapHeaderFaultPart = getPart(messageName, messagePart);
535                 if (soapHeaderFaultPart == null) {
536                     throw new WSIFException(
537                         "non existent part specified on soap:header: "
538                             + soapHeader);
539                 }
540             }
541         }
542
543         if (element instanceof BindingInput) {
544             this.inputSOAPHeader = soapHeaderPart;
545             this.inputSOAPHeaderFault = soapHeaderFaultPart;
546         } else {
547             this.outputSOAPHeader = soapHeaderPart;
548             this.outputSOAPHeaderFault = soapHeaderFaultPart;
549         }
550         //TODO now go and do something with them...
551
}
552
553     /**
554      * Validates the soap:body WSDL element.
555      * The soap:body WSDL element has the form:
556      * <soap:body parts="nmtokens"? use="literal|encoded"
557      * encodingStyle="uri-list"? namespace="uri"?>
558      * Returns an ArrayList of the WSDL parts
559      */

560     private List JavaDoc parseSoapBody(SOAPBody soapbody, boolean isInput)
561         throws WSIFException {
562         Trc.entry(this, soapbody, new Boolean JavaDoc(isInput));
563
564         // get input namespace
565
if (isInput) {
566             String JavaDoc ns = soapbody.getNamespaceURI();
567             if (ns != null) {
568                 setInputNamespace(soapbody.getNamespaceURI());
569             }
570         }
571
572         // get use
573
String JavaDoc use = soapbody.getUse();
574         if (!WSIFAXISConstants.VALID_USES.contains(use)) {
575             throw new WSIFException(
576                 "unsupported use " + use + " in " + soapOperation);
577         }
578
579         // get encoding style
580
if (isInput) {
581             List JavaDoc l = soapbody.getEncodingStyles();
582             if (l != null && l.size() > 0) {
583                 setInputEncodingStyle((String JavaDoc) l.get(0));
584             }
585         }
586
587         // get all the WSDL parts. If the soap:body parts= is defined
588
// only get those parts, otherwise get all parts in the WSDL message
589
javax.wsdl.Message m = null;
590         if (isInput) {
591             Input in = portTypeOperation.getInput();
592             if (in != null) {
593                 m = in.getMessage();
594             }
595         } else {
596             Output out = portTypeOperation.getOutput();
597             if (out != null) {
598                 m = out.getMessage();
599             }
600         }
601         ArrayList JavaDoc al = getParts(m, soapbody.getParts());
602
603         Trc.exit(al);
604         return al;
605     }
606
607     /**
608      * Gets the parts from a WSDL message.
609      * If the partNames list (from WSDL soap:body parts=) is
610      * not null only the parts named in the partName list are
611      * returned, otherwise all parts are returned.
612      */

613     private ArrayList JavaDoc getParts(javax.wsdl.Message m, List JavaDoc partNames ) throws WSIFException{
614         ArrayList JavaDoc al = new ArrayList JavaDoc();
615         List JavaDoc parts = null;
616         if (m != null) {
617             parts = m.getOrderedParts(null);
618         }
619
620         if ((parts == null || parts.size() < 1)
621         && (partNames != null && partNames.size() > 0)) {
622             throw new WSIFException("part '" +
623                 partNames.get(0) +
624                 "' not defined in message " + m);
625         }
626         
627         if (partNames == null) {
628             if (parts != null) {
629                 al.addAll(parts);
630             }
631         } else {
632             for (Iterator JavaDoc i = partNames.iterator(); i.hasNext(); ) {
633                 String JavaDoc partName = (String JavaDoc) i.next();
634                 Part p = m.getPart(partName);
635                 if (p == null) {
636                     throw new WSIFException("Part '" +
637                         partName +
638                         "' in soap:body parts not in message " + m);
639                 }
640                 // as there can be multiple mime:content elements which
641
// specify a coice of types (TODO: which wsif ignores for now)
642
// we only want each mime part once
643
if (!al.contains(p)) {
644                     al.add(p);
645                 }
646             }
647         }
648         return al;
649     }
650
651     /**
652      * Parses the mime:multipartRelated WSDL element
653      * The mime:multipartRelated element has the form:
654      * <mime:multipartRelated>
655      * <mime:part> *
656      * <-- mime element -->
657      * </mime:part>
658      * </mime:multipartRelated>
659      */

660     private void parseMimeMultipart(
661         MIMEMultipartRelated mimeMultipart,
662         boolean isInput)
663         throws WSIFException {
664         Trc.entry(this, mimeMultipart);
665
666         ArrayList JavaDoc mimePartNames = new ArrayList JavaDoc();
667         SOAPBody soapBody = null;
668         
669         Operation op = bindingOperation.getOperation();
670         Map JavaDoc mapInParts = op.getInput().getMessage().getParts();
671         Map JavaDoc mapOutParts =
672             op.getOutput() == null
673                 ? new HashMap JavaDoc()
674                 : op.getOutput().getMessage().getParts();
675
676         List JavaDoc mimeParts = mimeMultipart.getMIMEParts();
677         Iterator JavaDoc mimePartIt = mimeParts.iterator();
678         while (mimePartIt.hasNext()) {
679             Object JavaDoc nextMimePart = mimePartIt.next();
680             if (nextMimePart instanceof MIMEPart) {
681                 MIMEPart mimePart = (MIMEPart) nextMimePart;
682                 if (!MIMEConstants
683                     .NS_URI_MIME
684                     .equals(mimePart.getElementType().getNamespaceURI()))
685                     throw new WSIFException(
686                         "A MIME part in binding operation "
687                             + bindingOperation.getName()
688                             + " did not have the correct namespace URI of "
689                             + MIMEConstants.NS_URI_MIME
690                             + ".");
691
692                 boolean containsSoapBody = false;
693                 boolean containsMimeContent = false;
694                 List JavaDoc mimePartChildren = mimePart.getExtensibilityElements();
695                 Iterator JavaDoc mimePartChildrenIt = mimePartChildren.iterator();
696                 while (mimePartChildrenIt.hasNext()) {
697                     Object JavaDoc nextChild = mimePartChildrenIt.next();
698                     if (nextChild instanceof MIMEContent) {
699                         MIMEContent mimeContent = (MIMEContent) nextChild;
700                         if (!MIMEConstants
701                             .NS_URI_MIME
702                             .equals(
703                                 mimePart.getElementType().getNamespaceURI()))
704                             throw new WSIFException(
705                                 "A MIME part in binding operation "
706                                     + bindingOperation.getName()
707                                     + " did not have the correct namespace URI of "
708                                     + MIMEConstants.NS_URI_MIME
709                                     + ".");
710                         containsMimeContent = true;
711                         if (containsSoapBody)
712                             throw new WSIFException(
713                                 "A mime:part that contains a mime:content also "
714                                     + "contains a soap:body. Operation="
715                                     + getName());
716
717                         String JavaDoc partName = mimeContent.getPart();
718                         if (partName == null || partName.length() == 0)
719                             throw new WSIFException(
720                                 "No part name for a mime:content. Operation="
721                                     + getName());
722
723                         if ((isInput && mapInParts.get(partName) == null)
724                             || (!isInput && mapOutParts.get(partName) == null))
725                             throw new WSIFException(
726                                 "The part specified in a mime:content does "
727                                     + "not exist in the operation. Operation="
728                                     + getName()
729                                     + " Part="
730                                     + partName);
731
732                         mimePartNames.add(partName);
733
734                     } else if (nextChild instanceof SOAPBody) {
735                         if (soapBody!=null) {
736                             throw new WSIFException(
737                                 "Multiple soap:body tags found in a "
738                                     + "mime:multipartRelated. Operation="
739                                     + getName());
740                         }
741                         soapBody = (SOAPBody)nextChild;
742
743                         containsSoapBody = true;
744                         if (containsMimeContent)
745                             throw new WSIFException(
746                                 "A mime:part that contains a mime:content also "
747                                     + "contains a soap:body. Operation="
748                                     + getName());
749
750                     } else if (nextChild instanceof MIMEMultipartRelated) {
751                         throw new WSIFException(
752                             "WSIF does not support nesting mime:multipartRelated "
753                                 + "inside a mime:part. Operation="
754                                 + getName());
755                     } else if (nextChild instanceof MIMEMimeXml) {
756                         throw new WSIFException(
757                             "WSIF does not support mime:mimeXml. Operation="
758                                 + getName());
759                     }
760                 }
761             }
762         }
763
764         // There is at most one soap:body so process it here.
765
if (soapBody != null)
766         {
767             List JavaDoc soapBodyParts = soapBody.getParts();
768             if (soapBodyParts == null && !mimePartNames.isEmpty())
769             {
770                 /* In the WSDL (containing attachments and non-attachment
771                  * parts), if there is a soap:body that does not have
772                  * the parts attribute, which parts should the soap body
773                  * contain? The WSDL spec is not clear so this code
774                  * fixes the soap body to contain only the non-attachment
775                  * parts, which is the kinder option. The alternative which
776                  * is making the soap body contain all the parts (so duplicating
777                  * the attachments) is cruel since this is probably not
778                  * what the backend is expecting.
779                  */

780                 Map JavaDoc soapParts;
781                 if (isInput)
782                     soapParts = mapInParts;
783                 else
784                     soapParts = mapOutParts;
785
786                 if (soapParts != null && !soapParts.isEmpty())
787                 {
788                     ArrayList JavaDoc nonMimeParts =
789                         new ArrayList JavaDoc(
790                             Arrays.asList(soapParts.keySet().toArray()));
791                     nonMimeParts.removeAll(
792                         Arrays.asList(soapParts.keySet().toArray()));
793                     soapBody.setParts(nonMimeParts);
794                 }
795             }
796
797             List JavaDoc soapParts = parseSoapBody(soapBody, isInput);
798             if (isInput)
799                 this.inputSOAPParts = soapParts;
800             else
801                 this.outputSOAPParts = soapParts;
802         }
803
804         if (mimePartNames != null && !mimePartNames.isEmpty()) {
805             javax.wsdl.Message m = null;
806             if (isInput) {
807                 Input in = portTypeOperation.getInput();
808                 if (in != null) {
809                     m = in.getMessage();
810                 }
811             } else {
812                 Output out = portTypeOperation.getOutput();
813                 if (out != null) {
814                     m = out.getMessage();
815                 }
816             }
817             ArrayList JavaDoc al = getParts(m, mimePartNames);
818             if (isInput) {
819                 this.inputMIMEParts = al;
820             } else {
821                 this.outputMIMEParts = al;
822             }
823             
824         }
825
826         Trc.exit();
827     }
828
829     /**
830      * For document style operations the input and/or output
831      * may be 'wrapped'. A wrapped operation has a single top-
832      * level element wrapping the argument elements. For an input
833      * message the top level wrapper element name must be the same
834      * as the operation name, the output wrapper element name must
835      * be the name of the operation suffixed with "Response".
836      * WSIF clients may use either the wrapped or unwrapped parts.
837      */

838     private void unwrapSOAPParts() throws WSIFException {
839         if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)) {
840             String JavaDoc operationName = getName();
841             if (inputSOAPParts.size() == 1) {
842                 Part p = (Part)inputSOAPParts.get(0);
843                 QName JavaDoc elementName = p.getElementName();
844                 if (elementName != null && operationName.equals(elementName.getLocalPart())) {
845                    this.inputUnwrappedSOAPParts =
846                       WSIFUtils.unWrapPart(p, getDefinition());
847                 }
848             }
849             if (outputSOAPParts.size() == 1) {
850                 String JavaDoc s = operationName + "Response";
851                 Part p = (Part)outputSOAPParts.get(0);
852                 QName JavaDoc elementName = p.getElementName();
853                 if (elementName != null && s.equals(elementName.getLocalPart())) {
854                    this.outputUnwrappedSOAPParts =
855                       WSIFUtils.unWrapPart(p, getDefinition());
856                 }
857             }
858         }
859     }
860
861     /**
862      * Gets the WSDL binding:operation element for this operation
863      */

864     private BindingOperation getBindingOperation(Operation operation)
865         throws WSIFException {
866         Binding binding = wsifPort.getPort().getBinding();
867         BindingOperation bindingOp =
868             WSIFUtils.getBindingOperation(binding, operation);
869         if (bindingOp == null) {
870             throw new WSIFException(
871                 "cannot find binding operation for port operation:"
872                     + operation.getName());
873         }
874         return bindingOp;
875     }
876
877     /**
878      * Returns the Definition object for the WSDL file
879      * @return Definition the WSDL4J Definition object
880      */

881     public Definition getDefinition() {
882         Trc.entry(this);
883         Definition d = wsifPort.getDefinition();
884         Trc.exit(d);
885         return d;
886     }
887
888     /**
889      * @deprecated use getWSIFPort
890      */

891     public WSIFPort_ApacheAxis getDynamicWSIFPort() {
892         Trc.entry(this);
893         Trc.exit(wsifPort);
894         return wsifPort;
895     }
896
897     public String JavaDoc getInputEncodingStyle() {
898         Trc.entry(this);
899         Trc.exit(inputEncodingStyle);
900         return inputEncodingStyle;
901     }
902
903     public String JavaDoc getInputNamespace() {
904         Trc.entry(this);
905         Trc.exit(inputNamespace);
906         return inputNamespace;
907     }
908
909     /**
910      * Gets the name of the portType wsdl:operation element
911      * being used by this WSIFOperation
912      * @return String the operation name
913      */

914     public String JavaDoc getName() {
915         Trc.entry(this);
916         String JavaDoc s = portTypeOperation.getName();
917         Trc.exit(s);
918         return s;
919     }
920
921     /**
922      * @deprecated use getPortTypeOperation
923      */

924     public Operation getOperation() {
925         Trc.entry(this);
926         Operation o = getPortTypeOperation();
927         Trc.exit(o);
928         return o;
929     }
930
931     /**
932      * Returns the WSDL Part for the named part in a WSDL Message
933      */

934     private Part getPart(QName JavaDoc message, String JavaDoc partName) {
935         Part p = null;
936         Definition def = wsifPort.getDefinition();
937         javax.wsdl.Message m = def.getMessage(message);
938         if (m != null) {
939             p = m.getPart(partName);
940         }
941         return p;
942     }
943
944     /**
945      * Gets the portType wsdl:operation element used by this WSIFOperation
946      * @return Operation the WSDL4J portType Operation object
947      */

948     public Operation getPortTypeOperation() {
949         Trc.entry(this);
950         Trc.exit(portTypeOperation);
951         return portTypeOperation;
952     }
953
954     public String JavaDoc getOutputEncodingStyle() {
955         Trc.entry(this);
956         Trc.exit(outputEncodingStyle);
957         return outputEncodingStyle;
958     }
959
960     public String JavaDoc getSoapActionURI() {
961         Trc.entry(this);
962         Trc.exit(soapActionURI);
963         return soapActionURI;
964     }
965
966     public Transport getTransport() throws WSIFException {
967         Trc.entry(this);
968         Transport t = wsifPort.getTransport();
969         Trc.exit(t);
970         return t;
971     }
972
973     public WSIFCorrelationId getAsyncRequestID() {
974         Trc.entry(this);
975         Trc.exit(asyncRequestID);
976         return asyncRequestID;
977     }
978
979     private HashMap JavaDoc getResponseMessageParameters() {
980         return responseMessageParameters;
981     }
982
983     public WSIFPort getWSIFPort() {
984         Trc.entry(this);
985         Trc.exit(wsifPort);
986         return wsifPort;
987     }
988     
989     /**
990      * Tests if the currently executing request is an asynchronous request.
991      *
992      * @return true if the current request is a asynchronous request,
993      * otherwise false
994      */

995     public boolean isAsyncOperation() {
996         Trc.entry(this);
997         Trc.exit(asyncOperation);
998         return asyncOperation;
999     }
1000
1001    public void executeInputOnlyOperation(WSIFMessage inMsg)
1002        throws WSIFException {
1003        Trc.entry(this, inMsg);
1004
1005        if (inMsg == null) {
1006            throw new IllegalArgumentException JavaDoc("input message is null");
1007        }
1008
1009        setAsyncOperation(false);
1010        invokeRequestResponseOperation(inMsg, null, null);
1011        Trc.exit();
1012        return;
1013    }
1014
1015    public boolean executeRequestResponseOperation(
1016        WSIFMessage inMsg,
1017        WSIFMessage outMsg,
1018        WSIFMessage faultMsg)
1019        throws WSIFException {
1020
1021        Trc.entry(this, inMsg, outMsg, faultMsg);
1022
1023        if (inMsg == null) {
1024            throw new IllegalArgumentException JavaDoc("input message is null");
1025        }
1026        if (outMsg == null) {
1027            throw new IllegalArgumentException JavaDoc("output message is null");
1028        }
1029        if (faultMsg == null) {
1030            throw new IllegalArgumentException JavaDoc("fault message is null");
1031        }
1032
1033        close();
1034        setAsyncOperation(false);
1035
1036        boolean succ =
1037                invokeRequestResponseOperation(inMsg, outMsg, faultMsg);
1038
1039        Trc.exit(succ);
1040        return succ;
1041    }
1042
1043    /**
1044     * Performs a request response operation asynchronously.
1045     *
1046     * @param input input message to send to the operation
1047     * @return the correlation ID or the request. The correlation ID
1048     * is used to associate the request with the WSIFOperation.
1049     * @exception WSIFException if something goes wrong.
1050     * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
1051     */

1052    public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage inMsg)
1053        throws WSIFException {
1054        Trc.entry(this, inMsg);
1055
1056        if (inMsg == null) {
1057            throw new IllegalArgumentException JavaDoc("input message is null");
1058        }
1059
1060        WSIFCorrelationId id = executeRequestResponseAsync(inMsg, null);
1061        Trc.exit(id);
1062        return id;
1063
1064    }
1065
1066    /**
1067     * Performs a request response operation asynchronously.
1068     *
1069     * @param input input message to send to the operation
1070     * @param handler the response handler that will be notified
1071     * when the asynchronous response becomes available.
1072     * @return the correlation ID or the request. The correlation ID
1073     * is used to associate the request with the WSIFOperation.
1074     * @exception WSIFException if something goes wrong.
1075     * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage,WSIFResponseHandler)
1076     */

1077    public WSIFCorrelationId executeRequestResponseAsync(
1078        WSIFMessage inMsg,
1079        WSIFResponseHandler handler)
1080        throws WSIFException {
1081        Trc.entry(this, inMsg, handler);
1082
1083        if (inMsg == null) {
1084            throw new IllegalArgumentException JavaDoc("input message is null");
1085        }
1086        close();
1087        
1088        if (!wsifPort.supportsAsync()) {
1089            throw new WSIFException("asynchronous operations not available");
1090        }
1091
1092        setAsyncOperation(true);
1093        setResponseHandler(handler);
1094        WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
1095        transport.setWsifOperation(this);
1096        transport.setAsyncOperation("true");
1097
1098        invokeRequestResponseOperation(inMsg, null, null);
1099
1100        transport.setAsyncOperation("false");
1101        WSIFCorrelationId id = getAsyncRequestID();
1102        Trc.exit(id);
1103        return id;
1104
1105    }
1106
1107    /**
1108     * fireAsyncResponse is called by an AsyncListener when a response
1109     * has been received for a previous executeRequestResponseAsync call.
1110     * It passes the response to the executeAsyncResponse method of the
1111     * associated WSIFResponseHandler.
1112     * @see WSIFOperation#fireAsyncResponse(Object)
1113     * @param response an Object representing the response. The response
1114     * should be a JMS TextMessage containging the XML response.
1115     */

1116    public void fireAsyncResponse(Object JavaDoc response) throws WSIFException {
1117        Trc.entry(this, response);
1118
1119        Object JavaDoc result = deserialiseResponseObject(response);
1120
1121        WSIFMessage outMsg = createOutputMessage();
1122        WSIFMessage faultMsg = createFaultMessage();
1123        buildResponseMessages(result, outMsg, faultMsg);
1124
1125        getResponseHandler().executeAsyncResponse(outMsg, faultMsg);
1126
1127        Trc.exit(outMsg);
1128    }
1129
1130    /**
1131     * Processes the response to an asynchronous request.
1132     * This is called for when the asynchronous operation was
1133     * initiated without a WSIFResponseHandler, that is, by calling
1134     * the executeRequestResponseAsync(WSIFMessage input) method.
1135     *
1136     * @param response an Object representing the response.
1137     * @param output an empty message which will be filled in if
1138     * the operation invocation succeeds. If it does not
1139     * succeed, the contents of this message are undefined.
1140     * (This is a return value of this method.)
1141     * @param fault an empty message which will be filled in if
1142     * the operation invocation fails. If it succeeds, the
1143     * contents of this message are undefined. (This is a
1144     * return value of this method.)
1145     *
1146     * @return true or false indicating whether a fault message was
1147     * generated or not. The truth value indicates whether
1148     * the output or fault message has useful information.
1149     *
1150     */

1151    public boolean processAsyncResponse(
1152        Object JavaDoc response,
1153        WSIFMessage output,
1154        WSIFMessage fault)
1155        throws WSIFException {
1156        Trc.entry(this, response, output, fault);
1157
1158        Object JavaDoc result = deserialiseResponseObject(response);
1159        boolean ok = buildResponseMessages(result, output, fault);
1160
1161        Trc.exit(ok);
1162        return ok;
1163    }
1164
1165    /**
1166     * Deserialise and unmarshall the JMS response message.
1167     * Used to process the response to an asynchronous request.
1168     * This is copied, with minor changes, from the 2nd half
1169     * of the Apache Axis Call class invoke method.
1170     */

1171    private Object JavaDoc deserialiseResponseObject(Object JavaDoc msg) throws WSIFException {
1172        if (msg == null) {
1173            throw new WSIFException("null response to async send");
1174        }
1175        if (!(msg instanceof TextMessage JavaDoc)) {
1176            throw new WSIFException("response not a javax.jms.TextMessage");
1177        }
1178
1179        try {
1180            TextMessage JavaDoc m = (TextMessage JavaDoc) msg;
1181            Message JavaDoc responseMessage = new Message JavaDoc(m.getText());
1182            responseMessage.setMessageType(Message.RESPONSE);
1183
1184            Service service = new Service();
1185            MessageContext msgContext = new MessageContext(service.getEngine());
1186            msgContext.setResponseMessage(responseMessage);
1187
1188            TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry();
1189            org.apache.axis.encoding.TypeMapping tm =
1190                (org.apache.axis.encoding.TypeMapping) tmr.getTypeMapping(
1191                    outputEncodingStyle);
1192
1193            // register any default type mappings
1194
registerDefaultTypeMappings(tm, getContext());
1195        
1196            // register any mappings from WSIFService.mapType calls
1197
registerDynamicTypes(tm, typeMap, getContext());
1198
1199            Message JavaDoc resMsg = msgContext.getResponseMessage();
1200            SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();
1201
1202            Object JavaDoc b = resEnv.getFirstBody();
1203            if (b instanceof SOAPFaultElement) {
1204                return new AxisFault(b.toString());
1205            }
1206
1207            RPCElement body = (RPCElement) b;
1208
1209            Object JavaDoc result = null;
1210            HashMap JavaDoc outParams;
1211            Vector JavaDoc resArgs = body.getParams();
1212
1213            if (resArgs != null && resArgs.size() > 0) {
1214                RPCParam param = (RPCParam) resArgs.get(0);
1215                result = param.getValue();
1216
1217                if (resArgs.size() > 1) {
1218                    outParams = new HashMap JavaDoc();
1219                    for (int i = 1; i < resArgs.size(); i++) {
1220                        RPCParam p = (RPCParam) resArgs.get(i);
1221                        outParams.put(p.getName(), p.getValue());
1222                    }
1223                    setResponseMessageParameters(outParams);
1224                }
1225            }
1226            return result;
1227        } catch (Exception JavaDoc ex) {
1228            Trc.exception(ex);
1229            throw new WSIFException(ex.getMessage());
1230        }
1231
1232    }
1233
1234    /**
1235     * Extracts the output or fault message parts from the axis response.
1236     */

1237    private boolean buildResponseMessages(
1238        Object JavaDoc resp,
1239        WSIFMessage outMsg,
1240        WSIFMessage faultMsg)
1241        throws WSIFException {
1242
1243        boolean respOK;
1244
1245        if (resp instanceof AxisFault) {
1246            respOK = false;
1247            if (faultMsg != null) {
1248                AxisFault f = (AxisFault) resp;
1249                faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME);
1250                faultMsg.setObjectPart(WSIFConstants.SOAP_FAULT_OBJECT, f);
1251            }
1252        } else {
1253            respOK = true;
1254            populateOutMsgReturnPart(resp, outMsg);
1255            populateOutMsgParts(outMsg);
1256        }
1257
1258        return respOK;
1259    }
1260
1261    /**
1262     * Populate the outMessage with the response return value.
1263     */

1264    private void populateOutMsgReturnPart(Object JavaDoc resp, WSIFMessage outMsg)
1265        throws WSIFException {
1266        if (outMsg != null) {
1267            
1268            // style=wrapped uses the unwrapped parts
1269
List JavaDoc soapParts;
1270            if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1271                soapParts = outputUnwrappedSOAPParts;
1272            } else {
1273                soapParts = outputSOAPParts;
1274            }
1275
1276            Part returnPart = null;
1277            if (soapParts.size() > 0) {
1278                returnPart = (Part)soapParts.get(0);
1279                setSOAPMessagePart(outMsg,returnPart.getName(), resp);
1280            } else if (outputMIMEParts.size() > 0) {
1281                returnPart = (Part)outputMIMEParts.get(0);
1282                setMIMEMessagePart(
1283                    outMsg,
1284                    returnPart.getName(),
1285                    resp,
1286                    resp == null ? null : resp.getClass());
1287            }
1288        }
1289    }
1290
1291    /**
1292     * Populates the outMessage with the expected parts.
1293     * (this only does the out parameters not the return part)
1294     */

1295    private void populateOutMsgParts(WSIFMessage outMsg) throws WSIFException {
1296        if (outMsg != null) {
1297            HashMap JavaDoc respParms = getResponseMessageParameters();
1298
1299            if (respParms != null) {
1300                // style=wrapped uses the unwrapped parts
1301
List JavaDoc soapParts;
1302                if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1303                    soapParts = outputUnwrappedSOAPParts;
1304                } else {
1305                    soapParts = outputSOAPParts;
1306                }
1307                for (int i=1; i < soapParts.size(); i++) {
1308                    Part p = (Part) soapParts.get(i);
1309                    String JavaDoc name = p.getName();
1310                    Object JavaDoc value = respParms.get(name);
1311                    setSOAPMessagePart(outMsg, name, value);
1312                }
1313                int startMIMEindex;
1314                if (soapParts.size() > 0) {
1315                    startMIMEindex = 0;
1316                } else {
1317                    startMIMEindex = 1;
1318                }
1319                for (int i=startMIMEindex; i < outputMIMEParts.size(); i++) {
1320                    Part p = (Part) outputMIMEParts.get(i);
1321                    String JavaDoc name = p.getName();
1322                    Object JavaDoc value = respParms.get(name);
1323                    setMIMEMessagePart(
1324                        outMsg,
1325                        name,
1326                        value,
1327                        value == null ? null : value.getClass());
1328                }
1329            }
1330        }
1331
1332    }
1333
1334    private static void setSOAPMessagePart(
1335        WSIFMessage msg,
1336        String JavaDoc name,
1337        Object JavaDoc value)
1338        throws WSIFException {
1339        Trc.entry(null, msg, name, value);
1340
1341        //TODO type checking against the WSDL part type
1342
msg.setObjectPart(name, value);
1343
1344        Trc.exit();
1345    }
1346
1347
1348    private static void setMIMEMessagePart(
1349        WSIFMessage msg,
1350        String JavaDoc name,
1351        Object JavaDoc value,
1352        Class JavaDoc type)
1353        throws WSIFException {
1354        Trc.entry(null, msg, name, value, type);
1355
1356        MIMEHelper.setMIMEMessagePart(msg, name, value, type);
1357
1358        Trc.exit();
1359    }
1360
1361    /**
1362     * Gets the type of a Part, if the Part doesn't have a type,
1363     * then gets the Element name as WSIF treats this as the same thing.
1364     * (for now? probably the wrong thing to be doing)
1365     */

1366    private QName JavaDoc getPartType(Part p) {
1367        QName JavaDoc type = p.getTypeName();
1368        if (type == null) {
1369            type = p.getElementName();
1370        }
1371        return type;
1372    }
1373
1374    public boolean invokeRequestResponseOperation(
1375        WSIFMessage inMsg,
1376        WSIFMessage outMsg,
1377        WSIFMessage faultMsg)
1378        throws WSIFException {
1379        Trc.entry(this, inMsg, outMsg, faultMsg);
1380        boolean workedOK = false;
1381
1382        Call call = wsifPort.getCall();
1383
1384        // Make sure we're making a fresh start.
1385
call.removeAllParameters();
1386        call.clearHeaders();
1387
1388        call.setTargetEndpointAddress(wsifPort.getEndPoint());
1389
1390        if (inputSOAPParts == null) {
1391            prepare(call);
1392        }
1393        call.setSOAPActionURI(getSoapActionURI());
1394
1395        if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)
1396        && isInputMessageUnWrapped(inMsg)) {
1397            operationStyle = WSIFAXISConstants.AXIS_STYLE_WRAPPED;
1398        }
1399
1400        // TODO: what about wrapped messaging? Not supported yet
1401
if (isMessaging(inMsg)) {
1402            operationStyle = WSIFAXISConstants.AXIS_STYLE_MESSAGE;
1403        }
1404
1405        Transport axistransport = getTransport();
1406        WSIFJMSDestination dest = null;
1407        if (axistransport != null) {
1408            call.setTransport(axistransport);
1409            if (axistransport instanceof WSIFJmsTransport) {
1410                WSIFJmsTransport jmst = (WSIFJmsTransport) axistransport;
1411                dest = jmst.getDestination();
1412                dest.setAsyncMode(isAsyncOperation());
1413                jmst.setSyncTimeout(null); // reset timeouts to defaults
1414
jmst.setAsyncTimeout(null);
1415            }
1416        }
1417
1418        if (dest != null
1419            && inJmsPropVals != null
1420            && !inJmsPropVals.isEmpty()) {
1421            checkForTimeoutProperties(inJmsPropVals, dest);
1422            dest.setProperties(inJmsPropVals);
1423        }
1424
1425        //TODO: jms:property parts
1426

1427        setDestinationContext(dest);
1428        setCallContext(call);
1429
1430        if (WSIFAXISConstants.AXIS_STYLE_MESSAGE.equals(operationStyle)) {
1431            workedOK = invokeAXISMessaging(call, inMsg, outMsg, faultMsg);
1432        } else if (WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) {
1433            workedOK = invokeAXISRPCStyle(call, inMsg, outMsg, faultMsg, dest);
1434        } else {
1435            workedOK = invokeAXISDocStyle(call, inMsg, outMsg, faultMsg);
1436        }
1437        
1438        setResponseContext(call);
1439
1440        Trc.exit(workedOK);
1441        return workedOK;
1442    }
1443
1444    /**
1445     * This attempts to determine if the WSIF input message parts are
1446     * for a wrapped or unwrapped style operation. Tricky to tell for
1447     * sure so this just checks parts with the correct names exist in
1448     * the message.
1449     * @return true if the input message has a multiple parts matching
1450     * the unwrapped SOAP parts, otherwise false
1451     */

1452    private boolean isInputMessageUnWrapped(WSIFMessage msg) {
1453        boolean unWrapped = true;
1454
1455        Object JavaDoc style = null;
1456        try {
1457            WSIFMessage context = getContext();
1458            style = context.getObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE);
1459        } catch (WSIFException e) {
1460            Trc.ignoredException(e);
1461        }
1462        if (WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED.equals(style)) {
1463            unWrapped = true;
1464        } else if (WSIFConstants.CONTEXT_OPERATION_STYLE_UNWRAPPED.equals(style)) {
1465            unWrapped = false;
1466        } else if (inputUnwrappedSOAPParts != null
1467        && inputUnwrappedSOAPParts.size() > 0) {
1468            unWrapped = true;
1469            for (Iterator JavaDoc i=inputUnwrappedSOAPParts.iterator(); i.hasNext() && unWrapped; ) {
1470                Part p = (Part) i.next();
1471                try {
1472                    msg.getObjectPart(p.getName());
1473                } catch (WSIFException e) {
1474                    unWrapped = false;
1475                }
1476            }
1477        } else {
1478            unWrapped = false;
1479        }
1480
1481        return unWrapped;
1482    }
1483
1484    /**
1485     * This attempts to determine if the WSIF input message parts are
1486     * for a 'message' style document operation.
1487     * Note: messaging cannot use unwrapped parts
1488     * @return true if all the WSIF input message part types for the
1489     * soap parts have a type of DOM Element, otherwise false
1490     */

1491    private boolean isMessaging(WSIFMessage msg) {
1492        boolean allDOMElements = true;
1493        boolean anyDOMElements = false;
1494
1495        if (msg != null) {
1496            for (Iterator JavaDoc i = inputSOAPParts.iterator(); i.hasNext(); ) {
1497                Part p = (Part) i.next();
1498                try {
1499                    Object JavaDoc o = msg.getObjectPart(p.getName());
1500                    if (o instanceof Element) {
1501                        anyDOMElements = true;
1502                    } else {
1503                        allDOMElements = false;
1504                    }
1505                } catch (WSIFException e) {
1506                    Trc.ignoredException(e);
1507                }
1508            }
1509        }
1510        return anyDOMElements && allDOMElements;
1511    }
1512
1513
1514    /**
1515     * This does the AXIS Call invoke for document style operations
1516     * when the WSIF input message parts are NOT DOM elements
1517     */

1518    private boolean invokeAXISRPCStyle(
1519        Call call,
1520        WSIFMessage inMsg,
1521        WSIFMessage outMsg,
1522        WSIFMessage faultMsg,
1523        WSIFJMSDestination dest)
1524        throws WSIFException {
1525
1526        call.setOperationName(
1527            new QName JavaDoc(getInputNamespace(), portTypeOperation.getName()));
1528
1529        setCallParameterNames(call);
1530
1531        Object JavaDoc[] inputValues = getInputMessageValues(inMsg, dest);
1532
1533        Object JavaDoc response = null;
1534        boolean respOK = true;
1535        try {
1536            String JavaDoc name = portTypeOperation.getName();
1537            Trc.event(
1538                this,
1539                "Invoking operation ",
1540                name,
1541                " input namespace ",
1542                getInputNamespace(),
1543                " parameters ",
1544                inputValues,
1545                " call object ",
1546                call);
1547
1548            response = call.invoke(getInputNamespace(), name, inputValues);
1549
1550        } catch (AxisFault e) {
1551            Trc.exception(e);
1552            response = e;
1553            respOK = false;
1554        }
1555
1556        Trc.event(this, "Returned from operation, response ", response);
1557
1558        // setJMSOutPropsInContext( dest ); TODO doesn't work yet
1559

1560        if (!isAsyncOperation()
1561        && (outputSOAPParts.size() > 0 || outputMIMEParts.size() > 0) ) {
1562            Map JavaDoc callParams = call.getOutputParams();
1563            if (callParams != null) {
1564                HashMap JavaDoc outParams = new HashMap JavaDoc();
1565                QName JavaDoc qn;
1566                for (Iterator JavaDoc i = callParams.keySet().iterator();
1567                    i.hasNext();
1568                    ) {
1569                    qn = (QName JavaDoc) i.next();
1570                    outParams.put(qn.getLocalPart(), callParams.get(qn));
1571                }
1572                setResponseMessageParameters(outParams);
1573            }
1574            respOK =
1575                buildResponseMessages(response, outMsg, faultMsg);
1576        }
1577
1578        return respOK;
1579    }
1580
1581    /**
1582     * This tells AXIS the name and type of the input, return, and output parameters.
1583     */

1584    private void setCallParameterNames(Call call) throws WSIFException {
1585
1586        String JavaDoc inputNamespace = getInputNamespace();
1587        String JavaDoc outputNamespace = "";
1588
1589        List JavaDoc soapParts;
1590        // style=wrapped uses the unwrapped parts
1591
if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1592            soapParts = inputUnwrappedSOAPParts;
1593        } else {
1594            soapParts = inputSOAPParts;
1595        }
1596
1597        /* If there are no attachments take the part ordering from the
1598         * soap:body. If there are attachments then the soap:body will
1599         * not include the attachments, so take the part ordering from
1600         * the ordering of the parts in the original message.
1601         */

1602        if (inputMIMEParts.isEmpty())
1603        {
1604            // setup the input SOAP parts
1605
for (int i = 0; i < soapParts.size(); i++)
1606            {
1607                Part p = (Part) soapParts.get(i);
1608                String JavaDoc partName = p.getName();
1609                if (!inJmsProps.containsKey(partName))
1610                {
1611                    if (WSIFAXISConstants
1612                        .STYLE_DOCUMENT
1613                        .equals(operationStyle))
1614                    {
1615                        QName JavaDoc qn = p.getElementName();
1616                        if (qn != null)
1617                        {
1618                            partName = qn.getLocalPart();
1619                        }
1620                    }
1621                    QName JavaDoc name = new QName JavaDoc(inputNamespace, partName);
1622                    QName JavaDoc type = getPartType(p);
1623                    call.addParameter(name, type, ParameterMode.IN);
1624                }
1625            }
1626        }
1627        else
1628        {
1629            // This order should include both the attachments and
1630
// the non-attachments.
1631
List JavaDoc order =
1632                portTypeOperation.getInput().getMessage().getOrderedParts(null);
1633            Iterator JavaDoc it = order.iterator();
1634            while (it.hasNext())
1635            {
1636                Part p = (Part) it.next();
1637
1638                // Only add the part if it hasn't been excluded by the
1639
// soap:body parts="?"
1640
if (inputMIMEParts.contains(p) || soapParts.contains(p))
1641                {
1642                    QName JavaDoc name = new QName JavaDoc(inputNamespace, p.getName());
1643                    QName JavaDoc type = getPartType(p);
1644                    call.addParameter(name, type, ParameterMode.IN);
1645                }
1646            }
1647        }
1648
1649        // style=wrapped uses the unwrapped parts
1650
if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1651            soapParts = outputUnwrappedSOAPParts;
1652        } else {
1653            soapParts = outputSOAPParts;
1654        }
1655
1656        // setup the return part
1657
Part returnPart = null;
1658        if (soapParts.size() > 0) {
1659            returnPart = (Part)soapParts.get(0);
1660        } else if (outputMIMEParts.size() > 0) {
1661            returnPart = (Part)outputMIMEParts.get(0);
1662        }
1663        if (returnPart == null) {
1664            call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
1665        } else {
1666            QName JavaDoc type = getPartType(returnPart);
1667            call.setReturnType(type);
1668        }
1669
1670        // setup output SOAP parts
1671
// from 1 to skip the return part
1672
for (int i = 1; i < soapParts.size(); i++) {
1673            Part p = (Part) soapParts.get(i);
1674            QName JavaDoc name = new QName JavaDoc(outputNamespace, p.getName());
1675            QName JavaDoc type = getPartType(p);
1676            call.addParameter(name, type, ParameterMode.OUT);
1677        }
1678        
1679        // setup the output MIME parts
1680
// if no soap parts dont add 1st as its the return part
1681
int startMIMEIndex = (soapParts.size() > 0) ? 0 : 1;
1682        for (int i = startMIMEIndex; i < outputMIMEParts.size(); i++) {
1683            Part p = (Part) outputMIMEParts.get(i);
1684            QName JavaDoc name = new QName JavaDoc(outputNamespace, p.getName());
1685            QName JavaDoc type = getPartType(p);
1686            call.addParameter(name, type, ParameterMode.OUT);
1687        }
1688    }
1689
1690    /**
1691     * This does the AXIS Call invoke for document style operations
1692     * when the WSIF input message parts are NOT DOM elements
1693     */

1694    private boolean invokeAXISDocStyle(
1695        Call call,
1696        WSIFMessage inMsg,
1697        WSIFMessage outMsg,
1698        WSIFMessage faultMsg)
1699        throws WSIFException {
1700
1701        boolean respOK = false;
1702
1703        // setup the call object
1704
call.setOperationName(
1705            new QName JavaDoc(getInputNamespace(), portTypeOperation.getName()));
1706        call.setScopedProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
1707        call.setScopedProperty(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
1708        call.setOperationStyle(operationStyle);
1709        setCallParameterNames(call);
1710
1711        Object JavaDoc[] inputValues = getInputMessageValues(inMsg, null);
1712
1713        // invoke the AXIS call
1714
Trc.event(this, "Invoking AXIS call", call, inputValues);
1715        Object JavaDoc response;
1716        try {
1717            response = call.invoke(inputValues);
1718            respOK = true;
1719        } catch (RemoteException JavaDoc ex) {
1720            Trc.exception(ex);
1721            throw new WSIFException(
1722                "exception on AXIS invoke: " + ex.getLocalizedMessage(),
1723                ex);
1724        }
1725        Trc.event(this, "Returned from AXIS invoke, response: ", response);
1726
1727        // process the AXIS response
1728
if (!isAsyncOperation()) {
1729
1730            // style=wrapped uses the unwrapped parts
1731
List JavaDoc soapParts;
1732            if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1733                soapParts = outputUnwrappedSOAPParts;
1734            } else {
1735                soapParts = outputSOAPParts;
1736            }
1737             
1738            if (soapParts.size() > 0 || outputMIMEParts.size() > 0) {
1739                Map JavaDoc callParams = call.getOutputParams();
1740                if (callParams != null) {
1741                    HashMap JavaDoc outParams = new HashMap JavaDoc();
1742                    QName JavaDoc qn;
1743                    for (Iterator JavaDoc i = callParams.keySet().iterator(); i.hasNext(); ) {
1744                        qn = (QName JavaDoc) i.next();
1745                        outParams.put(qn.getLocalPart(), callParams.get(qn));
1746                    }
1747                    setResponseMessageParameters(outParams);
1748                }
1749                respOK =
1750                    buildResponseMessages(response, outMsg, faultMsg);
1751            }
1752        }
1753
1754        return respOK;
1755    }
1756
1757    /**
1758     * This does the AXIS Call invoke for 'messaging' - when all the
1759     * WSIF input message parts are DOM elements
1760     */

1761    private boolean invokeAXISMessaging(
1762        Call call,
1763        WSIFMessage inMsg,
1764        WSIFMessage outMsg,
1765        WSIFMessage faultMsg)
1766        throws WSIFException {
1767
1768        boolean workedOK = false;
1769
1770        List JavaDoc attachments = addAttachments(inMsg, call);
1771
1772        Object JavaDoc[] inputValues = getInputMessageValues(inMsg, null);
1773        ArrayList JavaDoc soapBodies = new ArrayList JavaDoc();
1774        for (int i = 0; i < inputValues.length; i++) {
1775            if (inputValues[i] instanceof Element) {
1776                Element el = (Element) inputValues[i];
1777                
1778                if ((attachments.size() > 0) && (i == 0)) {
1779                    fixAttachmentPartsCID(el, attachments);
1780                }
1781                
1782                soapBodies.add(new SOAPBodyElement(el));
1783            } else {
1784                throw new WSIFException(
1785                    "unexpected input type: " + inputValues[i]);
1786            }
1787        }
1788        
1789        Object JavaDoc[] axisInputs = soapBodies.toArray();
1790
1791        Trc.event(this, "Invoking AXIS call", call, axisInputs);
1792        Object JavaDoc axisResponse; // the response should be a Vector of RPCElement objects
1793
try {
1794            axisResponse = call.invoke(axisInputs);
1795        } catch (RemoteException JavaDoc ex) {
1796            throw new WSIFException(
1797                "exception on AXIS invoke: " + ex.getLocalizedMessage(),
1798                ex);
1799        }
1800        Trc.event(this, "Returned from AXIS invoke, response: ", axisResponse);
1801
1802        setOutputMessageValues(axisResponse, outMsg);
1803
1804        workedOK = true;
1805        return workedOK;
1806    }
1807
1808    /**
1809     * Fix the CID in the href of an attachment.
1810     * When sending an attachent with messaging two parts will
1811     * be in the WSIF input message, a DOM Element for the SOAP body contents,
1812     * and a DataHandler for the attachment. The contents Element must
1813     * include a href part for the attachment. This method will find
1814     * that href part and correct the CID value for the new AttachmentPart.
1815     * SOAPBody example with a href part named 'file':
1816     * <ns1:bounceImage4 xmlns:ns1="http://mime/">
1817     * <ns1:shouldBounce xsi:type="xsd:boolean">true</ns1:shouldBounce>
1818     * <ns1:file HREF="cid:413B07CE410E48EB9D89DC0A4DDD715D"/>
1819     * </ns1:bounceImage4>
1820     */

1821    private void fixAttachmentPartsCID(Element body, List JavaDoc attachments) throws WSIFException {
1822
1823        // find all the attachment Elements in the body
1824
ArrayList JavaDoc al = new ArrayList JavaDoc();
1825        getAttachmentElements(al, body);
1826        
1827        /* this isn't so nice: the AttachmentPart has no name
1828         * so we have to assume the the List is in the same
1829         * order as the attachment Elements in the body.
1830         */

1831        if (al.size() != attachments.size()) {
1832            throw new WSIFException("unexpected number of attachments,"
1833                + attachments.size() + " AttachmentParts, "
1834                + al.size() + " attachment href elements");
1835        }
1836
1837        // fiddle the cid: for each attachment
1838
for (int i = 0; i < attachments.size(); i++ ) {
1839            AttachmentPart attachment = (AttachmentPart) attachments.get(i);
1840            Element attachmentElement = (Element) al.get(i);
1841            attachmentElement.setAttribute("href", "cid:" + attachment.getContentId());
1842        }
1843    }
1844
1845    /**
1846     * Gets all attachment Elements within an Element
1847     * This recurses through the DOM tree structure adding any
1848     * attachment Element's to the ArrayList.
1849     * An attachment Element is one which has an href attribute
1850     * which has a value starting with the String "cid:"
1851     */

1852    private static void getAttachmentElements(ArrayList JavaDoc al, Element el) {
1853        NodeList JavaDoc childNodes = el.getChildNodes();
1854        for (int j = 0; j < childNodes.getLength(); j++) {
1855            Node JavaDoc n = childNodes.item(j);
1856            if (n instanceof Element) {
1857                Element childElement = (Element) n;
1858                String JavaDoc s = childElement.getAttribute("href");
1859                if (s != null && s.toLowerCase().startsWith("cid:")) {
1860                    al.add(childElement);
1861                } else {
1862                    getAttachmentElements(al, childElement);
1863                }
1864            }
1865        }
1866    }
1867
1868    /**
1869     * Prepares this operation.
1870     * The intention of this is to setup everything that can be reused
1871     * by the WSIFOperation. Clients must not reuse a WSIFOperation
1872     * but a WSIFPort may cache WSIFOperation instances and use the
1873     * WSIFOperation copy method to return copies to clients
1874     */

1875    private void prepare(Call call) throws WSIFException {
1876        Trc.entry(this, call);
1877
1878        /* Note: if you change anything here make sure you consider
1879         * the impact to the constructor, copy and prepare methods
1880         * and to if any instance variables are transient
1881         */

1882
1883        /* Create the ArrayList identify each part and populate
1884         * by calling the appropriate parseXxxx method.
1885         */

1886        this.inputSOAPParts = new ArrayList JavaDoc();
1887        this.inputMIMEParts = new ArrayList JavaDoc();
1888        this.outputSOAPParts = new ArrayList JavaDoc();
1889        this.outputMIMEParts = new ArrayList JavaDoc();
1890
1891        parseSoapOperation();
1892        parseBindingInput();
1893        parseBindingOutput();
1894        unwrapSOAPParts();
1895        
1896        // register any jms:address propertyValues
1897
addInputJmsPropertyValues(wsifPort.getJmsAddressPropVals());
1898        
1899        if (!WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) {
1900            call.setEncodingStyle(null);
1901            inputEncodingStyle = "";
1902            outputEncodingStyle = "";
1903        }
1904
1905        if (inputNamespace == null || inputNamespace.length() < 1) {
1906            this.inputNamespace = getTargetNamespaceURI();
1907        }
1908
1909        TypeMapping tm = call.getTypeMapping();
1910        WSIFMessage context = getContext();
1911        
1912        // register any default type mappings
1913
registerDefaultTypeMappings(tm, context);
1914        
1915        // register any mappings from WSIFService.mapType calls
1916
registerDynamicTypes(tm, typeMap, context);
1917            
1918        registerMIMETypes(
1919            inputMIMEParts,
1920            call);
1921
1922        registerMIMETypes(
1923            outputMIMEParts,
1924            call);
1925
1926        if (Trc.ON) {
1927            Trc.exit(deep());
1928        }
1929    }
1930    
1931    /**
1932     * Register any default mappings from the context with the AXIS Call
1933     */

1934    static void registerDefaultTypeMappings(TypeMapping callTypeMappings, WSIFMessage context) throws WSIFException {
1935        Object JavaDoc value = null;
1936        try {
1937            value = context.getObjectPart(WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS);
1938        } catch (WSIFException e) {
1939            Trc.ignoredException(e);
1940        }
1941        if (value == null) {
1942            return;
1943        }
1944        if (!(value instanceof List JavaDoc)) {
1945            throw new WSIFException(
1946                "context part '"
1947                + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS
1948                + "' value is not an instance of java.util.List: "
1949                + value);
1950        }
1951        List JavaDoc defaultMappings = (List JavaDoc) value;
1952        for (Iterator JavaDoc i = defaultMappings.iterator(); i.hasNext(); ) {
1953            Object JavaDoc o = i.next();
1954            if (!(o instanceof TypeSerializerInfo)) {
1955                throw new WSIFException(
1956                    "context part '"
1957                    + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS
1958                    + "' value List contains an entry that is not an instance "
1959                    + "of org.apache.wsif.util.TypeSerializer: "
1960                    + value);
1961            }
1962            TypeSerializerInfo ts = (TypeSerializerInfo) o;
1963            
1964            Class JavaDoc javaType = ts.getJavaType();
1965            QName JavaDoc elementType = ts.getElementType();
1966            Object JavaDoc tmp = ts.getSerializer();
1967            SerializerFactory sf = null;
1968            if (tmp instanceof SerializerFactory) {
1969                sf = (SerializerFactory) tmp;
1970            }
1971            tmp = ts.getDeserializer();
1972            DeserializerFactory df = null;
1973            if (tmp instanceof DeserializerFactory) {
1974                df = (DeserializerFactory) tmp;
1975            }
1976                  
1977            if (javaType != null
1978            && elementType != null
1979            && (sf != null || df != null) ) {
1980                callTypeMappings.register(javaType, elementType, sf, df);
1981            } else {
1982                Trc.event(null, "ignoring default TypeSerializer invalid for AXIS:" + ts);
1983            }
1984        }
1985    }
1986
1987    /**
1988     * Register any mappings from WSIFService.mapType calls with the AXIS Call
1989     */

1990    static void registerDynamicTypes(
1991        TypeMapping tm,
1992        WSIFDynamicTypeMap typeMap,
1993        WSIFMessage context)
1994        throws WSIFException {
1995            
1996        Class JavaDoc objClass;
1997        String JavaDoc namespaceURI, localPart;
1998        WSIFDynamicTypeMapping wsifdynamictypemapping;
1999        for (Iterator JavaDoc iterator = typeMap.iterator(); iterator.hasNext();) {
2000            wsifdynamictypemapping = (WSIFDynamicTypeMapping) iterator.next();
2001            objClass = wsifdynamictypemapping.getJavaType();
2002            QName JavaDoc xmlType = wsifdynamictypemapping.getXmlType();
2003
2004            SerializerFactory sf = null;
2005            DeserializerFactory df = null;
2006            
2007            // the context may override the default (de)serializer for a type
2008
TypeSerializerInfo contextTypeSerializer =
2009                findContextTypeSerialzer(context, objClass, xmlType);
2010            if (contextTypeSerializer != null) {
2011                objClass = contextTypeSerializer.getJavaType();
2012                xmlType = contextTypeSerializer.getElementType();
2013                sf = (SerializerFactory) contextTypeSerializer.getSerializer();
2014                df = (DeserializerFactory) contextTypeSerializer.getDeserializer();
2015            }
2016            
2017            if (sf == null && tm.getSerializer(objClass, xmlType) == null) {
2018                if (objClass.isArray()) {
2019                    sf = new ArraySerializerFactory();
2020                } else if (SimpleType.class.isAssignableFrom(objClass)) {
2021                    sf = new SimpleSerializerFactory(objClass, xmlType);
2022                } else {
2023                    sf = new BeanSerializerFactory(objClass, xmlType);
2024                }
2025            }
2026
2027            if (df == null && tm.getDeserializer(objClass, xmlType) == null) {
2028                if (objClass.isArray()) {
2029                    df = new ArrayDeserializerFactory();
2030                } else if (SimpleType.class.isAssignableFrom(objClass)) {
2031                    df = new SimpleDeserializerFactory(objClass, xmlType);
2032                } else {
2033                    df = new BeanDeserializerFactory(objClass, xmlType);
2034                }
2035            }
2036
2037            namespaceURI =
2038                wsifdynamictypemapping.getXmlType().getNamespaceURI();
2039
2040            // Filter out XSD and SOAP-ENC types from those we explicitly map.
2041
// Axis already knows how to deal with these; using the BeanSerializer
2042
// would be wrong anyway as they represent simple types and not beans.
2043
if (!isDefaultSOAPNamespace(namespaceURI) ) {
2044                    
2045                localPart = wsifdynamictypemapping.getXmlType().getLocalPart();
2046                QName JavaDoc qn = new QName JavaDoc(namespaceURI, localPart);
2047
2048                if (sf != null || df != null) {
2049                    tm.register(objClass, qn, sf, df);
2050                }
2051            }
2052        }
2053    }
2054
2055    private static TypeSerializerInfo findContextTypeSerialzer(
2056        WSIFMessage context,
2057        Class JavaDoc clazz,
2058        QName JavaDoc xmlType)
2059        throws WSIFException {
2060
2061        Object JavaDoc value = null;
2062        try {
2063            value = context.getObjectPart(WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS);
2064        } catch (WSIFException e) {
2065            Trc.ignoredException(e);
2066        }
2067        if (value == null) {
2068            return null;
2069        }
2070        if (!(value instanceof List JavaDoc)) {
2071            throw new WSIFException(
2072                "context part '"
2073                + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS
2074                + "' value is not an instance of java.util.List: "
2075                + value);
2076        }
2077        
2078        List JavaDoc typeSerializers = (List JavaDoc) value;
2079        for (Iterator JavaDoc i = typeSerializers.iterator(); i.hasNext(); ) {
2080            Object JavaDoc o = i.next();
2081            if (!(o instanceof TypeSerializerInfo)) {
2082                throw new WSIFException(
2083                    "context part '"
2084                    + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS
2085                    + "' value List contains an entry that is not an instance "
2086                    + "of org.apache.wsif.util.TypeSerializer: "
2087                    + value);
2088            }
2089            TypeSerializerInfo tm = (TypeSerializerInfo) o;
2090                
2091            Class JavaDoc javaType = tm.getJavaType();
2092            QName JavaDoc elementType = tm.getElementType();
2093            Object JavaDoc serializer = tm.getSerializer();
2094            Object JavaDoc deserializer = tm.getDeserializer();
2095                 
2096            if ( (javaType != null) || (javaType.isAssignableFrom(clazz))
2097            && ( (elementType != null) || (elementType.equals(xmlType)) ) ){
2098                if (serializer == null || serializer instanceof SerializerFactory
2099                && deserializer == null || deserializer instanceof DeserializerFactory
2100                && serializer != null || deserializer != null) {
2101                    return tm;
2102                }
2103            }
2104        }
2105
2106        return null; // couldn't find a TypeSerializer
2107
}
2108    
2109    private static boolean isDefaultSOAPNamespace(String JavaDoc ns) {
2110        boolean soapNamespace = false;
2111         if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns)
2112         || WSIFConstants.NS_URI_2000_SCHEMA_XSD.equals(ns)
2113         || WSIFConstants.NS_URI_2001_SCHEMA_XSD.equals(ns)
2114         || WSIFConstants.NS_URI_SOAP_ENC.equals(ns) ){
2115            soapNamespace = true;
2116         }
2117         return soapNamespace;
2118    }
2119
2120    /**
2121     * Gets an array of all the input WSIFMessage values
2122     */

2123    private Object JavaDoc[] getInputMessageValues(WSIFMessage inMsg, WSIFJMSDestination dest) throws WSIFException {
2124        ArrayList JavaDoc axisInputs = new ArrayList JavaDoc();
2125        List JavaDoc soapParts;
2126
2127        // style=wrapped uses the unwrapped parts
2128
if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
2129            soapParts = inputUnwrappedSOAPParts;
2130        } else {
2131            soapParts = inputSOAPParts;
2132        }
2133        
2134        /* If there are no attachments take the part ordering from the
2135         * soap:body. If there are attachments then the soap:body will
2136         * not include the attachments, so take the part ordering from
2137         * the ordering of the parts in the original message.
2138         */

2139        if (inputMIMEParts.isEmpty())
2140        {
2141            for (int i = 0; i < soapParts.size(); i++)
2142            {
2143                Part p = (Part) soapParts.get(i);
2144                String JavaDoc partName = p.getName();
2145                Object JavaDoc value;
2146                try
2147                {
2148                    value = inMsg.getObjectPart(partName);
2149                }
2150                catch (WSIFException e)
2151                {
2152                    Trc.ignoredException(e);
2153                    value = null; // missing part values default to null
2154
}
2155                if (inJmsProps.containsKey(partName) && dest != null)
2156                {
2157                    String JavaDoc name = (String JavaDoc) (inJmsProps.get(partName));
2158                    if (!timeoutProperty(dest, name, value))
2159                    {
2160                        dest.setProperty(name, value);
2161                    }
2162                }
2163                else
2164                {
2165                    axisInputs.add(value);
2166                }
2167
2168            }
2169        }
2170        else
2171        {
2172            // This order includes both the attachments and
2173
// the non-attachments.
2174
List JavaDoc order =
2175                portTypeOperation.getInput().getMessage().getOrderedParts(null);
2176            Iterator JavaDoc it = order.iterator();
2177            while (it.hasNext())
2178            {
2179                Part p = (Part) it.next();
2180                String JavaDoc partName = p.getName();
2181
2182                // Only add the part if it hasn't been excluded by the
2183
// soap:body parts="?"
2184
if (soapParts.contains(p)
2185                    || (inputMIMEParts.contains(p)
2186                        && !WSIFAXISConstants.AXIS_STYLE_MESSAGE.equals(
2187                            operationStyle)))
2188                {
2189                    Object JavaDoc value;
2190                    try
2191                    {
2192                        value = inMsg.getObjectPart(partName);
2193                    }
2194                    catch (WSIFException e)
2195                    {
2196                        Trc.ignoredException(e);
2197                        value = null; // missing part values default to null
2198
}
2199                    if (inJmsProps.containsKey(partName) && dest != null)
2200                    {
2201                        String JavaDoc name = (String JavaDoc) (inJmsProps.get(partName));
2202                        if (!timeoutProperty(dest, name, value))
2203                        {
2204                            dest.setProperty(name, value);
2205                        }
2206                    }
2207                    else
2208                    {
2209                        axisInputs.add(value);
2210                    }
2211                }
2212            }
2213        }
2214        return axisInputs.toArray();
2215    }
2216
2217    /**
2218     * adds all the attachments to the AXIS call
2219     * returns a List of all the AttachmentPart so that href parts
2220     * can be made for each attachment later if required.
2221     */

2222    private List JavaDoc addAttachments(WSIFMessage inMsg, Call call) throws WSIFException {
2223        ArrayList JavaDoc attachments = new ArrayList JavaDoc();
2224        for (int i = 0; i < inputMIMEParts.size(); i++) {
2225            Part p = (Part) inputMIMEParts.get(i);
2226            try {
2227                String JavaDoc partName = p.getName();
2228                Object JavaDoc value = inMsg.getObjectPart(partName);
2229                AttachmentPart ap = MIMEHelper.getAttachementPart(value);
2230                call.addAttachmentPart(ap);
2231                attachments.add(ap);
2232            } catch (WSIFException e) {
2233                throw new WSIFException("attachment part '" + p.getName() + "' not in input WSIFMessage");
2234            }
2235        }
2236        return attachments;
2237    }
2238
2239    /**
2240     * This extracts the values from the AXIS response when using messaging
2241     * The response could have DOM elements for the SOAP parts, or
2242     * AttachmentParts for the attachments.
2243     * TODO: only tested with a single response part - either SOAP or MIME
2244     * need to test with multiple outputs as probably doesn't work yet.
2245     */

2246    private void setOutputMessageValues(
2247        Object JavaDoc axisResponse,
2248        WSIFMessage outMsg)
2249        throws WSIFException {
2250        if (!(axisResponse instanceof Vector JavaDoc)) {
2251            throw new WSIFException(
2252                "expect response type of java.util.Vector of SOAPBodyElement, found: "
2253                    + axisResponse);
2254        }
2255
2256        Vector JavaDoc v = (Vector JavaDoc) axisResponse;
2257        for (int i = 0; i < v.size(); i++) {
2258            if (v.elementAt(i) instanceof RPCElement) {
2259                RPCElement rpcEl = (RPCElement) v.elementAt(i);
2260
2261                QName JavaDoc qn = new QName JavaDoc(rpcEl.getNamespaceURI(), rpcEl.getName());
2262                Part p = findPart(outputSOAPParts, qn);
2263                if (p != null) {
2264                    setSOAPPart(outMsg, rpcEl, p);
2265                } else {
2266                    setAttachmentPart(outMsg, rpcEl);
2267                }
2268                
2269            } else {
2270                throw new WSIFException(
2271                    "expecting response type org.w3c.dom.Element, found: "
2272                        + v.elementAt(i));
2273            }
2274        }
2275    }
2276
2277    /**
2278     * Extract a SOAP part from response and put in the output WSIFMessage
2279     */

2280    private void setSOAPPart(WSIFMessage outMsg, RPCElement rpcEl, Part p) throws WSIFException {
2281        Object JavaDoc responseValue = null;
2282        try {
2283            responseValue = rpcEl.getAsDOM();
2284        } catch (Exception JavaDoc e) {
2285            throw new WSIFException(
2286                "exception getting soap body as DOM: " +
2287                e.getLocalizedMessage(),
2288                e);
2289        }
2290        String JavaDoc partName = p.getName();
2291        outMsg.setObjectPart(partName, responseValue);
2292    }
2293
2294    /**
2295     * Extract an attachment DataHandler from response and put in the output WSIFMessage
2296     */

2297    private void setAttachmentPart(WSIFMessage outMsg, RPCElement rpcEl) throws WSIFException {
2298
2299        Vector JavaDoc params;
2300        try {
2301            params = rpcEl.getParams();
2302        } catch (SAXException JavaDoc e) {
2303            throw new WSIFException(
2304                "SAXException getting response MIME part: " +
2305                e.getLocalizedMessage(),
2306                e);
2307        }
2308
2309        if (params == null || params.size() < 1) {
2310            throw new WSIFException(
2311                "no attachments found in response element: " + rpcEl);
2312        }
2313        
2314        //TODO: will there ever be more than 1?
2315
RPCParam rpcParam = (RPCParam) params.get(0);
2316
2317        QName JavaDoc qn = rpcParam.getQName();
2318        Part p = findPart(outputMIMEParts, qn);
2319        if (p != null) {
2320            Object JavaDoc responseValue = rpcParam.getValue();
2321            if (responseValue instanceof AttachmentPart) {
2322                try {
2323                    Object JavaDoc attachment = ((AttachmentPart)responseValue).getDataHandler();
2324                    String JavaDoc partName = p.getName();
2325                    outMsg.setObjectPart(partName, attachment);
2326                } catch (SOAPException JavaDoc e) {
2327                    throw new WSIFException(
2328                        "SOAPException getting DataHandler from AttachmentPart: " +
2329                        e.getLocalizedMessage(),
2330                        e);
2331                }
2332            } else {
2333                throw new WSIFException(
2334                    "expecting response AttachmentPart but found: " + responseValue);
2335            }
2336        } else {
2337            throw new WSIFException("cannot find a WSDL output MIME part for response element: " + rpcEl);
2338        }
2339
2340    }
2341
2342    /**
2343     * Searches the list of parts for one that matches the name.
2344     * The list of parts will be the outputSOAPParts or outputMIMEParts
2345     */

2346    private Part findPart(List JavaDoc partsList, QName JavaDoc partName) {
2347        Part part = null;
2348        for (Iterator JavaDoc i = partsList.iterator(); i.hasNext() && part == null; ) {
2349            Part p = (Part) i.next();
2350            if (partName.equals(p.getElementName())) {
2351                part = p;
2352            } else if (partName.getLocalPart().equals(p.getName())) {
2353                part = p;
2354            }
2355        }
2356        return part;
2357    }
2358
2359    /**
2360     * Automatically register MIME types as DataHandler.
2361     */

2362    private void registerMIMETypes(
2363        List JavaDoc mimeParts,
2364        Call call) {
2365        if (mimeParts != null && !mimeParts.isEmpty()) {
2366            for (Iterator JavaDoc i = mimeParts.iterator(); i.hasNext(); ) {
2367                Part p = (Part) i.next();
2368                QName JavaDoc type = getPartType(p);
2369                MIMEHelper.registerAttachmentType(call, type);
2370            }
2371        }
2372    }
2373
2374    /**
2375     * Sets the response handler that will be used to
2376     * process the response to an asynchronous request.
2377     * @param responseHandler the responseHandler to use
2378     */

2379    private void setResponseHandler(WSIFResponseHandler responseHandler) {
2380        this.responseHandler = responseHandler;
2381    }
2382
2383    /**
2384     * Gets the response handler that will be used to
2385     * process the response to a asynchronous request.
2386     * @return the current response handler.
2387     * package visable as its used by the transport
2388     */

2389    WSIFResponseHandler getResponseHandler() {
2390        return responseHandler;
2391    }
2392
2393    /**
2394     * @deprecated should anyone be calling this?
2395     */

2396    public void setDefinition(Definition definition1) {
2397        Trc.entry(this, definition1);
2398        throw new RuntimeException JavaDoc("method nolonger supported");
2399    }
2400
2401    public void setDynamicWSIFPort(WSIFPort_ApacheAxis wsifport_apacheaxis) {
2402        Trc.entry(this, wsifport_apacheaxis);
2403        wsifPort = wsifport_apacheaxis;
2404        Trc.exit();
2405    }
2406
2407    public void setInputEncodingStyle(String JavaDoc s) {
2408        Trc.entry(this, s);
2409        inputEncodingStyle = s;
2410        Trc.exit();
2411    }
2412
2413    public void setInputNamespace(String JavaDoc s) {
2414        Trc.entry(this, s);
2415        inputNamespace = s;
2416        Trc.exit();
2417    }
2418
2419    public void setOperation(Operation operation1) {
2420        Trc.entry(this, operation1);
2421        portTypeOperation = operation1;
2422        Trc.exit();
2423    }
2424
2425    public void setOutputEncodingStyle(String JavaDoc s) {
2426        Trc.entry(this, s);
2427        outputEncodingStyle = s;
2428        Trc.exit();
2429    }
2430
2431    public void setSoapActionURI(String JavaDoc s) {
2432        Trc.entry(this, s);
2433        soapActionURI = s;
2434        Trc.exit();
2435    }
2436
2437    private void setResponseMessageParameters(HashMap JavaDoc hm) {
2438        this.responseMessageParameters = hm;
2439    }
2440
2441    /**
2442     * Sets if the currently executing request is an asynchronous request.
2443     *
2444     * @param b true if the current request is a asynchronous request,
2445     * otherwise false
2446     */

2447    private void setAsyncOperation(boolean b) {
2448        asyncOperation = b;
2449    }
2450
2451    /**
2452     * Gets the target namespace URI of this WSIFOperation
2453     *
2454     * @return the target namespace URI
2455     */

2456    public String JavaDoc getTargetNamespaceURI() {
2457        Trc.entry(this);
2458        Definition d = getDefinition();
2459        String JavaDoc s = (d == null) ? "" : d.getTargetNamespace();
2460        Trc.exit(s);
2461        return s;
2462    }
2463
2464    /**
2465     * This sets up the output JMS property values in the context
2466     */

2467    private void setJMSOutPropsInContext(WSIFJMSDestination dest)
2468        throws WSIFException {
2469        if (dest == null) {
2470            return;
2471        }
2472        HashMap JavaDoc props = dest.getProperties();
2473        if (props != null) {
2474            getContext().setParts(props);
2475        }
2476    }
2477
2478    /**
2479     * This sets up any context JMS property values in the Destination
2480     */

2481    private void setDestinationContext(WSIFJMSDestination dest) throws WSIFException {
2482        if (dest == null) {
2483            return;
2484        }
2485        WSIFMessage context = getContext();
2486        HashMap JavaDoc jmsProps = new HashMap JavaDoc();
2487        for (Iterator JavaDoc i = context.getPartNames(); i.hasNext();) {
2488            String JavaDoc partName = (String JavaDoc) i.next();
2489            try {
2490                Object JavaDoc value = context.getObjectPart(partName);
2491                if (!timeoutProperty(dest, partName, value)) {
2492                    if (partName
2493                        .startsWith(WSIFConstants.CONTEXT_JMS_PREFIX)) {
2494                        String JavaDoc propertyName =
2495                            partName.substring(
2496                                WSIFConstants.CONTEXT_JMS_PREFIX.length());
2497                        jmsProps.put(propertyName, value);
2498                    }
2499                }
2500            } catch (WSIFException ex) {
2501                Trc.ignoredException(ex);
2502            }
2503        }
2504        if (jmsProps.size() > 0) {
2505            dest.setProperties(jmsProps);
2506        }
2507    }
2508
2509    /**
2510     * This sets up the context headers in the axis
2511     * Call object prior to invoke method being issued.
2512     */

2513    private void setCallContext(Call call) throws WSIFException {
2514        Object JavaDoc o;
2515        String JavaDoc name;
2516        WSIFMessage context = getContext();
2517
2518        name = WSIFConstants.CONTEXT_HTTP_USER;
2519        try {
2520            o = context.getObjectPart(name);
2521            if (o instanceof String JavaDoc) {
2522                addHTTPHeader(call, name, (String JavaDoc) o);
2523            }
2524        } catch (WSIFException ex) {
2525            Trc.ignoredException(ex);
2526        }
2527
2528        name = WSIFConstants.CONTEXT_HTTP_PSWD;
2529        try {
2530            o = context.getObjectPart(name);
2531            if (o instanceof String JavaDoc) {
2532                addHTTPHeader(call, name, (String JavaDoc) o);
2533            }
2534        } catch (WSIFException ex) {
2535            Trc.ignoredException(ex);
2536        }
2537
2538        try {
2539            name = WSIFConstants.CONTEXT_REQUEST_SOAP_HEADERS;
2540            o = context.getObjectPart(name);
2541            if (o instanceof List JavaDoc) {
2542                addSOAPHeader(call, name, (List JavaDoc) o);
2543            }
2544        } catch (WSIFException ex) {
2545            Trc.ignoredException(ex);
2546        }
2547    }
2548
2549    /**
2550     * This sets up any context from the response message
2551     */

2552    private void setResponseContext(Call call) throws WSIFException {
2553        org.apache.axis.Message m = call.getResponseMessage();
2554        if (m != null) {
2555            javax.xml.soap.SOAPEnvelope JavaDoc env;
2556            try {
2557                env = m.getSOAPEnvelope();
2558            } catch (AxisFault e) {
2559                throw new WSIFException(
2560                    "AxisFault getting response SOAP envelope", e);
2561            }
2562            if (env != null) {
2563                javax.xml.soap.SOAPHeader JavaDoc soapHeader;
2564                try {
2565                    soapHeader = env.getHeader();
2566                } catch (SOAPException JavaDoc e) {
2567                    throw new WSIFException(
2568                        "SOAPException getting response headers from SOAP envelope", e);
2569                }
2570                addContextResponseSOAPHeaders(soapHeader);
2571            }
2572        }
2573    }
2574
2575    /**
2576     * Sets any SOAP headers from the context message.
2577     */

2578    private void addSOAPHeader(Call call, String JavaDoc name, List JavaDoc soapHeaders) {
2579        for (Iterator JavaDoc i = soapHeaders.iterator(); i.hasNext();) {
2580            Object JavaDoc o = i.next();
2581            if (o instanceof Element) {
2582                call.addHeader(new SOAPHeaderElement((Element) o));
2583            }
2584        }
2585    }
2586
2587    /**
2588     * This adds any SOAP headers in the response to the context
2589     */

2590    private void addContextResponseSOAPHeaders(
2591        javax.xml.soap.SOAPHeader JavaDoc soapHeader) throws WSIFException {
2592            
2593        if( soapHeader != null ) {
2594            ArrayList JavaDoc headers = new ArrayList JavaDoc();
2595            for(Iterator JavaDoc i = soapHeader.getChildElements(); i.hasNext(); ) {
2596                Object JavaDoc o = i.next();
2597                if (o instanceof SOAPHeaderElement) {
2598                    SOAPHeaderElement she = (SOAPHeaderElement) o;
2599                    try {
2600                        headers.add(she.getAsDOM());
2601                    } catch (Exception JavaDoc e) {
2602                        throw new WSIFException(
2603                            "exception getting response SOAP header",
2604                            e);
2605                    }
2606                } else {
2607                    Trc.event("unexpected response SOAP header type: ", o);
2608                }
2609            }
2610            if (headers.size() > 0) {
2611                WSIFMessage context = getContext();
2612                context.setObjectPart(
2613                    WSIFConstants.CONTEXT_RESPONSE_SOAP_HEADERS,
2614                    headers);
2615                setContext(context);
2616            }
2617        }
2618    }
2619
2620    /**
2621     * Sets the HTTP header value in the message context.
2622     * How these are used depends on the underlying transport,
2623     * eg. org.apache.axis.transport.http.HTTPSender
2624     * will use the 'user.id' and 'user.password' headers
2625     * for HTTP basic authentication..
2626     */

2627    private void addHTTPHeader(Call call, String JavaDoc name, String JavaDoc value) {
2628        if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
2629            call.setProperty(Call.USERNAME_PROPERTY, value);
2630        } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
2631            call.setProperty(Call.PASSWORD_PROPERTY, value);
2632        }
2633    }
2634
2635    /**
2636     * This checks if any of the JMS propertyValues are for the
2637     * sync or async timeout values. If so it set the appropriate
2638     * value on the JMS transport and removes the property from
2639     * the JMS propertyValues list.
2640     */

2641    private void checkForTimeoutProperties(
2642        HashMap JavaDoc inJmsPropVals,
2643        WSIFJMSDestination dest)
2644        throws WSIFException {
2645        for (Iterator JavaDoc i = inJmsPropVals.keySet().iterator(); i.hasNext();) {
2646            String JavaDoc name = (String JavaDoc) i.next();
2647            Object JavaDoc value = inJmsPropVals.get(name);
2648            if (timeoutProperty(dest, name, value)) {
2649                i.remove();
2650            }
2651        }
2652    }
2653
2654    private boolean timeoutProperty(
2655        WSIFJMSDestination dest,
2656        String JavaDoc propertyName,
2657        Object JavaDoc value)
2658        throws WSIFException {
2659        boolean isTimeoutProperty = false;
2660        try {
2661            if (WSIFConstants.WSIF_PROP_SYNC_TIMEOUT.equals(propertyName)) {
2662                isTimeoutProperty = true;
2663                Long JavaDoc syncTimeout = new Long JavaDoc(value.toString());
2664                WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
2665                transport.setSyncTimeout(syncTimeout);
2666                Trc.event(this, "overridding syncTimeout to " + syncTimeout);
2667            } else if (
2668                WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT.equals(propertyName)) {
2669                isTimeoutProperty = true;
2670                Long JavaDoc asyncTimeout = new Long JavaDoc(value.toString());
2671                WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
2672                transport.setAsyncTimeout(asyncTimeout);
2673                Trc.event(this, "overridding asyncTimeout to " + asyncTimeout);
2674            }
2675        } catch (NumberFormatException JavaDoc ex) {
2676            Trc.ignoredException(ex);
2677        }
2678        return isTimeoutProperty;
2679    }
2680
2681    /**
2682     * Returns true if primitive is the equivalent primitive class of clazz.
2683     * Why doesn't java provide this function?
2684     */

2685    private static boolean isPrimitiveOf(Class JavaDoc clazz, Class JavaDoc primitive) {
2686        if ((primitive.equals(boolean.class)
2687            && Boolean JavaDoc.class.isAssignableFrom(clazz))
2688            || (primitive.equals(char.class)
2689                && Character JavaDoc.class.isAssignableFrom(clazz))
2690            || (primitive.equals(byte.class)
2691                && Byte JavaDoc.class.isAssignableFrom(clazz))
2692            || (primitive.equals(short.class)
2693                && Short JavaDoc.class.isAssignableFrom(clazz))
2694            || (primitive.equals(int.class)
2695                && Integer JavaDoc.class.isAssignableFrom(clazz))
2696            || (primitive.equals(long.class)
2697                && Long JavaDoc.class.isAssignableFrom(clazz))
2698            || (primitive.equals(float.class)
2699                && Float JavaDoc.class.isAssignableFrom(clazz))
2700            || (primitive.equals(double.class)
2701                && Double JavaDoc.class.isAssignableFrom(clazz)))
2702            return true;
2703        else
2704            return false;
2705    }
2706
2707    // package visable as it's used by WSIFJmsTransport
2708
void setAsyncRequestID(WSIFCorrelationId asyncRequestID) {
2709        Trc.entry(this, asyncRequestID);
2710        this.asyncRequestID = asyncRequestID;
2711        Trc.exit();
2712    }
2713
2714    /**
2715     * @deprecated use getOperationStyle
2716     */

2717    public String JavaDoc getStyle() {
2718        return operationStyle;
2719    }
2720
2721    /**
2722     * Returns the operation style.
2723     * @return String
2724     */

2725    public String JavaDoc getOperationStyle() {
2726        return operationStyle;
2727    }
2728
2729    /**
2730     * @deprecated use setOperationStyle
2731     */

2732    public void setStyle(String JavaDoc style) {
2733        this.operationStyle = style;
2734    }
2735
2736    /**
2737     * @deprecated should anyone be doing this?
2738     */

2739    public void setOperationStyle(String JavaDoc style) {
2740        this.operationStyle = style;
2741    }
2742
2743    public String JavaDoc deep() {
2744        StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
2745        try {
2746            buff.append(super.toString()).append(":\n");
2747            buff.append("wsifPort:").append(wsifPort);
2748            buff.append(" portTypeOperation:").append(Trc.brief(portTypeOperation));
2749            buff.append(" bindingOperation:").append(bindingOperation);
2750            buff.append(" soapOperation:").append(soapOperation);
2751            buff.append(" operationStyle:").append(operationStyle);
2752            buff.append(" inputSOAPParts:").append(inputSOAPParts);
2753            buff.append(" inputUnwrappedSOAPParts:").append(inputUnwrappedSOAPParts);
2754            buff.append(" inputMIMEParts:").append(inputMIMEParts);
2755            buff.append(" inputSOAPHeader:").append(inputSOAPHeader);
2756            buff.append(" inputSOAPHeaderFault:").append(inputSOAPHeaderFault);
2757            buff.append(" outputSOAPParts:").append(outputSOAPParts);
2758            buff.append(" outputUnwrappedSOAPParts:").append(outputUnwrappedSOAPParts);
2759            buff.append(" outputMIMEParts:").append(outputMIMEParts);
2760            buff.append(" outputSOAPHeader:").append(outputSOAPHeader);
2761            buff.append(" outputSOAPHeaderFault:").append(outputSOAPHeaderFault);
2762            buff.append(" inputEncodingStyle:").append(inputEncodingStyle);
2763            buff.append(" inputNamespace:").append(inputNamespace);
2764            buff.append(" actionUri:").append(soapActionURI);
2765            buff.append(" inJmsProps:").append(inJmsProps);
2766            buff.append(" outJmsProps:").append(outJmsProps);
2767            buff.append(" inJmsPropVals:").append(inJmsPropVals);
2768            buff.append(" context:").append(context);
2769            buff.append(" asyncOperation:").append(asyncOperation);
2770            buff.append(" asyncRequestID:").append(asyncRequestID);
2771            buff.append(" responseHandler:").append(responseHandler);
2772            buff.append(" responseMessageParameters:").append(responseMessageParameters);
2773            buff.append(" outputEncodingStyle:").append(outputEncodingStyle);
2774            buff.append(" typeMap:").append(typeMap);
2775        } catch (Exception JavaDoc e) {
2776            Trc.exceptionInTrace(e);
2777        }
2778        return buff.toString();
2779    }
2780}
2781
Popular Tags