Source Code Cross Referenced for WSIFOperation_ApacheAxis.java in  » Web-Services » wsif » org » apache » wsif » providers » soap » apacheaxis » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » wsif » org.apache.wsif.providers.soap.apacheaxis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The Apache Software License, Version 1.1
0003:         *
0004:         *
0005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
0006:         * reserved.
0007:         *
0008:         * Redistribution and use in source and binary forms, with or without
0009:         * modification, are permitted provided that the following conditions
0010:         * are met:
0011:         *
0012:         * 1. Redistributions of source code must retain the above copyright
0013:         *    notice, this list of conditions and the following disclaimer. 
0014:         *
0015:         * 2. Redistributions in binary form must reproduce the above copyright
0016:         *    notice, this list of conditions and the following disclaimer in
0017:         *    the documentation and/or other materials provided with the
0018:         *    distribution.
0019:         *
0020:         * 3. The end-user documentation included with the redistribution,
0021:         *    if any, must include the following acknowledgment:  
0022:         *       "This product includes software developed by the
0023:         *        Apache Software Foundation (http://www.apache.org/)."
0024:         *    Alternately, this acknowledgment may appear in the software itself,
0025:         *    if and wherever such third-party acknowledgments normally appear.
0026:         *
0027:         * 4. The names "WSIF" and "Apache Software Foundation" must
0028:         *    not be used to endorse or promote products derived from this
0029:         *    software without prior written permission. For written 
0030:         *    permission, please contact apache@apache.org.
0031:         *
0032:         * 5. Products derived from this software may not be called "Apache",
0033:         *    nor may "Apache" appear in their name, without prior written
0034:         *    permission of the Apache Software Foundation.
0035:         *
0036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0047:         * SUCH DAMAGE.
0048:         * ====================================================================
0049:         *
0050:         * This software consists of voluntary contributions made by many
0051:         * individuals on behalf of the Apache Software Foundation and was
0052:         * originally based on software copyright (c) 2001, 2002, International
0053:         * Business Machines, Inc., http://www.apache.org.  For more
0054:         * information on the Apache Software Foundation, please see
0055:         * <http://www.apache.org/>.
0056:         */
0057:
0058:        package org.apache.wsif.providers.soap.apacheaxis;
0059:
0060:        import java.rmi.RemoteException;
0061:        import java.util.ArrayList;
0062:        import java.util.Arrays;
0063:        import java.util.HashMap;
0064:        import java.util.Iterator;
0065:        import java.util.List;
0066:        import java.util.Map;
0067:        import java.util.Vector;
0068:
0069:        import javax.jms.TextMessage;
0070:        import javax.wsdl.Binding;
0071:        import javax.wsdl.BindingFault;
0072:        import javax.wsdl.BindingInput;
0073:        import javax.wsdl.BindingOperation;
0074:        import javax.wsdl.BindingOutput;
0075:        import javax.wsdl.Definition;
0076:        import javax.wsdl.Input;
0077:        import javax.wsdl.Operation;
0078:        import javax.wsdl.Output;
0079:        import javax.wsdl.Part;
0080:        import javax.wsdl.extensions.mime.MIMEContent;
0081:        import javax.wsdl.extensions.mime.MIMEMimeXml;
0082:        import javax.wsdl.extensions.mime.MIMEMultipartRelated;
0083:        import javax.wsdl.extensions.mime.MIMEPart;
0084:        import javax.wsdl.extensions.soap.SOAPBody;
0085:        import javax.wsdl.extensions.soap.SOAPFault;
0086:        import javax.wsdl.extensions.soap.SOAPHeader;
0087:        import javax.wsdl.extensions.soap.SOAPHeaderFault;
0088:        import javax.wsdl.extensions.soap.SOAPOperation;
0089:        import javax.xml.namespace.QName;
0090:        import javax.xml.rpc.ParameterMode;
0091:        import javax.xml.soap.SOAPException;
0092:
0093:        import org.apache.axis.AxisEngine;
0094:        import org.apache.axis.AxisFault;
0095:        import org.apache.axis.Message;
0096:        import org.apache.axis.MessageContext;
0097:        import org.apache.axis.attachments.AttachmentPart;
0098:        import org.apache.axis.client.Call;
0099:        import org.apache.axis.client.Service;
0100:        import org.apache.axis.client.Transport;
0101:        import org.apache.axis.encoding.DeserializerFactory;
0102:        import org.apache.axis.encoding.SerializerFactory;
0103:        import org.apache.axis.encoding.SimpleType;
0104:        import org.apache.axis.encoding.TypeMapping;
0105:        import org.apache.axis.encoding.TypeMappingRegistry;
0106:        import org.apache.axis.encoding.ser.ArrayDeserializerFactory;
0107:        import org.apache.axis.encoding.ser.ArraySerializerFactory;
0108:        import org.apache.axis.encoding.ser.BeanDeserializerFactory;
0109:        import org.apache.axis.encoding.ser.BeanSerializerFactory;
0110:        import org.apache.axis.encoding.ser.SimpleDeserializerFactory;
0111:        import org.apache.axis.encoding.ser.SimpleSerializerFactory;
0112:        import org.apache.axis.message.RPCElement;
0113:        import org.apache.axis.message.RPCParam;
0114:        import org.apache.axis.message.SOAPBodyElement;
0115:        import org.apache.axis.message.SOAPEnvelope;
0116:        import org.apache.axis.message.SOAPFaultElement;
0117:        import org.apache.axis.message.SOAPHeaderElement;
0118:        import org.apache.wsif.WSIFConstants;
0119:        import org.apache.wsif.WSIFCorrelationId;
0120:        import org.apache.wsif.WSIFException;
0121:        import org.apache.wsif.WSIFMessage;
0122:        import org.apache.wsif.WSIFPort;
0123:        import org.apache.wsif.WSIFResponseHandler;
0124:        import org.apache.wsif.base.WSIFDefaultOperation;
0125:        import org.apache.wsif.logging.Trc;
0126:        import org.apache.wsif.providers.WSIFDynamicTypeMap;
0127:        import org.apache.wsif.providers.WSIFDynamicTypeMapping;
0128:        import org.apache.wsif.util.TypeSerializerInfo;
0129:        import org.apache.wsif.util.WSIFUtils;
0130:        import org.apache.wsif.util.jms.WSIFJMSDestination;
0131:        import org.apache.wsif.wsdl.extensions.jms.JMSProperty;
0132:        import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue;
0133:        import org.w3c.dom.Element;
0134:        import org.w3c.dom.Node;
0135:        import org.w3c.dom.NodeList;
0136:        import org.xml.sax.SAXException;
0137:
0138:        import com.ibm.wsdl.extensions.mime.MIMEConstants;
0139:
0140:        /**
0141:         * The WSIFOperation class for invoking WSDL operations using Apache AXIS.
0142:         *   
0143:         * @author Mark Whitlock <whitlock@apache.org>
0144:         * @author Ant Elder <ant.elder@uk.ibm.com>
0145:         */
0146:        public class WSIFOperation_ApacheAxis extends WSIFDefaultOperation {
0147:
0148:            private static final long serialVersionUID = 2L;
0149:
0150:            transient protected WSIFPort_ApacheAxis wsifPort;
0151:
0152:            transient protected Operation portTypeOperation;
0153:            transient protected BindingOperation bindingOperation;
0154:            transient protected SOAPOperation soapOperation;
0155:
0156:            transient protected List inputSOAPParts;
0157:            transient protected List inputUnwrappedSOAPParts;
0158:            transient protected List inputMIMEParts;
0159:            transient protected Part inputSOAPHeader;
0160:            transient protected Part inputSOAPHeaderFault;
0161:
0162:            protected List outputSOAPParts;
0163:            protected List outputUnwrappedSOAPParts;
0164:            protected List outputMIMEParts;
0165:            protected Part outputSOAPHeader;
0166:            protected Part outputSOAPHeaderFault;
0167:
0168:            transient protected String inputEncodingStyle;
0169:            transient protected String inputNamespace;
0170:            transient protected String soapActionURI;
0171:
0172:            transient protected HashMap responseMessageParameters;
0173:
0174:            // for async operation
0175:            transient protected boolean asyncOperation;
0176:            transient protected WSIFCorrelationId asyncRequestID;
0177:
0178:            // everything other than what is needed to process async response should be transient
0179:            protected WSIFResponseHandler responseHandler;
0180:            protected String outputEncodingStyle;
0181:            protected WSIFDynamicTypeMap typeMap;
0182:            protected String operationStyle;
0183:
0184:            /**
0185:             * Construct a new WSIFOperation
0186:             */
0187:            public WSIFOperation_ApacheAxis(WSIFPort_ApacheAxis wsifPort,
0188:                    Operation portTypeOperation, WSIFDynamicTypeMap typeMap)
0189:                    throws WSIFException {
0190:                Trc.entry(this , wsifPort, portTypeOperation, typeMap);
0191:
0192:                /* Note: if you change anything here make sure you consider
0193:                 * the impact to the constructor, copy and prepare methods
0194:                 * and to if any instance variables are transient 
0195:                 */
0196:
0197:                this .wsifPort = wsifPort;
0198:                this .portTypeOperation = portTypeOperation;
0199:                this .typeMap = typeMap;
0200:
0201:                this .bindingOperation = getBindingOperation(portTypeOperation);
0202:
0203:                this .inputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI;
0204:                this .outputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI;
0205:
0206:                if (Trc.ON) {
0207:                    Trc.exit(deep());
0208:                }
0209:            }
0210:
0211:            /**
0212:             * Create a new copy of this object. This is not a clone, since 
0213:             * it does not copy the referenced objects as well.
0214:             * The intention here is to copy anything that the prepare method
0215:             * has done so that WSIFOperation instances can be cached by the
0216:             * WSIFPort and safely reused with minimum overhead. 
0217:             * @deprecated why was this ever made public??? It should only
0218:             * ever be used by the WSIFPort!!!
0219:             */
0220:            public WSIFOperation_ApacheAxis copy() throws WSIFException {
0221:                Trc.entry(this );
0222:
0223:                /* Note: if you change anything here make sure you consider
0224:                 * the impact to the constructor, copy and prepare methods
0225:                 * and to if any instance variables are transient 
0226:                 */
0227:
0228:                WSIFOperation_ApacheAxis op = new WSIFOperation_ApacheAxis(
0229:                        wsifPort, portTypeOperation, typeMap);
0230:
0231:                op.inputSOAPParts = inputSOAPParts;
0232:                op.inputUnwrappedSOAPParts = inputUnwrappedSOAPParts;
0233:                op.inputMIMEParts = inputMIMEParts;
0234:                op.inputSOAPHeader = inputSOAPHeader;
0235:                op.inputSOAPHeaderFault = inputSOAPHeaderFault;
0236:
0237:                op.outputSOAPParts = outputSOAPParts;
0238:                op.outputUnwrappedSOAPParts = outputUnwrappedSOAPParts;
0239:                op.outputMIMEParts = outputMIMEParts;
0240:                op.outputSOAPHeader = outputSOAPHeader;
0241:                op.outputSOAPHeaderFault = outputSOAPHeaderFault;
0242:
0243:                op.soapOperation = soapOperation;
0244:
0245:                op.setSoapActionURI(getSoapActionURI());
0246:                op.setInputNamespace(getInputNamespace());
0247:                op.setInputEncodingStyle(getInputEncodingStyle());
0248:                op.setOutputEncodingStyle(getOutputEncodingStyle());
0249:                op.setAsyncOperation(isAsyncOperation());
0250:                op.setResponseHandler(getResponseHandler());
0251:                op.setInputJmsProperties(getInputJmsProperties());
0252:                op.setOutputJmsProperties(getOutputJmsProperties());
0253:                op.setInputJmsPropertyValues(getInputJmsPropertyValues());
0254:                op.setOperationStyle(getOperationStyle());
0255:
0256:                if (Trc.ON)
0257:                    Trc.exit(op.deep());
0258:                return op;
0259:            }
0260:
0261:            /**
0262:             * Initialises instance variables relating to the WSDL soap:operation element
0263:             * The soap:operation WSDL element has the form: 
0264:             *    <soap:operation soapAction="uri"? style="rpc|document"?>?
0265:             */
0266:            private void parseSoapOperation() throws WSIFException {
0267:
0268:                this .soapOperation = wsifPort
0269:                        .getSOAPOperation(bindingOperation);
0270:                this .soapActionURI = soapOperation.getSoapActionURI();
0271:                this .operationStyle = soapOperation.getStyle();
0272:
0273:                if (operationStyle == null || operationStyle.length() < 1) {
0274:                    operationStyle = wsifPort.getBindingStyle();
0275:                } else if (!WSIFAXISConstants.VALID_STYLES
0276:                        .contains(operationStyle)) {
0277:                    throw new WSIFException("unsupported style "
0278:                            + operationStyle + " for operation "
0279:                            + portTypeOperation.getName());
0280:                }
0281:                if (operationStyle == null || operationStyle.length() < 1) {
0282:                    operationStyle = WSIFAXISConstants.STYLE_DOCUMENT;
0283:                }
0284:            }
0285:
0286:            /**
0287:             * Initialises instance variables relating to the WSDL binding:input element
0288:             * The WSDL binding input has the form:
0289:             *      <input>
0290:             *          <soap:body parts="nmtokens"? use="literal|encoded"
0291:             *                     encodingStyle="uri-list"? namespace="uri"?>
0292:             *          <soap:header message="qname" part="nmtoken" use="literal|encoded"
0293:             *                       encodingStyle="uri-list"? namespace="uri"?>*
0294:             *              <soap:headerfault message="qname" 
0295:             *                                part="nmtoken" use="literal|encoded"
0296:             *                                encodingStyle="uri-list"? namespace="uri"?/>*
0297:             *          <soap:header>                                
0298:             *      </input>
0299:             */
0300:            private void parseBindingInput() throws WSIFException {
0301:                BindingInput bindinginput = bindingOperation.getBindingInput();
0302:                List inExtElems = bindinginput.getExtensibilityElements();
0303:
0304:                SOAPBody inSoapBody = (SOAPBody) wsifPort.getExtElem(
0305:                        bindinginput,
0306:                        javax.wsdl.extensions.soap.SOAPBody.class, inExtElems);
0307:                if (inSoapBody != null) {
0308:                    this .inputSOAPParts = parseSoapBody(inSoapBody, true);
0309:                }
0310:
0311:                MIMEMultipartRelated inMimeMultipart = (MIMEMultipartRelated) wsifPort
0312:                        .getExtElem(bindinginput, MIMEMultipartRelated.class,
0313:                                inExtElems);
0314:
0315:                if (inSoapBody != null && inMimeMultipart != null) {
0316:                    throw new WSIFException(
0317:                            "In a binding operation that contains a mime:multipartRelated, "
0318:                                    + "a soap:body was found that was not in a mime:part. "
0319:                                    + "OperationName=" + getName());
0320:                }
0321:                if (inSoapBody == null && inMimeMultipart == null) {
0322:                    throw new WSIFException(
0323:                            "binding operation input must contain either a soap:body "
0324:                                    + "or a mime:multipartRelated element. "
0325:                                    + "OperationName=" + getName());
0326:                }
0327:
0328:                if (inMimeMultipart != null) {
0329:                    parseMimeMultipart(inMimeMultipart, true);
0330:                }
0331:
0332:                MIMEMimeXml inMimeMimeXml = (MIMEMimeXml) wsifPort.getExtElem(
0333:                        bindinginput, MIMEMimeXml.class, inExtElems);
0334:                if (inMimeMimeXml != null)
0335:                    throw new WSIFException(
0336:                            "WSIF does not support mime:mimeXml. Operation="
0337:                                    + getName());
0338:
0339:                parseSOAPHeaderElement(bindinginput);
0340:
0341:                List inJmsProps = wsifPort.getExtElems(bindinginput,
0342:                        JMSProperty.class, bindinginput
0343:                                .getExtensibilityElements());
0344:                if (inJmsProps != null && inJmsProps.size() > 0) {
0345:                    if (wsifPort.isTransportJMS())
0346:                        setInputJmsProperties(inJmsProps);
0347:                    else
0348:                        throw new WSIFException(
0349:                                "jms:property found in non-jms binding");
0350:                }
0351:
0352:                List inJmsPropVals = wsifPort.getExtElems(bindinginput,
0353:                        JMSPropertyValue.class, bindinginput
0354:                                .getExtensibilityElements());
0355:                if (inJmsPropVals != null && inJmsPropVals.size() > 0) {
0356:                    if (wsifPort.isTransportJMS())
0357:                        addInputJmsPropertyValues(inJmsPropVals);
0358:                    else
0359:                        throw new WSIFException(
0360:                                "jms:propertyValue found in non-jms binding");
0361:                }
0362:            }
0363:
0364:            /**
0365:             * Initialises instance variables relating to the WSDL binding:output element
0366:             * The WSDL binding output has the form:
0367:             *      <output>
0368:             *          <soap:body parts="nmtokens"? use="literal|encoded"
0369:             *                     encodingStyle="uri-list"? namespace="uri"?>
0370:             *          <soap:header message="qname" part="nmtoken" use="literal|encoded"
0371:             *                       encodingStyle="uri-list"? namespace="uri"?>*
0372:             *              <soap:headerfault message="qname" 
0373:             *                                part="nmtoken" use="literal|encoded"
0374:             *                                encodingStyle="uri-list"? namespace="uri"?/>*
0375:             *          <soap:header>                                
0376:             *      </output>
0377:             */
0378:            private void parseBindingOutput() throws WSIFException {
0379:                BindingOutput bindingoutput = bindingOperation
0380:                        .getBindingOutput();
0381:                if (bindingoutput != null) {
0382:                    List outExtElems = bindingoutput.getExtensibilityElements();
0383:                    SOAPBody outSoapBody = (SOAPBody) wsifPort.getExtElem(
0384:                            bindingoutput,
0385:                            javax.wsdl.extensions.soap.SOAPBody.class,
0386:                            outExtElems);
0387:                    if (outSoapBody != null) {
0388:                        this .outputSOAPParts = parseSoapBody(outSoapBody, false);
0389:                    }
0390:
0391:                    MIMEMultipartRelated outMimeMultipart = (MIMEMultipartRelated) wsifPort
0392:                            .getExtElem(bindingoutput,
0393:                                    MIMEMultipartRelated.class, outExtElems);
0394:
0395:                    if (outSoapBody != null && outMimeMultipart != null) {
0396:                        throw new WSIFException(
0397:                                "In a binding operation that contains a mime:multipartRelated, "
0398:                                        + "a soap:body was found that was not in a mime:part. "
0399:                                        + "OperationName=" + getName());
0400:                    }
0401:                    if (outSoapBody == null && outMimeMultipart == null) {
0402:                        throw new WSIFException(
0403:                                "binding operation output must contain either a soap:body "
0404:                                        + "or a mime:multipartRelated element. "
0405:                                        + "OperationName=" + getName());
0406:                    }
0407:
0408:                    if (outMimeMultipart != null) {
0409:                        parseMimeMultipart(outMimeMultipart, false);
0410:                    }
0411:
0412:                    MIMEMimeXml outMimeMimeXml = (MIMEMimeXml) wsifPort
0413:                            .getExtElem(bindingoutput, MIMEMimeXml.class,
0414:                                    outExtElems);
0415:                    if (outMimeMimeXml != null) {
0416:                        throw new WSIFException(
0417:                                "WSIF does not support mime:mimeXml. Operation="
0418:                                        + getName());
0419:                    }
0420:
0421:                    parseSOAPHeaderElement(bindingoutput);
0422:
0423:                    for (Iterator iterator1 = bindingOperation
0424:                            .getBindingFaults().values().iterator(); iterator1
0425:                            .hasNext();) {
0426:                        BindingFault bindingfault = (BindingFault) iterator1
0427:                                .next();
0428:                        SOAPFault soapfault = (SOAPFault) wsifPort.getExtElem(
0429:                                bindingfault,
0430:                                javax.wsdl.extensions.soap.SOAPFault.class,
0431:                                bindingfault.getExtensibilityElements());
0432:                    }
0433:
0434:                    List outJmsProps = wsifPort.getExtElems(bindingoutput,
0435:                            JMSProperty.class, outExtElems);
0436:                    if (outJmsProps != null && outJmsProps.size() > 0) {
0437:                        if (wsifPort.isTransportJMS()) {
0438:                            setOutputJmsProperties(outJmsProps);
0439:                        } else {
0440:                            throw new WSIFException(
0441:                                    "jms:properties found in non-jms binding");
0442:                        }
0443:                    }
0444:                }
0445:            }
0446:
0447:            /**
0448:             * Parses any SOAP header elements in the binding input or output.
0449:             * The WSDL soap:header element has the form:
0450:             *    <soap:header message="qname" part="nmtoken" use="literal|encoded"
0451:             *                 encodingStyle="uri-list"? namespace="uri"?>*
0452:             *       <soap:headerfault message="qname" part="nmtoken" use="literal|encoded"
0453:             *                         encodingStyle="uri-list"? namespace="uri"?/>*
0454:             *    <soap:header>                                
0455:             */
0456:            private void parseSOAPHeaderElement(Object element)
0457:                    throws WSIFException {
0458:
0459:                List extensabilityElements;
0460:                if (element instanceof  BindingInput) {
0461:                    extensabilityElements = ((BindingInput) element)
0462:                            .getExtensibilityElements();
0463:                } else if (element instanceof  BindingOutput) {
0464:                    extensabilityElements = ((BindingOutput) element)
0465:                            .getExtensibilityElements();
0466:                } else {
0467:                    throw new WSIFException(
0468:                            "internal error, unexpected object: " + element);
0469:                }
0470:
0471:                Part soapHeaderPart = null;
0472:                Part soapHeaderFaultPart = null;
0473:
0474:                SOAPHeader soapHeader = (SOAPHeader) wsifPort.getExtElem(
0475:                        element, javax.wsdl.extensions.soap.SOAPHeader.class,
0476:                        extensabilityElements);
0477:                if (soapHeader != null) {
0478:                    QName messageName = soapHeader.getMessage();
0479:                    if (messageName == null) {
0480:                        throw new WSIFException(
0481:                                "no message attribute on soap:header: "
0482:                                        + soapHeader);
0483:                    }
0484:                    String messagePart = soapHeader.getPart();
0485:                    if (messagePart == null) {
0486:                        throw new WSIFException(
0487:                                "no part attribute on soap:header: "
0488:                                        + soapHeader);
0489:                    }
0490:                    soapHeaderPart = getPart(messageName, messagePart);
0491:                    if (soapHeaderPart == null) {
0492:                        throw new WSIFException(
0493:                                "non existent part specified on soap:header: "
0494:                                        + soapHeader);
0495:                    }
0496:
0497:                    SOAPHeaderFault soapHeaderFault = (SOAPHeaderFault) wsifPort
0498:                            .getExtElem(
0499:                                    soapHeader,
0500:                                    javax.wsdl.extensions.soap.SOAPHeaderFault.class,
0501:                                    extensabilityElements);
0502:                    if (soapHeaderFault != null) {
0503:                        messageName = soapHeader.getMessage();
0504:                        if (messageName == null) {
0505:                            throw new WSIFException(
0506:                                    "no message attribute on soap:header: "
0507:                                            + soapHeader);
0508:                        }
0509:                        messagePart = soapHeader.getPart();
0510:                        if (messagePart == null) {
0511:                            throw new WSIFException(
0512:                                    "no part attribute on soap:header: "
0513:                                            + soapHeader);
0514:                        }
0515:                        soapHeaderFaultPart = getPart(messageName, messagePart);
0516:                        if (soapHeaderFaultPart == null) {
0517:                            throw new WSIFException(
0518:                                    "non existent part specified on soap:header: "
0519:                                            + soapHeader);
0520:                        }
0521:                    }
0522:                }
0523:
0524:                if (element instanceof  BindingInput) {
0525:                    this .inputSOAPHeader = soapHeaderPart;
0526:                    this .inputSOAPHeaderFault = soapHeaderFaultPart;
0527:                } else {
0528:                    this .outputSOAPHeader = soapHeaderPart;
0529:                    this .outputSOAPHeaderFault = soapHeaderFaultPart;
0530:                }
0531:                //TODO now go and do something with them...
0532:            }
0533:
0534:            /**
0535:             * Validates the soap:body WSDL element.
0536:             * The soap:body WSDL element has the form:
0537:             *   <soap:body parts="nmtokens"? use="literal|encoded"
0538:             *              encodingStyle="uri-list"? namespace="uri"?>
0539:             * Returns an ArrayList of the WSDL parts 
0540:             */
0541:            private List parseSoapBody(SOAPBody soapbody, boolean isInput)
0542:                    throws WSIFException {
0543:                Trc.entry(this , soapbody, new Boolean(isInput));
0544:
0545:                // get input namespace
0546:                if (isInput) {
0547:                    String ns = soapbody.getNamespaceURI();
0548:                    if (ns != null) {
0549:                        setInputNamespace(soapbody.getNamespaceURI());
0550:                    }
0551:                }
0552:
0553:                // get use
0554:                String use = soapbody.getUse();
0555:                if (!WSIFAXISConstants.VALID_USES.contains(use)) {
0556:                    throw new WSIFException("unsupported use " + use + " in "
0557:                            + soapOperation);
0558:                }
0559:
0560:                // get encoding style
0561:                if (isInput) {
0562:                    List l = soapbody.getEncodingStyles();
0563:                    if (l != null && l.size() > 0) {
0564:                        setInputEncodingStyle((String) l.get(0));
0565:                    }
0566:                }
0567:
0568:                // get all the WSDL parts. If the soap:body parts= is defined
0569:                // only get those parts, otherwise get all parts in the WSDL message
0570:                javax.wsdl.Message m = null;
0571:                if (isInput) {
0572:                    Input in = portTypeOperation.getInput();
0573:                    if (in != null) {
0574:                        m = in.getMessage();
0575:                    }
0576:                } else {
0577:                    Output out = portTypeOperation.getOutput();
0578:                    if (out != null) {
0579:                        m = out.getMessage();
0580:                    }
0581:                }
0582:                ArrayList al = getParts(m, soapbody.getParts());
0583:
0584:                Trc.exit(al);
0585:                return al;
0586:            }
0587:
0588:            /**
0589:             * Gets the parts from a WSDL message.
0590:             * If the partNames list (from WSDL soap:body parts=) is 
0591:             * not null only the parts named in the partName list are
0592:             * returned, otherwise all parts are returned.
0593:             */
0594:            private ArrayList getParts(javax.wsdl.Message m, List partNames)
0595:                    throws WSIFException {
0596:                ArrayList al = new ArrayList();
0597:                List parts = null;
0598:                if (m != null) {
0599:                    parts = m.getOrderedParts(null);
0600:                }
0601:
0602:                if ((parts == null || parts.size() < 1)
0603:                        && (partNames != null && partNames.size() > 0)) {
0604:                    throw new WSIFException("part '" + partNames.get(0)
0605:                            + "' not defined in message " + m);
0606:                }
0607:
0608:                if (partNames == null) {
0609:                    if (parts != null) {
0610:                        al.addAll(parts);
0611:                    }
0612:                } else {
0613:                    for (Iterator i = partNames.iterator(); i.hasNext();) {
0614:                        String partName = (String) i.next();
0615:                        Part p = m.getPart(partName);
0616:                        if (p == null) {
0617:                            throw new WSIFException("Part '" + partName
0618:                                    + "' in soap:body parts not in message "
0619:                                    + m);
0620:                        }
0621:                        // as there can be multiple mime:content elements which
0622:                        // specify a coice of types (TODO: which wsif ignores for now)
0623:                        // we only want each mime part once
0624:                        if (!al.contains(p)) {
0625:                            al.add(p);
0626:                        }
0627:                    }
0628:                }
0629:                return al;
0630:            }
0631:
0632:            /**
0633:             * Parses the mime:multipartRelated WSDL element
0634:             * The mime:multipartRelated element has the form:
0635:             *   <mime:multipartRelated>
0636:             *      <mime:part> *
0637:             *         <-- mime element -->
0638:             *      </mime:part>
0639:             *   </mime:multipartRelated>
0640:             */
0641:            private void parseMimeMultipart(MIMEMultipartRelated mimeMultipart,
0642:                    boolean isInput) throws WSIFException {
0643:                Trc.entry(this , mimeMultipart);
0644:
0645:                ArrayList mimePartNames = new ArrayList();
0646:                SOAPBody soapBody = null;
0647:
0648:                Operation op = bindingOperation.getOperation();
0649:                Map mapInParts = op.getInput().getMessage().getParts();
0650:                Map mapOutParts = op.getOutput() == null ? new HashMap() : op
0651:                        .getOutput().getMessage().getParts();
0652:
0653:                List mimeParts = mimeMultipart.getMIMEParts();
0654:                Iterator mimePartIt = mimeParts.iterator();
0655:                while (mimePartIt.hasNext()) {
0656:                    Object nextMimePart = mimePartIt.next();
0657:                    if (nextMimePart instanceof  MIMEPart) {
0658:                        MIMEPart mimePart = (MIMEPart) nextMimePart;
0659:                        if (!MIMEConstants.NS_URI_MIME.equals(mimePart
0660:                                .getElementType().getNamespaceURI()))
0661:                            throw new WSIFException(
0662:                                    "A MIME part in binding operation "
0663:                                            + bindingOperation.getName()
0664:                                            + " did not have the correct namespace URI of "
0665:                                            + MIMEConstants.NS_URI_MIME + ".");
0666:
0667:                        boolean containsSoapBody = false;
0668:                        boolean containsMimeContent = false;
0669:                        List mimePartChildren = mimePart
0670:                                .getExtensibilityElements();
0671:                        Iterator mimePartChildrenIt = mimePartChildren
0672:                                .iterator();
0673:                        while (mimePartChildrenIt.hasNext()) {
0674:                            Object nextChild = mimePartChildrenIt.next();
0675:                            if (nextChild instanceof  MIMEContent) {
0676:                                MIMEContent mimeContent = (MIMEContent) nextChild;
0677:                                if (!MIMEConstants.NS_URI_MIME.equals(mimePart
0678:                                        .getElementType().getNamespaceURI()))
0679:                                    throw new WSIFException(
0680:                                            "A MIME part in binding operation "
0681:                                                    + bindingOperation
0682:                                                            .getName()
0683:                                                    + " did not have the correct namespace URI of "
0684:                                                    + MIMEConstants.NS_URI_MIME
0685:                                                    + ".");
0686:                                containsMimeContent = true;
0687:                                if (containsSoapBody)
0688:                                    throw new WSIFException(
0689:                                            "A mime:part that contains a mime:content also "
0690:                                                    + "contains a soap:body. Operation="
0691:                                                    + getName());
0692:
0693:                                String partName = mimeContent.getPart();
0694:                                if (partName == null || partName.length() == 0)
0695:                                    throw new WSIFException(
0696:                                            "No part name for a mime:content. Operation="
0697:                                                    + getName());
0698:
0699:                                if ((isInput && mapInParts.get(partName) == null)
0700:                                        || (!isInput && mapOutParts
0701:                                                .get(partName) == null))
0702:                                    throw new WSIFException(
0703:                                            "The part specified in a mime:content does "
0704:                                                    + "not exist in the operation. Operation="
0705:                                                    + getName() + " Part="
0706:                                                    + partName);
0707:
0708:                                mimePartNames.add(partName);
0709:
0710:                            } else if (nextChild instanceof  SOAPBody) {
0711:                                if (soapBody != null) {
0712:                                    throw new WSIFException(
0713:                                            "Multiple soap:body tags found in a "
0714:                                                    + "mime:multipartRelated. Operation="
0715:                                                    + getName());
0716:                                }
0717:                                soapBody = (SOAPBody) nextChild;
0718:
0719:                                containsSoapBody = true;
0720:                                if (containsMimeContent)
0721:                                    throw new WSIFException(
0722:                                            "A mime:part that contains a mime:content also "
0723:                                                    + "contains a soap:body. Operation="
0724:                                                    + getName());
0725:
0726:                            } else if (nextChild instanceof  MIMEMultipartRelated) {
0727:                                throw new WSIFException(
0728:                                        "WSIF does not support nesting mime:multipartRelated "
0729:                                                + "inside a mime:part. Operation="
0730:                                                + getName());
0731:                            } else if (nextChild instanceof  MIMEMimeXml) {
0732:                                throw new WSIFException(
0733:                                        "WSIF does not support mime:mimeXml. Operation="
0734:                                                + getName());
0735:                            }
0736:                        }
0737:                    }
0738:                }
0739:
0740:                // There is at most one soap:body so process it here.		
0741:                if (soapBody != null) {
0742:                    List soapBodyParts = soapBody.getParts();
0743:                    if (soapBodyParts == null && !mimePartNames.isEmpty()) {
0744:                        /* In the WSDL (containing attachments and non-attachment
0745:                         * parts), if there is a soap:body that does not have 
0746:                         * the parts attribute, which parts should the soap body
0747:                         * contain? The WSDL spec is not clear so this code 
0748:                         * fixes the soap body to contain only the non-attachment
0749:                         * parts, which is the kinder option. The alternative which 
0750:                         * is making the soap body contain all the parts (so duplicating
0751:                         * the attachments) is cruel since this is probably not 
0752:                         * what the backend is expecting.
0753:                         */
0754:                        Map soapParts;
0755:                        if (isInput)
0756:                            soapParts = mapInParts;
0757:                        else
0758:                            soapParts = mapOutParts;
0759:
0760:                        if (soapParts != null && !soapParts.isEmpty()) {
0761:                            ArrayList nonMimeParts = new ArrayList(Arrays
0762:                                    .asList(soapParts.keySet().toArray()));
0763:                            nonMimeParts.removeAll(Arrays.asList(soapParts
0764:                                    .keySet().toArray()));
0765:                            soapBody.setParts(nonMimeParts);
0766:                        }
0767:                    }
0768:
0769:                    List soapParts = parseSoapBody(soapBody, isInput);
0770:                    if (isInput)
0771:                        this .inputSOAPParts = soapParts;
0772:                    else
0773:                        this .outputSOAPParts = soapParts;
0774:                }
0775:
0776:                if (mimePartNames != null && !mimePartNames.isEmpty()) {
0777:                    javax.wsdl.Message m = null;
0778:                    if (isInput) {
0779:                        Input in = portTypeOperation.getInput();
0780:                        if (in != null) {
0781:                            m = in.getMessage();
0782:                        }
0783:                    } else {
0784:                        Output out = portTypeOperation.getOutput();
0785:                        if (out != null) {
0786:                            m = out.getMessage();
0787:                        }
0788:                    }
0789:                    ArrayList al = getParts(m, mimePartNames);
0790:                    if (isInput) {
0791:                        this .inputMIMEParts = al;
0792:                    } else {
0793:                        this .outputMIMEParts = al;
0794:                    }
0795:
0796:                }
0797:
0798:                Trc.exit();
0799:            }
0800:
0801:            /**
0802:             * For document style operations the input and/or output
0803:             * may be 'wrapped'. A wrapped operation has  a single top-
0804:             * level element wrapping the argument elements. For an input 
0805:             * message the top level wrapper element name must be the same
0806:             * as the operation name, the output wrapper element name must 
0807:             * be the name of the operation suffixed with "Response".
0808:             * WSIF clients may use either the wrapped or unwrapped parts.
0809:             */
0810:            private void unwrapSOAPParts() throws WSIFException {
0811:                if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)) {
0812:                    String operationName = getName();
0813:                    if (inputSOAPParts.size() == 1) {
0814:                        Part p = (Part) inputSOAPParts.get(0);
0815:                        QName elementName = p.getElementName();
0816:                        if (elementName != null
0817:                                && operationName.equals(elementName
0818:                                        .getLocalPart())) {
0819:                            this .inputUnwrappedSOAPParts = WSIFUtils
0820:                                    .unWrapPart(p, getDefinition());
0821:                        }
0822:                    }
0823:                    if (outputSOAPParts.size() == 1) {
0824:                        String s = operationName + "Response";
0825:                        Part p = (Part) outputSOAPParts.get(0);
0826:                        QName elementName = p.getElementName();
0827:                        if (elementName != null
0828:                                && s.equals(elementName.getLocalPart())) {
0829:                            this .outputUnwrappedSOAPParts = WSIFUtils
0830:                                    .unWrapPart(p, getDefinition());
0831:                        }
0832:                    }
0833:                }
0834:            }
0835:
0836:            /**
0837:             * Gets the WSDL binding:operation element for this operation
0838:             */
0839:            private BindingOperation getBindingOperation(Operation operation)
0840:                    throws WSIFException {
0841:                Binding binding = wsifPort.getPort().getBinding();
0842:                BindingOperation bindingOp = WSIFUtils.getBindingOperation(
0843:                        binding, operation);
0844:                if (bindingOp == null) {
0845:                    throw new WSIFException(
0846:                            "cannot find binding operation for port operation:"
0847:                                    + operation.getName());
0848:                }
0849:                return bindingOp;
0850:            }
0851:
0852:            /**
0853:             * Returns the Definition object for the WSDL file
0854:             * @return Definition   the WSDL4J Definition object
0855:             */
0856:            public Definition getDefinition() {
0857:                Trc.entry(this );
0858:                Definition d = wsifPort.getDefinition();
0859:                Trc.exit(d);
0860:                return d;
0861:            }
0862:
0863:            /**
0864:             * @deprecated use getWSIFPort
0865:             */
0866:            public WSIFPort_ApacheAxis getDynamicWSIFPort() {
0867:                Trc.entry(this );
0868:                Trc.exit(wsifPort);
0869:                return wsifPort;
0870:            }
0871:
0872:            public String getInputEncodingStyle() {
0873:                Trc.entry(this );
0874:                Trc.exit(inputEncodingStyle);
0875:                return inputEncodingStyle;
0876:            }
0877:
0878:            public String getInputNamespace() {
0879:                Trc.entry(this );
0880:                Trc.exit(inputNamespace);
0881:                return inputNamespace;
0882:            }
0883:
0884:            /**
0885:             * Gets the name of the portType wsdl:operation element
0886:             * being used by this WSIFOperation
0887:             * @return String   the operation name
0888:             */
0889:            public String getName() {
0890:                Trc.entry(this );
0891:                String s = portTypeOperation.getName();
0892:                Trc.exit(s);
0893:                return s;
0894:            }
0895:
0896:            /**
0897:             * @deprecated use getPortTypeOperation
0898:             */
0899:            public Operation getOperation() {
0900:                Trc.entry(this );
0901:                Operation o = getPortTypeOperation();
0902:                Trc.exit(o);
0903:                return o;
0904:            }
0905:
0906:            /**
0907:             * Returns the WSDL Part for the named part in a WSDL Message
0908:             */
0909:            private Part getPart(QName message, String partName) {
0910:                Part p = null;
0911:                Definition def = wsifPort.getDefinition();
0912:                javax.wsdl.Message m = def.getMessage(message);
0913:                if (m != null) {
0914:                    p = m.getPart(partName);
0915:                }
0916:                return p;
0917:            }
0918:
0919:            /**
0920:             * Gets the portType wsdl:operation element used by this WSIFOperation
0921:             * @return Operation   the WSDL4J portType Operation object
0922:             */
0923:            public Operation getPortTypeOperation() {
0924:                Trc.entry(this );
0925:                Trc.exit(portTypeOperation);
0926:                return portTypeOperation;
0927:            }
0928:
0929:            public String getOutputEncodingStyle() {
0930:                Trc.entry(this );
0931:                Trc.exit(outputEncodingStyle);
0932:                return outputEncodingStyle;
0933:            }
0934:
0935:            public String getSoapActionURI() {
0936:                Trc.entry(this );
0937:                Trc.exit(soapActionURI);
0938:                return soapActionURI;
0939:            }
0940:
0941:            public Transport getTransport() throws WSIFException {
0942:                Trc.entry(this );
0943:                Transport t = wsifPort.getTransport();
0944:                Trc.exit(t);
0945:                return t;
0946:            }
0947:
0948:            public WSIFCorrelationId getAsyncRequestID() {
0949:                Trc.entry(this );
0950:                Trc.exit(asyncRequestID);
0951:                return asyncRequestID;
0952:            }
0953:
0954:            private HashMap getResponseMessageParameters() {
0955:                return responseMessageParameters;
0956:            }
0957:
0958:            public WSIFPort getWSIFPort() {
0959:                Trc.entry(this );
0960:                Trc.exit(wsifPort);
0961:                return wsifPort;
0962:            }
0963:
0964:            /**
0965:             * Tests if the currently executing request is an asynchronous request.
0966:             * 
0967:             * @return   true if the current request is a asynchronous request,
0968:             *            otherwise false
0969:             */
0970:            public boolean isAsyncOperation() {
0971:                Trc.entry(this );
0972:                Trc.exit(asyncOperation);
0973:                return asyncOperation;
0974:            }
0975:
0976:            public void executeInputOnlyOperation(WSIFMessage inMsg)
0977:                    throws WSIFException {
0978:                Trc.entry(this , inMsg);
0979:
0980:                if (inMsg == null) {
0981:                    throw new IllegalArgumentException("input message is null");
0982:                }
0983:
0984:                setAsyncOperation(false);
0985:                invokeRequestResponseOperation(inMsg, null, null);
0986:                Trc.exit();
0987:                return;
0988:            }
0989:
0990:            public boolean executeRequestResponseOperation(WSIFMessage inMsg,
0991:                    WSIFMessage outMsg, WSIFMessage faultMsg)
0992:                    throws WSIFException {
0993:
0994:                Trc.entry(this , inMsg, outMsg, faultMsg);
0995:
0996:                if (inMsg == null) {
0997:                    throw new IllegalArgumentException("input message is null");
0998:                }
0999:                if (outMsg == null) {
1000:                    throw new IllegalArgumentException("output message is null");
1001:                }
1002:                if (faultMsg == null) {
1003:                    throw new IllegalArgumentException("fault message is null");
1004:                }
1005:
1006:                close();
1007:                setAsyncOperation(false);
1008:
1009:                boolean succ = invokeRequestResponseOperation(inMsg, outMsg,
1010:                        faultMsg);
1011:
1012:                Trc.exit(succ);
1013:                return succ;
1014:            }
1015:
1016:            /**
1017:             * Performs a request response operation asynchronously.
1018:             * 
1019:             * @param input   input message to send to the operation
1020:             * @return the correlation ID or the request. The correlation ID
1021:             *         is used to associate the request with the WSIFOperation.
1022:             * @exception WSIFException if something goes wrong.
1023:             * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
1024:             */
1025:            public WSIFCorrelationId executeRequestResponseAsync(
1026:                    WSIFMessage inMsg) throws WSIFException {
1027:                Trc.entry(this , inMsg);
1028:
1029:                if (inMsg == null) {
1030:                    throw new IllegalArgumentException("input message is null");
1031:                }
1032:
1033:                WSIFCorrelationId id = executeRequestResponseAsync(inMsg, null);
1034:                Trc.exit(id);
1035:                return id;
1036:
1037:            }
1038:
1039:            /**
1040:             * Performs a request response operation asynchronously.
1041:             * 
1042:             * @param input   input message to send to the operation
1043:             * @param handler   the response handler that will be notified 
1044:             *        when the asynchronous response becomes available.
1045:             * @return the correlation ID or the request. The correlation ID
1046:             *         is used to associate the request with the WSIFOperation.
1047:             * @exception WSIFException if something goes wrong.
1048:             * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage,WSIFResponseHandler)
1049:             */
1050:            public WSIFCorrelationId executeRequestResponseAsync(
1051:                    WSIFMessage inMsg, WSIFResponseHandler handler)
1052:                    throws WSIFException {
1053:                Trc.entry(this , inMsg, handler);
1054:
1055:                if (inMsg == null) {
1056:                    throw new IllegalArgumentException("input message is null");
1057:                }
1058:                close();
1059:
1060:                if (!wsifPort.supportsAsync()) {
1061:                    throw new WSIFException(
1062:                            "asynchronous operations not available");
1063:                }
1064:
1065:                setAsyncOperation(true);
1066:                setResponseHandler(handler);
1067:                WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
1068:                transport.setWsifOperation(this );
1069:                transport.setAsyncOperation("true");
1070:
1071:                invokeRequestResponseOperation(inMsg, null, null);
1072:
1073:                transport.setAsyncOperation("false");
1074:                WSIFCorrelationId id = getAsyncRequestID();
1075:                Trc.exit(id);
1076:                return id;
1077:
1078:            }
1079:
1080:            /**
1081:             * fireAsyncResponse is called by an AsyncListener when a response
1082:             * has been received for a previous executeRequestResponseAsync call.
1083:             * It passes the response to the executeAsyncResponse method of the
1084:             * associated WSIFResponseHandler.
1085:             * @see WSIFOperation#fireAsyncResponse(Object)
1086:             * @param response   an Object representing the response. The response
1087:             *            should be a JMS TextMessage containging the XML response.
1088:             */
1089:            public void fireAsyncResponse(Object response) throws WSIFException {
1090:                Trc.entry(this , response);
1091:
1092:                Object result = deserialiseResponseObject(response);
1093:
1094:                WSIFMessage outMsg = createOutputMessage();
1095:                WSIFMessage faultMsg = createFaultMessage();
1096:                buildResponseMessages(result, outMsg, faultMsg);
1097:
1098:                getResponseHandler().executeAsyncResponse(outMsg, faultMsg);
1099:
1100:                Trc.exit(outMsg);
1101:            }
1102:
1103:            /**
1104:             * Processes the response to an asynchronous request. 
1105:             * This is called for when the asynchronous operation was
1106:             * initiated without a WSIFResponseHandler, that is, by calling
1107:             * the executeRequestResponseAsync(WSIFMessage input) method.
1108:             * 
1109:             * @param response   an Object representing the response.
1110:             * @param output an empty message which will be filled in if
1111:             *        the operation invocation succeeds. If it does not
1112:             *        succeed, the contents of this message are undefined.
1113:             *        (This is a return value of this method.)
1114:             * @param fault an empty message which will be filled in if
1115:             *        the operation invocation fails. If it succeeds, the
1116:             *        contents of this message are undefined. (This is a
1117:             *        return value of this method.)
1118:             * 
1119:             * @return true or false indicating whether a fault message was
1120:             *         generated or not. The truth value indicates whether
1121:             *         the output or fault message has useful information.
1122:             *
1123:             */
1124:            public boolean processAsyncResponse(Object response,
1125:                    WSIFMessage output, WSIFMessage fault) throws WSIFException {
1126:                Trc.entry(this , response, output, fault);
1127:
1128:                Object result = deserialiseResponseObject(response);
1129:                boolean ok = buildResponseMessages(result, output, fault);
1130:
1131:                Trc.exit(ok);
1132:                return ok;
1133:            }
1134:
1135:            /**
1136:             * Deserialise and unmarshall the JMS response message.
1137:             * Used to process the response to an asynchronous request.
1138:             * This is copied, with minor changes, from the 2nd half
1139:             * of the Apache Axis Call class invoke method.
1140:             */
1141:            private Object deserialiseResponseObject(Object msg)
1142:                    throws WSIFException {
1143:                if (msg == null) {
1144:                    throw new WSIFException("null response to async send");
1145:                }
1146:                if (!(msg instanceof  TextMessage)) {
1147:                    throw new WSIFException(
1148:                            "response not a javax.jms.TextMessage");
1149:                }
1150:
1151:                try {
1152:                    TextMessage m = (TextMessage) msg;
1153:                    Message responseMessage = new Message(m.getText());
1154:                    responseMessage.setMessageType(Message.RESPONSE);
1155:
1156:                    Service service = new Service();
1157:                    MessageContext msgContext = new MessageContext(service
1158:                            .getEngine());
1159:                    msgContext.setResponseMessage(responseMessage);
1160:
1161:                    TypeMappingRegistry tmr = msgContext
1162:                            .getTypeMappingRegistry();
1163:                    org.apache.axis.encoding.TypeMapping tm = (org.apache.axis.encoding.TypeMapping) tmr
1164:                            .getTypeMapping(outputEncodingStyle);
1165:
1166:                    // register any default type mappings    	
1167:                    registerDefaultTypeMappings(tm, getContext());
1168:
1169:                    // register any mappings from WSIFService.mapType calls
1170:                    registerDynamicTypes(tm, typeMap, getContext());
1171:
1172:                    Message resMsg = msgContext.getResponseMessage();
1173:                    SOAPEnvelope resEnv = resMsg.getSOAPEnvelope();
1174:
1175:                    Object b = resEnv.getFirstBody();
1176:                    if (b instanceof  SOAPFaultElement) {
1177:                        return new AxisFault(b.toString());
1178:                    }
1179:
1180:                    RPCElement body = (RPCElement) b;
1181:
1182:                    Object result = null;
1183:                    HashMap outParams;
1184:                    Vector resArgs = body.getParams();
1185:
1186:                    if (resArgs != null && resArgs.size() > 0) {
1187:                        RPCParam param = (RPCParam) resArgs.get(0);
1188:                        result = param.getValue();
1189:
1190:                        if (resArgs.size() > 1) {
1191:                            outParams = new HashMap();
1192:                            for (int i = 1; i < resArgs.size(); i++) {
1193:                                RPCParam p = (RPCParam) resArgs.get(i);
1194:                                outParams.put(p.getName(), p.getValue());
1195:                            }
1196:                            setResponseMessageParameters(outParams);
1197:                        }
1198:                    }
1199:                    return result;
1200:                } catch (Exception ex) {
1201:                    Trc.exception(ex);
1202:                    throw new WSIFException(ex.getMessage());
1203:                }
1204:
1205:            }
1206:
1207:            /**
1208:             * Extracts the output or fault message parts from the axis response.
1209:             */
1210:            private boolean buildResponseMessages(Object resp,
1211:                    WSIFMessage outMsg, WSIFMessage faultMsg)
1212:                    throws WSIFException {
1213:
1214:                boolean respOK;
1215:
1216:                if (resp instanceof  AxisFault) {
1217:                    respOK = false;
1218:                    if (faultMsg != null) {
1219:                        AxisFault f = (AxisFault) resp;
1220:                        faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME);
1221:                        faultMsg.setObjectPart(WSIFConstants.SOAP_FAULT_OBJECT,
1222:                                f);
1223:                    }
1224:                } else {
1225:                    respOK = true;
1226:                    populateOutMsgReturnPart(resp, outMsg);
1227:                    populateOutMsgParts(outMsg);
1228:                }
1229:
1230:                return respOK;
1231:            }
1232:
1233:            /**
1234:             * Populate the outMessage with the response return value.
1235:             */
1236:            private void populateOutMsgReturnPart(Object resp,
1237:                    WSIFMessage outMsg) throws WSIFException {
1238:                if (outMsg != null) {
1239:
1240:                    // style=wrapped uses the unwrapped parts  
1241:                    List soapParts;
1242:                    if (WSIFAXISConstants.AXIS_STYLE_WRAPPED
1243:                            .equals(operationStyle)) {
1244:                        soapParts = outputUnwrappedSOAPParts;
1245:                    } else {
1246:                        soapParts = outputSOAPParts;
1247:                    }
1248:
1249:                    Part returnPart = null;
1250:                    if (soapParts.size() > 0) {
1251:                        returnPart = (Part) soapParts.get(0);
1252:                        setSOAPMessagePart(outMsg, returnPart.getName(), resp);
1253:                    } else if (outputMIMEParts.size() > 0) {
1254:                        returnPart = (Part) outputMIMEParts.get(0);
1255:                        setMIMEMessagePart(outMsg, returnPart.getName(), resp,
1256:                                resp == null ? null : resp.getClass());
1257:                    }
1258:                }
1259:            }
1260:
1261:            /**
1262:             * Populates the outMessage with the expected parts.
1263:             * (this only does the out parameters not the return part)
1264:             */
1265:            private void populateOutMsgParts(WSIFMessage outMsg)
1266:                    throws WSIFException {
1267:                if (outMsg != null) {
1268:                    HashMap respParms = getResponseMessageParameters();
1269:
1270:                    if (respParms != null) {
1271:                        // style=wrapped uses the unwrapped parts  
1272:                        List soapParts;
1273:                        if (WSIFAXISConstants.AXIS_STYLE_WRAPPED
1274:                                .equals(operationStyle)) {
1275:                            soapParts = outputUnwrappedSOAPParts;
1276:                        } else {
1277:                            soapParts = outputSOAPParts;
1278:                        }
1279:                        for (int i = 1; i < soapParts.size(); i++) {
1280:                            Part p = (Part) soapParts.get(i);
1281:                            String name = p.getName();
1282:                            Object value = respParms.get(name);
1283:                            setSOAPMessagePart(outMsg, name, value);
1284:                        }
1285:                        int startMIMEindex;
1286:                        if (soapParts.size() > 0) {
1287:                            startMIMEindex = 0;
1288:                        } else {
1289:                            startMIMEindex = 1;
1290:                        }
1291:                        for (int i = startMIMEindex; i < outputMIMEParts.size(); i++) {
1292:                            Part p = (Part) outputMIMEParts.get(i);
1293:                            String name = p.getName();
1294:                            Object value = respParms.get(name);
1295:                            setMIMEMessagePart(outMsg, name, value,
1296:                                    value == null ? null : value.getClass());
1297:                        }
1298:                    }
1299:                }
1300:
1301:            }
1302:
1303:            private static void setSOAPMessagePart(WSIFMessage msg,
1304:                    String name, Object value) throws WSIFException {
1305:                Trc.entry(null, msg, name, value);
1306:
1307:                //TODO type checking against the WSDL part type
1308:                msg.setObjectPart(name, value);
1309:
1310:                Trc.exit();
1311:            }
1312:
1313:            private static void setMIMEMessagePart(WSIFMessage msg,
1314:                    String name, Object value, Class type) throws WSIFException {
1315:                Trc.entry(null, msg, name, value, type);
1316:
1317:                MIMEHelper.setMIMEMessagePart(msg, name, value, type);
1318:
1319:                Trc.exit();
1320:            }
1321:
1322:            /**
1323:             * Gets the type of a Part, if the Part doesn't have a type,
1324:             * then gets the Element name as WSIF treats this as the same thing.
1325:             * (for now? probably the wrong thing to be doing)
1326:             */
1327:            private QName getPartType(Part p) {
1328:                QName type = p.getTypeName();
1329:                if (type == null) {
1330:                    type = p.getElementName();
1331:                }
1332:                return type;
1333:            }
1334:
1335:            public boolean invokeRequestResponseOperation(WSIFMessage inMsg,
1336:                    WSIFMessage outMsg, WSIFMessage faultMsg)
1337:                    throws WSIFException {
1338:                Trc.entry(this , inMsg, outMsg, faultMsg);
1339:                boolean workedOK = false;
1340:
1341:                Call call = wsifPort.getCall();
1342:
1343:                // Make sure we're making a fresh start.
1344:                call.removeAllParameters();
1345:                call.clearHeaders();
1346:
1347:                call.setTargetEndpointAddress(wsifPort.getEndPoint());
1348:
1349:                if (inputSOAPParts == null) {
1350:                    prepare(call);
1351:                }
1352:                call.setSOAPActionURI(getSoapActionURI());
1353:
1354:                if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)
1355:                        && isInputMessageUnWrapped(inMsg)) {
1356:                    operationStyle = WSIFAXISConstants.AXIS_STYLE_WRAPPED;
1357:                }
1358:
1359:                // TODO: what about wrapped messaging? Not supported yet
1360:                if (isMessaging(inMsg)) {
1361:                    operationStyle = WSIFAXISConstants.AXIS_STYLE_MESSAGE;
1362:                }
1363:
1364:                Transport axistransport = getTransport();
1365:                WSIFJMSDestination dest = null;
1366:                if (axistransport != null) {
1367:                    call.setTransport(axistransport);
1368:                    if (axistransport instanceof  WSIFJmsTransport) {
1369:                        WSIFJmsTransport jmst = (WSIFJmsTransport) axistransport;
1370:                        dest = jmst.getDestination();
1371:                        dest.setAsyncMode(isAsyncOperation());
1372:                        jmst.setSyncTimeout(null); // reset timeouts to defaults
1373:                        jmst.setAsyncTimeout(null);
1374:                    }
1375:                }
1376:
1377:                if (dest != null && inJmsPropVals != null
1378:                        && !inJmsPropVals.isEmpty()) {
1379:                    checkForTimeoutProperties(inJmsPropVals, dest);
1380:                    dest.setProperties(inJmsPropVals);
1381:                }
1382:
1383:                //TODO: jms:property parts
1384:
1385:                setDestinationContext(dest);
1386:                setCallContext(call);
1387:
1388:                if (WSIFAXISConstants.AXIS_STYLE_MESSAGE.equals(operationStyle)) {
1389:                    workedOK = invokeAXISMessaging(call, inMsg, outMsg,
1390:                            faultMsg);
1391:                } else if (WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) {
1392:                    workedOK = invokeAXISRPCStyle(call, inMsg, outMsg,
1393:                            faultMsg, dest);
1394:                } else {
1395:                    workedOK = invokeAXISDocStyle(call, inMsg, outMsg, faultMsg);
1396:                }
1397:
1398:                setResponseContext(call);
1399:
1400:                Trc.exit(workedOK);
1401:                return workedOK;
1402:            }
1403:
1404:            /**
1405:             * This attempts to determine if the WSIF input message parts are 
1406:             * for a wrapped or unwrapped style operation. Tricky to tell for
1407:             * sure so this just checks parts with the correct names exist in
1408:             * the message.  
1409:             * @return true if the input message has a multiple parts matching 
1410:             *          the unwrapped SOAP parts, otherwise false
1411:             */
1412:            private boolean isInputMessageUnWrapped(WSIFMessage msg) {
1413:                boolean unWrapped = true;
1414:
1415:                Object style = null;
1416:                try {
1417:                    WSIFMessage context = getContext();
1418:                    style = context
1419:                            .getObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE);
1420:                } catch (WSIFException e) {
1421:                    Trc.ignoredException(e);
1422:                }
1423:                if (WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED.equals(style)) {
1424:                    unWrapped = true;
1425:                } else if (WSIFConstants.CONTEXT_OPERATION_STYLE_UNWRAPPED
1426:                        .equals(style)) {
1427:                    unWrapped = false;
1428:                } else if (inputUnwrappedSOAPParts != null
1429:                        && inputUnwrappedSOAPParts.size() > 0) {
1430:                    unWrapped = true;
1431:                    for (Iterator i = inputUnwrappedSOAPParts.iterator(); i
1432:                            .hasNext()
1433:                            && unWrapped;) {
1434:                        Part p = (Part) i.next();
1435:                        try {
1436:                            msg.getObjectPart(p.getName());
1437:                        } catch (WSIFException e) {
1438:                            unWrapped = false;
1439:                        }
1440:                    }
1441:                } else {
1442:                    unWrapped = false;
1443:                }
1444:
1445:                return unWrapped;
1446:            }
1447:
1448:            /**
1449:             * This attempts to determine if the WSIF input message parts are 
1450:             * for a 'message' style document operation.
1451:             * Note: messaging cannot use unwrapped parts
1452:             * @return true if all the WSIF input message part types for the
1453:             *          soap parts have a type of DOM Element, otherwise false
1454:             */
1455:            private boolean isMessaging(WSIFMessage msg) {
1456:                boolean allDOMElements = true;
1457:                boolean anyDOMElements = false;
1458:
1459:                if (msg != null) {
1460:                    for (Iterator i = inputSOAPParts.iterator(); i.hasNext();) {
1461:                        Part p = (Part) i.next();
1462:                        try {
1463:                            Object o = msg.getObjectPart(p.getName());
1464:                            if (o instanceof  Element) {
1465:                                anyDOMElements = true;
1466:                            } else {
1467:                                allDOMElements = false;
1468:                            }
1469:                        } catch (WSIFException e) {
1470:                            Trc.ignoredException(e);
1471:                        }
1472:                    }
1473:                }
1474:                return anyDOMElements && allDOMElements;
1475:            }
1476:
1477:            /**
1478:             * This does the AXIS Call invoke for document style operations
1479:             * when the WSIF input message parts are NOT DOM elements 
1480:             */
1481:            private boolean invokeAXISRPCStyle(Call call, WSIFMessage inMsg,
1482:                    WSIFMessage outMsg, WSIFMessage faultMsg,
1483:                    WSIFJMSDestination dest) throws WSIFException {
1484:
1485:                call.setOperationName(new QName(getInputNamespace(),
1486:                        portTypeOperation.getName()));
1487:
1488:                setCallParameterNames(call);
1489:
1490:                Object[] inputValues = getInputMessageValues(inMsg, dest);
1491:
1492:                Object response = null;
1493:                boolean respOK = true;
1494:                try {
1495:                    String name = portTypeOperation.getName();
1496:                    Trc.event(this , "Invoking operation ", name,
1497:                            " input namespace ", getInputNamespace(),
1498:                            " parameters ", inputValues, " call object ", call);
1499:
1500:                    response = call.invoke(getInputNamespace(), name,
1501:                            inputValues);
1502:
1503:                } catch (AxisFault e) {
1504:                    Trc.exception(e);
1505:                    response = e;
1506:                    respOK = false;
1507:                }
1508:
1509:                Trc.event(this , "Returned from operation, response ", response);
1510:
1511:                // setJMSOutPropsInContext( dest ); TODO doesn't work yet
1512:
1513:                if (!isAsyncOperation()
1514:                        && (outputSOAPParts.size() > 0 || outputMIMEParts
1515:                                .size() > 0)) {
1516:                    Map callParams = call.getOutputParams();
1517:                    if (callParams != null) {
1518:                        HashMap outParams = new HashMap();
1519:                        QName qn;
1520:                        for (Iterator i = callParams.keySet().iterator(); i
1521:                                .hasNext();) {
1522:                            qn = (QName) i.next();
1523:                            outParams
1524:                                    .put(qn.getLocalPart(), callParams.get(qn));
1525:                        }
1526:                        setResponseMessageParameters(outParams);
1527:                    }
1528:                    respOK = buildResponseMessages(response, outMsg, faultMsg);
1529:                }
1530:
1531:                return respOK;
1532:            }
1533:
1534:            /**
1535:             * This tells AXIS the name and type of the input, return, and output parameters. 
1536:             */
1537:            private void setCallParameterNames(Call call) throws WSIFException {
1538:
1539:                String inputNamespace = getInputNamespace();
1540:                String outputNamespace = "";
1541:
1542:                List soapParts;
1543:                // style=wrapped uses the unwrapped parts  
1544:                if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1545:                    soapParts = inputUnwrappedSOAPParts;
1546:                } else {
1547:                    soapParts = inputSOAPParts;
1548:                }
1549:
1550:                /* If there are no attachments take the part ordering from the 
1551:                 * soap:body. If there are attachments then the soap:body will 
1552:                 * not include the attachments, so take the part ordering from 
1553:                 * the ordering of the parts in the original message.
1554:                 */
1555:                if (inputMIMEParts.isEmpty()) {
1556:                    // setup the input SOAP parts
1557:                    for (int i = 0; i < soapParts.size(); i++) {
1558:                        Part p = (Part) soapParts.get(i);
1559:                        String partName = p.getName();
1560:                        if (!inJmsProps.containsKey(partName)) {
1561:                            if (WSIFAXISConstants.STYLE_DOCUMENT
1562:                                    .equals(operationStyle)) {
1563:                                QName qn = p.getElementName();
1564:                                if (qn != null) {
1565:                                    partName = qn.getLocalPart();
1566:                                }
1567:                            }
1568:                            QName name = new QName(inputNamespace, partName);
1569:                            QName type = getPartType(p);
1570:                            call.addParameter(name, type, ParameterMode.IN);
1571:                        }
1572:                    }
1573:                } else {
1574:                    // This order should include both the attachments and 
1575:                    // the non-attachments.
1576:                    List order = portTypeOperation.getInput().getMessage()
1577:                            .getOrderedParts(null);
1578:                    Iterator it = order.iterator();
1579:                    while (it.hasNext()) {
1580:                        Part p = (Part) it.next();
1581:
1582:                        // Only add the part if it hasn't been excluded by the 
1583:                        // soap:body parts="?"
1584:                        if (inputMIMEParts.contains(p) || soapParts.contains(p)) {
1585:                            QName name = new QName(inputNamespace, p.getName());
1586:                            QName type = getPartType(p);
1587:                            call.addParameter(name, type, ParameterMode.IN);
1588:                        }
1589:                    }
1590:                }
1591:
1592:                // style=wrapped uses the unwrapped parts  
1593:                if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
1594:                    soapParts = outputUnwrappedSOAPParts;
1595:                } else {
1596:                    soapParts = outputSOAPParts;
1597:                }
1598:
1599:                // setup the return part
1600:                Part returnPart = null;
1601:                if (soapParts.size() > 0) {
1602:                    returnPart = (Part) soapParts.get(0);
1603:                } else if (outputMIMEParts.size() > 0) {
1604:                    returnPart = (Part) outputMIMEParts.get(0);
1605:                }
1606:                if (returnPart == null) {
1607:                    call
1608:                            .setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
1609:                } else {
1610:                    QName type = getPartType(returnPart);
1611:                    call.setReturnType(type);
1612:                }
1613:
1614:                // setup output SOAP parts
1615:                // from 1 to skip the return part
1616:                for (int i = 1; i < soapParts.size(); i++) {
1617:                    Part p = (Part) soapParts.get(i);
1618:                    QName name = new QName(outputNamespace, p.getName());
1619:                    QName type = getPartType(p);
1620:                    call.addParameter(name, type, ParameterMode.OUT);
1621:                }
1622:
1623:                // setup the output MIME parts
1624:                // if no soap parts dont add 1st as its the return part
1625:                int startMIMEIndex = (soapParts.size() > 0) ? 0 : 1;
1626:                for (int i = startMIMEIndex; i < outputMIMEParts.size(); i++) {
1627:                    Part p = (Part) outputMIMEParts.get(i);
1628:                    QName name = new QName(outputNamespace, p.getName());
1629:                    QName type = getPartType(p);
1630:                    call.addParameter(name, type, ParameterMode.OUT);
1631:                }
1632:            }
1633:
1634:            /**
1635:             * This does the AXIS Call invoke for document style operations
1636:             * when the WSIF input message parts are NOT DOM elements 
1637:             */
1638:            private boolean invokeAXISDocStyle(Call call, WSIFMessage inMsg,
1639:                    WSIFMessage outMsg, WSIFMessage faultMsg)
1640:                    throws WSIFException {
1641:
1642:                boolean respOK = false;
1643:
1644:                // setup the call object
1645:                call.setOperationName(new QName(getInputNamespace(),
1646:                        portTypeOperation.getName()));
1647:                call.setScopedProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);
1648:                call.setScopedProperty(AxisEngine.PROP_DOMULTIREFS,
1649:                        Boolean.FALSE);
1650:                call.setOperationStyle(operationStyle);
1651:                setCallParameterNames(call);
1652:
1653:                Object[] inputValues = getInputMessageValues(inMsg, null);
1654:
1655:                // invoke the AXIS call
1656:                Trc.event(this , "Invoking AXIS call", call, inputValues);
1657:                Object response;
1658:                try {
1659:                    response = call.invoke(inputValues);
1660:                    respOK = true;
1661:                } catch (RemoteException ex) {
1662:                    Trc.exception(ex);
1663:                    throw new WSIFException("exception on AXIS invoke: "
1664:                            + ex.getLocalizedMessage(), ex);
1665:                }
1666:                Trc.event(this , "Returned from AXIS invoke, response: ",
1667:                        response);
1668:
1669:                // process the AXIS response
1670:                if (!isAsyncOperation()) {
1671:
1672:                    // style=wrapped uses the unwrapped parts  
1673:                    List soapParts;
1674:                    if (WSIFAXISConstants.AXIS_STYLE_WRAPPED
1675:                            .equals(operationStyle)) {
1676:                        soapParts = outputUnwrappedSOAPParts;
1677:                    } else {
1678:                        soapParts = outputSOAPParts;
1679:                    }
1680:
1681:                    if (soapParts.size() > 0 || outputMIMEParts.size() > 0) {
1682:                        Map callParams = call.getOutputParams();
1683:                        if (callParams != null) {
1684:                            HashMap outParams = new HashMap();
1685:                            QName qn;
1686:                            for (Iterator i = callParams.keySet().iterator(); i
1687:                                    .hasNext();) {
1688:                                qn = (QName) i.next();
1689:                                outParams.put(qn.getLocalPart(), callParams
1690:                                        .get(qn));
1691:                            }
1692:                            setResponseMessageParameters(outParams);
1693:                        }
1694:                        respOK = buildResponseMessages(response, outMsg,
1695:                                faultMsg);
1696:                    }
1697:                }
1698:
1699:                return respOK;
1700:            }
1701:
1702:            /**
1703:             * This does the AXIS Call invoke for 'messaging' - when all the 
1704:             * WSIF input message parts are DOM elements 
1705:             */
1706:            private boolean invokeAXISMessaging(Call call, WSIFMessage inMsg,
1707:                    WSIFMessage outMsg, WSIFMessage faultMsg)
1708:                    throws WSIFException {
1709:
1710:                boolean workedOK = false;
1711:
1712:                List attachments = addAttachments(inMsg, call);
1713:
1714:                Object[] inputValues = getInputMessageValues(inMsg, null);
1715:                ArrayList soapBodies = new ArrayList();
1716:                for (int i = 0; i < inputValues.length; i++) {
1717:                    if (inputValues[i] instanceof  Element) {
1718:                        Element el = (Element) inputValues[i];
1719:
1720:                        if ((attachments.size() > 0) && (i == 0)) {
1721:                            fixAttachmentPartsCID(el, attachments);
1722:                        }
1723:
1724:                        soapBodies.add(new SOAPBodyElement(el));
1725:                    } else {
1726:                        throw new WSIFException("unexpected input type: "
1727:                                + inputValues[i]);
1728:                    }
1729:                }
1730:
1731:                Object[] axisInputs = soapBodies.toArray();
1732:
1733:                Trc.event(this , "Invoking AXIS call", call, axisInputs);
1734:                Object axisResponse; // the response should be a Vector of RPCElement objects
1735:                try {
1736:                    axisResponse = call.invoke(axisInputs);
1737:                } catch (RemoteException ex) {
1738:                    throw new WSIFException("exception on AXIS invoke: "
1739:                            + ex.getLocalizedMessage(), ex);
1740:                }
1741:                Trc.event(this , "Returned from AXIS invoke, response: ",
1742:                        axisResponse);
1743:
1744:                setOutputMessageValues(axisResponse, outMsg);
1745:
1746:                workedOK = true;
1747:                return workedOK;
1748:            }
1749:
1750:            /**
1751:             * Fix the CID in the href of an attachment.
1752:             * When sending an attachent with messaging two parts will
1753:             * be in the WSIF input message, a DOM Element for the SOAP body contents,
1754:             * and a DataHandler for the attachment. The contents Element must
1755:             * include a href part for the attachment. This method will find
1756:             * that href part and correct the CID value for the new AttachmentPart.
1757:             * SOAPBody example with a href part named 'file':
1758:             *	<ns1:bounceImage4 xmlns:ns1="http://mime/">
1759:             *	   <ns1:shouldBounce xsi:type="xsd:boolean">true</ns1:shouldBounce>
1760:             *	   <ns1:file href="cid:413B07CE410E48EB9D89DC0A4DDD715D"/>
1761:             *  </ns1:bounceImage4>
1762:             */
1763:            private void fixAttachmentPartsCID(Element body, List attachments)
1764:                    throws WSIFException {
1765:
1766:                // find all the attachment Elements in the body
1767:                ArrayList al = new ArrayList();
1768:                getAttachmentElements(al, body);
1769:
1770:                /* this isn't so nice: the AttachmentPart has no name
1771:                 * so we have to assume the the List is in the same
1772:                 * order as the attachment Elements in the body. 
1773:                 */
1774:                if (al.size() != attachments.size()) {
1775:                    throw new WSIFException("unexpected number of attachments,"
1776:                            + attachments.size() + " AttachmentParts, "
1777:                            + al.size() + " attachment href elements");
1778:                }
1779:
1780:                // fiddle the cid: for each attachment
1781:                for (int i = 0; i < attachments.size(); i++) {
1782:                    AttachmentPart attachment = (AttachmentPart) attachments
1783:                            .get(i);
1784:                    Element attachmentElement = (Element) al.get(i);
1785:                    attachmentElement.setAttribute("href", "cid:"
1786:                            + attachment.getContentId());
1787:                }
1788:            }
1789:
1790:            /**
1791:             * Gets all attachment Elements within an Element
1792:             * This recurses through the DOM tree structure adding any
1793:             * attachment Element's to the ArrayList. 
1794:             * An attachment Element is one which has an href attribute
1795:             * which has a value starting with the String "cid:"
1796:             */
1797:            private static void getAttachmentElements(ArrayList al, Element el) {
1798:                NodeList childNodes = el.getChildNodes();
1799:                for (int j = 0; j < childNodes.getLength(); j++) {
1800:                    Node n = childNodes.item(j);
1801:                    if (n instanceof  Element) {
1802:                        Element childElement = (Element) n;
1803:                        String s = childElement.getAttribute("href");
1804:                        if (s != null && s.toLowerCase().startsWith("cid:")) {
1805:                            al.add(childElement);
1806:                        } else {
1807:                            getAttachmentElements(al, childElement);
1808:                        }
1809:                    }
1810:                }
1811:            }
1812:
1813:            /**
1814:             * Prepares this operation.
1815:             * The intention of this is to setup everything that can be reused
1816:             * by the WSIFOperation. Clients must not reuse a WSIFOperation 
1817:             * but a WSIFPort may cache WSIFOperation instances and use the
1818:             * WSIFOperation copy method to return copies to clients
1819:             */
1820:            private void prepare(Call call) throws WSIFException {
1821:                Trc.entry(this , call);
1822:
1823:                /* Note: if you change anything here make sure you consider
1824:                 * the impact to the constructor, copy and prepare methods
1825:                 * and to if any instance variables are transient 
1826:                 */
1827:
1828:                /* Create the ArrayList identify each part and populate
1829:                 * by calling the appropriate parseXxxx method.
1830:                 */
1831:                this .inputSOAPParts = new ArrayList();
1832:                this .inputMIMEParts = new ArrayList();
1833:                this .outputSOAPParts = new ArrayList();
1834:                this .outputMIMEParts = new ArrayList();
1835:
1836:                parseSoapOperation();
1837:                parseBindingInput();
1838:                parseBindingOutput();
1839:                unwrapSOAPParts();
1840:
1841:                // register any jms:address propertyValues
1842:                addInputJmsPropertyValues(wsifPort.getJmsAddressPropVals());
1843:
1844:                if (!WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) {
1845:                    call.setEncodingStyle(null);
1846:                    inputEncodingStyle = "";
1847:                    outputEncodingStyle = "";
1848:                }
1849:
1850:                if (inputNamespace == null || inputNamespace.length() < 1) {
1851:                    this .inputNamespace = getTargetNamespaceURI();
1852:                }
1853:
1854:                TypeMapping tm = call.getTypeMapping();
1855:                WSIFMessage context = getContext();
1856:
1857:                // register any default type mappings    	
1858:                registerDefaultTypeMappings(tm, context);
1859:
1860:                // register any mappings from WSIFService.mapType calls
1861:                registerDynamicTypes(tm, typeMap, context);
1862:
1863:                registerMIMETypes(inputMIMEParts, call);
1864:
1865:                registerMIMETypes(outputMIMEParts, call);
1866:
1867:                if (Trc.ON) {
1868:                    Trc.exit(deep());
1869:                }
1870:            }
1871:
1872:            /**
1873:             * Register any default mappings from the context with the AXIS Call
1874:             */
1875:            static void registerDefaultTypeMappings(
1876:                    TypeMapping callTypeMappings, WSIFMessage context)
1877:                    throws WSIFException {
1878:                Object value = null;
1879:                try {
1880:                    value = context
1881:                            .getObjectPart(WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS);
1882:                } catch (WSIFException e) {
1883:                    Trc.ignoredException(e);
1884:                }
1885:                if (value == null) {
1886:                    return;
1887:                }
1888:                if (!(value instanceof  List)) {
1889:                    throw new WSIFException(
1890:                            "context part '"
1891:                                    + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS
1892:                                    + "' value is not an instance of java.util.List: "
1893:                                    + value);
1894:                }
1895:                List defaultMappings = (List) value;
1896:                for (Iterator i = defaultMappings.iterator(); i.hasNext();) {
1897:                    Object o = i.next();
1898:                    if (!(o instanceof  TypeSerializerInfo)) {
1899:                        throw new WSIFException(
1900:                                "context part '"
1901:                                        + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS
1902:                                        + "' value List contains an entry that is not an instance "
1903:                                        + "of org.apache.wsif.util.TypeSerializer: "
1904:                                        + value);
1905:                    }
1906:                    TypeSerializerInfo ts = (TypeSerializerInfo) o;
1907:
1908:                    Class javaType = ts.getJavaType();
1909:                    QName elementType = ts.getElementType();
1910:                    Object tmp = ts.getSerializer();
1911:                    SerializerFactory sf = null;
1912:                    if (tmp instanceof  SerializerFactory) {
1913:                        sf = (SerializerFactory) tmp;
1914:                    }
1915:                    tmp = ts.getDeserializer();
1916:                    DeserializerFactory df = null;
1917:                    if (tmp instanceof  DeserializerFactory) {
1918:                        df = (DeserializerFactory) tmp;
1919:                    }
1920:
1921:                    if (javaType != null && elementType != null
1922:                            && (sf != null || df != null)) {
1923:                        callTypeMappings
1924:                                .register(javaType, elementType, sf, df);
1925:                    } else {
1926:                        Trc.event(null,
1927:                                "ignoring default TypeSerializer invalid for AXIS:"
1928:                                        + ts);
1929:                    }
1930:                }
1931:            }
1932:
1933:            /**
1934:             * Register any mappings from WSIFService.mapType calls with the AXIS Call
1935:             */
1936:            static void registerDynamicTypes(TypeMapping tm,
1937:                    WSIFDynamicTypeMap typeMap, WSIFMessage context)
1938:                    throws WSIFException {
1939:
1940:                Class objClass;
1941:                String namespaceURI, localPart;
1942:                WSIFDynamicTypeMapping wsifdynamictypemapping;
1943:                for (Iterator iterator = typeMap.iterator(); iterator.hasNext();) {
1944:                    wsifdynamictypemapping = (WSIFDynamicTypeMapping) iterator
1945:                            .next();
1946:                    objClass = wsifdynamictypemapping.getJavaType();
1947:                    QName xmlType = wsifdynamictypemapping.getXmlType();
1948:
1949:                    SerializerFactory sf = null;
1950:                    DeserializerFactory df = null;
1951:
1952:                    // the context may override the default (de)serializer for a type
1953:                    TypeSerializerInfo contextTypeSerializer = findContextTypeSerialzer(
1954:                            context, objClass, xmlType);
1955:                    if (contextTypeSerializer != null) {
1956:                        objClass = contextTypeSerializer.getJavaType();
1957:                        xmlType = contextTypeSerializer.getElementType();
1958:                        sf = (SerializerFactory) contextTypeSerializer
1959:                                .getSerializer();
1960:                        df = (DeserializerFactory) contextTypeSerializer
1961:                                .getDeserializer();
1962:                    }
1963:
1964:                    if (sf == null
1965:                            && tm.getSerializer(objClass, xmlType) == null) {
1966:                        if (objClass.isArray()) {
1967:                            sf = new ArraySerializerFactory();
1968:                        } else if (SimpleType.class.isAssignableFrom(objClass)) {
1969:                            sf = new SimpleSerializerFactory(objClass, xmlType);
1970:                        } else {
1971:                            sf = new BeanSerializerFactory(objClass, xmlType);
1972:                        }
1973:                    }
1974:
1975:                    if (df == null
1976:                            && tm.getDeserializer(objClass, xmlType) == null) {
1977:                        if (objClass.isArray()) {
1978:                            df = new ArrayDeserializerFactory();
1979:                        } else if (SimpleType.class.isAssignableFrom(objClass)) {
1980:                            df = new SimpleDeserializerFactory(objClass,
1981:                                    xmlType);
1982:                        } else {
1983:                            df = new BeanDeserializerFactory(objClass, xmlType);
1984:                        }
1985:                    }
1986:
1987:                    namespaceURI = wsifdynamictypemapping.getXmlType()
1988:                            .getNamespaceURI();
1989:
1990:                    // Filter out XSD and SOAP-ENC types from those we explicitly map.      
1991:                    // Axis already knows how to deal with these; using the BeanSerializer 
1992:                    // would be wrong anyway as they represent simple types and not beans. 
1993:                    if (!isDefaultSOAPNamespace(namespaceURI)) {
1994:
1995:                        localPart = wsifdynamictypemapping.getXmlType()
1996:                                .getLocalPart();
1997:                        QName qn = new QName(namespaceURI, localPart);
1998:
1999:                        if (sf != null || df != null) {
2000:                            tm.register(objClass, qn, sf, df);
2001:                        }
2002:                    }
2003:                }
2004:            }
2005:
2006:            private static TypeSerializerInfo findContextTypeSerialzer(
2007:                    WSIFMessage context, Class clazz, QName xmlType)
2008:                    throws WSIFException {
2009:
2010:                Object value = null;
2011:                try {
2012:                    value = context
2013:                            .getObjectPart(WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS);
2014:                } catch (WSIFException e) {
2015:                    Trc.ignoredException(e);
2016:                }
2017:                if (value == null) {
2018:                    return null;
2019:                }
2020:                if (!(value instanceof  List)) {
2021:                    throw new WSIFException("context part '"
2022:                            + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS
2023:                            + "' value is not an instance of java.util.List: "
2024:                            + value);
2025:                }
2026:
2027:                List typeSerializers = (List) value;
2028:                for (Iterator i = typeSerializers.iterator(); i.hasNext();) {
2029:                    Object o = i.next();
2030:                    if (!(o instanceof  TypeSerializerInfo)) {
2031:                        throw new WSIFException(
2032:                                "context part '"
2033:                                        + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS
2034:                                        + "' value List contains an entry that is not an instance "
2035:                                        + "of org.apache.wsif.util.TypeSerializer: "
2036:                                        + value);
2037:                    }
2038:                    TypeSerializerInfo tm = (TypeSerializerInfo) o;
2039:
2040:                    Class javaType = tm.getJavaType();
2041:                    QName elementType = tm.getElementType();
2042:                    Object serializer = tm.getSerializer();
2043:                    Object deserializer = tm.getDeserializer();
2044:
2045:                    if ((javaType != null)
2046:                            || (javaType.isAssignableFrom(clazz))
2047:                            && ((elementType != null) || (elementType
2048:                                    .equals(xmlType)))) {
2049:                        if (serializer == null
2050:                                || serializer instanceof  SerializerFactory
2051:                                && deserializer == null
2052:                                || deserializer instanceof  DeserializerFactory
2053:                                && serializer != null || deserializer != null) {
2054:                            return tm;
2055:                        }
2056:                    }
2057:                }
2058:
2059:                return null; // couldn't find a TypeSerializer
2060:            }
2061:
2062:            private static boolean isDefaultSOAPNamespace(String ns) {
2063:                boolean soapNamespace = false;
2064:                if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns)
2065:                        || WSIFConstants.NS_URI_2000_SCHEMA_XSD.equals(ns)
2066:                        || WSIFConstants.NS_URI_2001_SCHEMA_XSD.equals(ns)
2067:                        || WSIFConstants.NS_URI_SOAP_ENC.equals(ns)) {
2068:                    soapNamespace = true;
2069:                }
2070:                return soapNamespace;
2071:            }
2072:
2073:            /**
2074:             * Gets an array of all the input WSIFMessage values 
2075:             */
2076:            private Object[] getInputMessageValues(WSIFMessage inMsg,
2077:                    WSIFJMSDestination dest) throws WSIFException {
2078:                ArrayList axisInputs = new ArrayList();
2079:                List soapParts;
2080:
2081:                // style=wrapped uses the unwrapped parts  
2082:                if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
2083:                    soapParts = inputUnwrappedSOAPParts;
2084:                } else {
2085:                    soapParts = inputSOAPParts;
2086:                }
2087:
2088:                /* If there are no attachments take the part ordering from the 
2089:                 * soap:body. If there are attachments then the soap:body will 
2090:                 * not include the attachments, so take the part ordering from 
2091:                 * the ordering of the parts in the original message.
2092:                 */
2093:                if (inputMIMEParts.isEmpty()) {
2094:                    for (int i = 0; i < soapParts.size(); i++) {
2095:                        Part p = (Part) soapParts.get(i);
2096:                        String partName = p.getName();
2097:                        Object value;
2098:                        try {
2099:                            value = inMsg.getObjectPart(partName);
2100:                        } catch (WSIFException e) {
2101:                            Trc.ignoredException(e);
2102:                            value = null; // missing part values default to null
2103:                        }
2104:                        if (inJmsProps.containsKey(partName) && dest != null) {
2105:                            String name = (String) (inJmsProps.get(partName));
2106:                            if (!timeoutProperty(dest, name, value)) {
2107:                                dest.setProperty(name, value);
2108:                            }
2109:                        } else {
2110:                            axisInputs.add(value);
2111:                        }
2112:
2113:                    }
2114:                } else {
2115:                    // This order includes both the attachments and 
2116:                    // the non-attachments.
2117:                    List order = portTypeOperation.getInput().getMessage()
2118:                            .getOrderedParts(null);
2119:                    Iterator it = order.iterator();
2120:                    while (it.hasNext()) {
2121:                        Part p = (Part) it.next();
2122:                        String partName = p.getName();
2123:
2124:                        // Only add the part if it hasn't been excluded by the 
2125:                        // soap:body parts="?"
2126:                        if (soapParts.contains(p)
2127:                                || (inputMIMEParts.contains(p) && !WSIFAXISConstants.AXIS_STYLE_MESSAGE
2128:                                        .equals(operationStyle))) {
2129:                            Object value;
2130:                            try {
2131:                                value = inMsg.getObjectPart(partName);
2132:                            } catch (WSIFException e) {
2133:                                Trc.ignoredException(e);
2134:                                value = null; // missing part values default to null
2135:                            }
2136:                            if (inJmsProps.containsKey(partName)
2137:                                    && dest != null) {
2138:                                String name = (String) (inJmsProps
2139:                                        .get(partName));
2140:                                if (!timeoutProperty(dest, name, value)) {
2141:                                    dest.setProperty(name, value);
2142:                                }
2143:                            } else {
2144:                                axisInputs.add(value);
2145:                            }
2146:                        }
2147:                    }
2148:                }
2149:                return axisInputs.toArray();
2150:            }
2151:
2152:            /**
2153:             * adds all the attachments to the AXIS call
2154:             * returns a List of all the AttachmentPart so that href parts
2155:             * can be made for each attachment later if required.
2156:             */
2157:            private List addAttachments(WSIFMessage inMsg, Call call)
2158:                    throws WSIFException {
2159:                ArrayList attachments = new ArrayList();
2160:                for (int i = 0; i < inputMIMEParts.size(); i++) {
2161:                    Part p = (Part) inputMIMEParts.get(i);
2162:                    try {
2163:                        String partName = p.getName();
2164:                        Object value = inMsg.getObjectPart(partName);
2165:                        AttachmentPart ap = MIMEHelper
2166:                                .getAttachementPart(value);
2167:                        call.addAttachmentPart(ap);
2168:                        attachments.add(ap);
2169:                    } catch (WSIFException e) {
2170:                        throw new WSIFException("attachment part '"
2171:                                + p.getName() + "' not in input WSIFMessage");
2172:                    }
2173:                }
2174:                return attachments;
2175:            }
2176:
2177:            /**
2178:             * This extracts the values from the AXIS response when using messaging
2179:             * The response could have DOM elements for the SOAP parts, or 
2180:             * AttachmentParts for the attachments.
2181:             * TODO: only tested with a single response part - either SOAP or MIME
2182:             *       need to test with multiple outputs as probably doesn't work yet.
2183:             */
2184:            private void setOutputMessageValues(Object axisResponse,
2185:                    WSIFMessage outMsg) throws WSIFException {
2186:                if (!(axisResponse instanceof  Vector)) {
2187:                    throw new WSIFException(
2188:                            "expect response type of java.util.Vector of SOAPBodyElement, found: "
2189:                                    + axisResponse);
2190:                }
2191:
2192:                Vector v = (Vector) axisResponse;
2193:                for (int i = 0; i < v.size(); i++) {
2194:                    if (v.elementAt(i) instanceof  RPCElement) {
2195:                        RPCElement rpcEl = (RPCElement) v.elementAt(i);
2196:
2197:                        QName qn = new QName(rpcEl.getNamespaceURI(), rpcEl
2198:                                .getName());
2199:                        Part p = findPart(outputSOAPParts, qn);
2200:                        if (p != null) {
2201:                            setSOAPPart(outMsg, rpcEl, p);
2202:                        } else {
2203:                            setAttachmentPart(outMsg, rpcEl);
2204:                        }
2205:
2206:                    } else {
2207:                        throw new WSIFException(
2208:                                "expecting response type org.w3c.dom.Element, found: "
2209:                                        + v.elementAt(i));
2210:                    }
2211:                }
2212:            }
2213:
2214:            /**
2215:             * Extract a SOAP part from response and put in the output WSIFMessage 
2216:             */
2217:            private void setSOAPPart(WSIFMessage outMsg, RPCElement rpcEl,
2218:                    Part p) throws WSIFException {
2219:                Object responseValue = null;
2220:                try {
2221:                    responseValue = rpcEl.getAsDOM();
2222:                } catch (Exception e) {
2223:                    throw new WSIFException(
2224:                            "exception getting soap body as DOM: "
2225:                                    + e.getLocalizedMessage(), e);
2226:                }
2227:                String partName = p.getName();
2228:                outMsg.setObjectPart(partName, responseValue);
2229:            }
2230:
2231:            /**
2232:             * Extract an attachment DataHandler from response and put in the output WSIFMessage 
2233:             */
2234:            private void setAttachmentPart(WSIFMessage outMsg, RPCElement rpcEl)
2235:                    throws WSIFException {
2236:
2237:                Vector params;
2238:                try {
2239:                    params = rpcEl.getParams();
2240:                } catch (SAXException e) {
2241:                    throw new WSIFException(
2242:                            "SAXException getting response MIME part: "
2243:                                    + e.getLocalizedMessage(), e);
2244:                }
2245:
2246:                if (params == null || params.size() < 1) {
2247:                    throw new WSIFException(
2248:                            "no attachments found in response element: "
2249:                                    + rpcEl);
2250:                }
2251:
2252:                //TODO: will there ever be more than 1?
2253:                RPCParam rpcParam = (RPCParam) params.get(0);
2254:
2255:                QName qn = rpcParam.getQName();
2256:                Part p = findPart(outputMIMEParts, qn);
2257:                if (p != null) {
2258:                    Object responseValue = rpcParam.getValue();
2259:                    if (responseValue instanceof  AttachmentPart) {
2260:                        try {
2261:                            Object attachment = ((AttachmentPart) responseValue)
2262:                                    .getDataHandler();
2263:                            String partName = p.getName();
2264:                            outMsg.setObjectPart(partName, attachment);
2265:                        } catch (SOAPException e) {
2266:                            throw new WSIFException(
2267:                                    "SOAPException getting DataHandler from AttachmentPart: "
2268:                                            + e.getLocalizedMessage(), e);
2269:                        }
2270:                    } else {
2271:                        throw new WSIFException(
2272:                                "expecting response AttachmentPart but found: "
2273:                                        + responseValue);
2274:                    }
2275:                } else {
2276:                    throw new WSIFException(
2277:                            "cannot find a WSDL output MIME part for response element: "
2278:                                    + rpcEl);
2279:                }
2280:
2281:            }
2282:
2283:            /**
2284:             * Searches the list of parts for one that matches the name.
2285:             * The list of parts will be the outputSOAPParts or outputMIMEParts
2286:             */
2287:            private Part findPart(List partsList, QName partName) {
2288:                Part part = null;
2289:                for (Iterator i = partsList.iterator(); i.hasNext()
2290:                        && part == null;) {
2291:                    Part p = (Part) i.next();
2292:                    if (partName.equals(p.getElementName())) {
2293:                        part = p;
2294:                    } else if (partName.getLocalPart().equals(p.getName())) {
2295:                        part = p;
2296:                    }
2297:                }
2298:                return part;
2299:            }
2300:
2301:            /**
2302:             * Automatically register MIME types as DataHandler.
2303:             */
2304:            private void registerMIMETypes(List mimeParts, Call call) {
2305:                if (mimeParts != null && !mimeParts.isEmpty()) {
2306:                    for (Iterator i = mimeParts.iterator(); i.hasNext();) {
2307:                        Part p = (Part) i.next();
2308:                        QName type = getPartType(p);
2309:                        MIMEHelper.registerAttachmentType(call, type);
2310:                    }
2311:                }
2312:            }
2313:
2314:            /**
2315:             * Sets the response handler that will be used to
2316:             * process the response to an asynchronous request.
2317:             * @param responseHandler   the responseHandler to use 
2318:             */
2319:            private void setResponseHandler(WSIFResponseHandler responseHandler) {
2320:                this .responseHandler = responseHandler;
2321:            }
2322:
2323:            /**
2324:             * Gets the response handler that will be used to
2325:             * process the response to a asynchronous request.
2326:             * @return the current response handler.
2327:             * package visable as its used by the transport
2328:             */
2329:            WSIFResponseHandler getResponseHandler() {
2330:                return responseHandler;
2331:            }
2332:
2333:            /**
2334:             * @deprecated should anyone be calling this?
2335:             */
2336:            public void setDefinition(Definition definition1) {
2337:                Trc.entry(this , definition1);
2338:                throw new RuntimeException("method nolonger supported");
2339:            }
2340:
2341:            public void setDynamicWSIFPort(
2342:                    WSIFPort_ApacheAxis wsifport_apacheaxis) {
2343:                Trc.entry(this , wsifport_apacheaxis);
2344:                wsifPort = wsifport_apacheaxis;
2345:                Trc.exit();
2346:            }
2347:
2348:            public void setInputEncodingStyle(String s) {
2349:                Trc.entry(this , s);
2350:                inputEncodingStyle = s;
2351:                Trc.exit();
2352:            }
2353:
2354:            public void setInputNamespace(String s) {
2355:                Trc.entry(this , s);
2356:                inputNamespace = s;
2357:                Trc.exit();
2358:            }
2359:
2360:            public void setOperation(Operation operation1) {
2361:                Trc.entry(this , operation1);
2362:                portTypeOperation = operation1;
2363:                Trc.exit();
2364:            }
2365:
2366:            public void setOutputEncodingStyle(String s) {
2367:                Trc.entry(this , s);
2368:                outputEncodingStyle = s;
2369:                Trc.exit();
2370:            }
2371:
2372:            public void setSoapActionURI(String s) {
2373:                Trc.entry(this , s);
2374:                soapActionURI = s;
2375:                Trc.exit();
2376:            }
2377:
2378:            private void setResponseMessageParameters(HashMap hm) {
2379:                this .responseMessageParameters = hm;
2380:            }
2381:
2382:            /**
2383:             * Sets if the currently executing request is an asynchronous request.
2384:             * 
2385:             * @param b   true if the current request is a asynchronous request,
2386:             *            otherwise false
2387:             */
2388:            private void setAsyncOperation(boolean b) {
2389:                asyncOperation = b;
2390:            }
2391:
2392:            /**
2393:             * Gets the target namespace URI of this WSIFOperation 
2394:             * 
2395:             * @return the target namespace URI
2396:             */
2397:            public String getTargetNamespaceURI() {
2398:                Trc.entry(this );
2399:                Definition d = getDefinition();
2400:                String s = (d == null) ? "" : d.getTargetNamespace();
2401:                Trc.exit(s);
2402:                return s;
2403:            }
2404:
2405:            /**
2406:             * This sets up the output JMS property values in the context
2407:             */
2408:            private void setJMSOutPropsInContext(WSIFJMSDestination dest)
2409:                    throws WSIFException {
2410:                if (dest == null) {
2411:                    return;
2412:                }
2413:                HashMap props = dest.getProperties();
2414:                if (props != null) {
2415:                    getContext().setParts(props);
2416:                }
2417:            }
2418:
2419:            /**
2420:             * This sets up any context JMS property values in the Destination
2421:             */
2422:            private void setDestinationContext(WSIFJMSDestination dest)
2423:                    throws WSIFException {
2424:                if (dest == null) {
2425:                    return;
2426:                }
2427:                WSIFMessage context = getContext();
2428:                HashMap jmsProps = new HashMap();
2429:                for (Iterator i = context.getPartNames(); i.hasNext();) {
2430:                    String partName = (String) i.next();
2431:                    try {
2432:                        Object value = context.getObjectPart(partName);
2433:                        if (!timeoutProperty(dest, partName, value)) {
2434:                            if (partName
2435:                                    .startsWith(WSIFConstants.CONTEXT_JMS_PREFIX)) {
2436:                                String propertyName = partName
2437:                                        .substring(WSIFConstants.CONTEXT_JMS_PREFIX
2438:                                                .length());
2439:                                jmsProps.put(propertyName, value);
2440:                            }
2441:                        }
2442:                    } catch (WSIFException ex) {
2443:                        Trc.ignoredException(ex);
2444:                    }
2445:                }
2446:                if (jmsProps.size() > 0) {
2447:                    dest.setProperties(jmsProps);
2448:                }
2449:            }
2450:
2451:            /**
2452:             * This sets up the context headers in the axis 
2453:             * Call object prior to invoke method being issued.
2454:             */
2455:            private void setCallContext(Call call) throws WSIFException {
2456:                Object o;
2457:                String name;
2458:                WSIFMessage context = getContext();
2459:
2460:                name = WSIFConstants.CONTEXT_HTTP_USER;
2461:                try {
2462:                    o = context.getObjectPart(name);
2463:                    if (o instanceof  String) {
2464:                        addHTTPHeader(call, name, (String) o);
2465:                    }
2466:                } catch (WSIFException ex) {
2467:                    Trc.ignoredException(ex);
2468:                }
2469:
2470:                name = WSIFConstants.CONTEXT_HTTP_PSWD;
2471:                try {
2472:                    o = context.getObjectPart(name);
2473:                    if (o instanceof  String) {
2474:                        addHTTPHeader(call, name, (String) o);
2475:                    }
2476:                } catch (WSIFException ex) {
2477:                    Trc.ignoredException(ex);
2478:                }
2479:
2480:                try {
2481:                    name = WSIFConstants.CONTEXT_REQUEST_SOAP_HEADERS;
2482:                    o = context.getObjectPart(name);
2483:                    if (o instanceof  List) {
2484:                        addSOAPHeader(call, name, (List) o);
2485:                    }
2486:                } catch (WSIFException ex) {
2487:                    Trc.ignoredException(ex);
2488:                }
2489:            }
2490:
2491:            /**
2492:             * This sets up any context from the response message
2493:             */
2494:            private void setResponseContext(Call call) throws WSIFException {
2495:                org.apache.axis.Message m = call.getResponseMessage();
2496:                if (m != null) {
2497:                    javax.xml.soap.SOAPEnvelope env;
2498:                    try {
2499:                        env = m.getSOAPEnvelope();
2500:                    } catch (AxisFault e) {
2501:                        throw new WSIFException(
2502:                                "AxisFault getting response SOAP envelope", e);
2503:                    }
2504:                    if (env != null) {
2505:                        javax.xml.soap.SOAPHeader soapHeader;
2506:                        try {
2507:                            soapHeader = env.getHeader();
2508:                        } catch (SOAPException e) {
2509:                            throw new WSIFException(
2510:                                    "SOAPException getting response headers from SOAP envelope",
2511:                                    e);
2512:                        }
2513:                        addContextResponseSOAPHeaders(soapHeader);
2514:                    }
2515:                }
2516:            }
2517:
2518:            /**
2519:             * Sets any SOAP headers from the context message.
2520:             */
2521:            private void addSOAPHeader(Call call, String name, List soapHeaders) {
2522:                for (Iterator i = soapHeaders.iterator(); i.hasNext();) {
2523:                    Object o = i.next();
2524:                    if (o instanceof  Element) {
2525:                        call.addHeader(new SOAPHeaderElement((Element) o));
2526:                    }
2527:                }
2528:            }
2529:
2530:            /**
2531:             * This adds any SOAP headers in the response to the context 
2532:             */
2533:            private void addContextResponseSOAPHeaders(
2534:                    javax.xml.soap.SOAPHeader soapHeader) throws WSIFException {
2535:
2536:                if (soapHeader != null) {
2537:                    ArrayList headers = new ArrayList();
2538:                    for (Iterator i = soapHeader.getChildElements(); i
2539:                            .hasNext();) {
2540:                        Object o = i.next();
2541:                        if (o instanceof  SOAPHeaderElement) {
2542:                            SOAPHeaderElement she = (SOAPHeaderElement) o;
2543:                            try {
2544:                                headers.add(she.getAsDOM());
2545:                            } catch (Exception e) {
2546:                                throw new WSIFException(
2547:                                        "exception getting response SOAP header",
2548:                                        e);
2549:                            }
2550:                        } else {
2551:                            Trc.event("unexpected response SOAP header type: ",
2552:                                    o);
2553:                        }
2554:                    }
2555:                    if (headers.size() > 0) {
2556:                        WSIFMessage context = getContext();
2557:                        context.setObjectPart(
2558:                                WSIFConstants.CONTEXT_RESPONSE_SOAP_HEADERS,
2559:                                headers);
2560:                        setContext(context);
2561:                    }
2562:                }
2563:            }
2564:
2565:            /**
2566:             * Sets the HTTP header value in the message context.
2567:             * How these are used depends on the underlying transport, 
2568:             * eg. org.apache.axis.transport.http.HTTPSender
2569:             * will use the 'user.id' and 'user.password' headers
2570:             * for HTTP basic authentication..  
2571:             */
2572:            private void addHTTPHeader(Call call, String name, String value) {
2573:                if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
2574:                    call.setProperty(Call.USERNAME_PROPERTY, value);
2575:                } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
2576:                    call.setProperty(Call.PASSWORD_PROPERTY, value);
2577:                }
2578:            }
2579:
2580:            /**
2581:             * This checks if any of the JMS propertyValues are for the
2582:             * sync or async timeout values. If so it set the appropriate
2583:             * value on the JMS transport and removes the property from 
2584:             * the JMS propertyValues list.
2585:             */
2586:            private void checkForTimeoutProperties(HashMap inJmsPropVals,
2587:                    WSIFJMSDestination dest) throws WSIFException {
2588:                for (Iterator i = inJmsPropVals.keySet().iterator(); i
2589:                        .hasNext();) {
2590:                    String name = (String) i.next();
2591:                    Object value = inJmsPropVals.get(name);
2592:                    if (timeoutProperty(dest, name, value)) {
2593:                        i.remove();
2594:                    }
2595:                }
2596:            }
2597:
2598:            private boolean timeoutProperty(WSIFJMSDestination dest,
2599:                    String propertyName, Object value) throws WSIFException {
2600:                boolean isTimeoutProperty = false;
2601:                try {
2602:                    if (WSIFConstants.WSIF_PROP_SYNC_TIMEOUT
2603:                            .equals(propertyName)) {
2604:                        isTimeoutProperty = true;
2605:                        Long syncTimeout = new Long(value.toString());
2606:                        WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
2607:                        transport.setSyncTimeout(syncTimeout);
2608:                        Trc.event(this , "overridding syncTimeout to "
2609:                                + syncTimeout);
2610:                    } else if (WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT
2611:                            .equals(propertyName)) {
2612:                        isTimeoutProperty = true;
2613:                        Long asyncTimeout = new Long(value.toString());
2614:                        WSIFJmsTransport transport = (WSIFJmsTransport) getTransport();
2615:                        transport.setAsyncTimeout(asyncTimeout);
2616:                        Trc.event(this , "overridding asyncTimeout to "
2617:                                + asyncTimeout);
2618:                    }
2619:                } catch (NumberFormatException ex) {
2620:                    Trc.ignoredException(ex);
2621:                }
2622:                return isTimeoutProperty;
2623:            }
2624:
2625:            /**
2626:             * Returns true if primitive is the equivalent primitive class of clazz.
2627:             * Why doesn't java provide this function?
2628:             */
2629:            private static boolean isPrimitiveOf(Class clazz, Class primitive) {
2630:                if ((primitive.equals(boolean.class) && Boolean.class
2631:                        .isAssignableFrom(clazz))
2632:                        || (primitive.equals(char.class) && Character.class
2633:                                .isAssignableFrom(clazz))
2634:                        || (primitive.equals(byte.class) && Byte.class
2635:                                .isAssignableFrom(clazz))
2636:                        || (primitive.equals(short.class) && Short.class
2637:                                .isAssignableFrom(clazz))
2638:                        || (primitive.equals(int.class) && Integer.class
2639:                                .isAssignableFrom(clazz))
2640:                        || (primitive.equals(long.class) && Long.class
2641:                                .isAssignableFrom(clazz))
2642:                        || (primitive.equals(float.class) && Float.class
2643:                                .isAssignableFrom(clazz))
2644:                        || (primitive.equals(double.class) && Double.class
2645:                                .isAssignableFrom(clazz)))
2646:                    return true;
2647:                else
2648:                    return false;
2649:            }
2650:
2651:            // package visable as it's used by WSIFJmsTransport
2652:            void setAsyncRequestID(WSIFCorrelationId asyncRequestID) {
2653:                Trc.entry(this , asyncRequestID);
2654:                this .asyncRequestID = asyncRequestID;
2655:                Trc.exit();
2656:            }
2657:
2658:            /**
2659:             * @deprecated use getOperationStyle
2660:             */
2661:            public String getStyle() {
2662:                return operationStyle;
2663:            }
2664:
2665:            /**
2666:             * Returns the operation style.
2667:             * @return String
2668:             */
2669:            public String getOperationStyle() {
2670:                return operationStyle;
2671:            }
2672:
2673:            /**
2674:             * @deprecated use setOperationStyle
2675:             */
2676:            public void setStyle(String style) {
2677:                this .operationStyle = style;
2678:            }
2679:
2680:            /**
2681:             * @deprecated should anyone be doing this?
2682:             */
2683:            public void setOperationStyle(String style) {
2684:                this .operationStyle = style;
2685:            }
2686:
2687:            public String deep() {
2688:                StringBuffer buff = new StringBuffer();
2689:                try {
2690:                    buff.append(super .toString()).append(":\n");
2691:                    buff.append("wsifPort:").append(wsifPort);
2692:                    buff.append(" portTypeOperation:").append(
2693:                            Trc.brief(portTypeOperation));
2694:                    buff.append(" bindingOperation:").append(bindingOperation);
2695:                    buff.append(" soapOperation:").append(soapOperation);
2696:                    buff.append(" operationStyle:").append(operationStyle);
2697:                    buff.append(" inputSOAPParts:").append(inputSOAPParts);
2698:                    buff.append(" inputUnwrappedSOAPParts:").append(
2699:                            inputUnwrappedSOAPParts);
2700:                    buff.append(" inputMIMEParts:").append(inputMIMEParts);
2701:                    buff.append(" inputSOAPHeader:").append(inputSOAPHeader);
2702:                    buff.append(" inputSOAPHeaderFault:").append(
2703:                            inputSOAPHeaderFault);
2704:                    buff.append(" outputSOAPParts:").append(outputSOAPParts);
2705:                    buff.append(" outputUnwrappedSOAPParts:").append(
2706:                            outputUnwrappedSOAPParts);
2707:                    buff.append(" outputMIMEParts:").append(outputMIMEParts);
2708:                    buff.append(" outputSOAPHeader:").append(outputSOAPHeader);
2709:                    buff.append(" outputSOAPHeaderFault:").append(
2710:                            outputSOAPHeaderFault);
2711:                    buff.append(" inputEncodingStyle:").append(
2712:                            inputEncodingStyle);
2713:                    buff.append(" inputNamespace:").append(inputNamespace);
2714:                    buff.append(" actionUri:").append(soapActionURI);
2715:                    buff.append(" inJmsProps:").append(inJmsProps);
2716:                    buff.append(" outJmsProps:").append(outJmsProps);
2717:                    buff.append(" inJmsPropVals:").append(inJmsPropVals);
2718:                    buff.append(" context:").append(context);
2719:                    buff.append(" asyncOperation:").append(asyncOperation);
2720:                    buff.append(" asyncRequestID:").append(asyncRequestID);
2721:                    buff.append(" responseHandler:").append(responseHandler);
2722:                    buff.append(" responseMessageParameters:").append(
2723:                            responseMessageParameters);
2724:                    buff.append(" outputEncodingStyle:").append(
2725:                            outputEncodingStyle);
2726:                    buff.append(" typeMap:").append(typeMap);
2727:                } catch (Exception e) {
2728:                    Trc.exceptionInTrace(e);
2729:                }
2730:                return buff.toString();
2731:            }
2732:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.