KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > soap > apachesoap > WSIFOperation_ApacheSOAP


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

57
58 package org.apache.wsif.providers.soap.apachesoap;
59
60 import java.beans.BeanInfo JavaDoc;
61 import java.beans.IntrospectionException JavaDoc;
62 import java.beans.Introspector JavaDoc;
63 import java.beans.PropertyDescriptor JavaDoc;
64 import java.io.Serializable JavaDoc;
65 import java.io.StringReader JavaDoc;
66 import java.net.URL JavaDoc;
67 import java.security.AccessController JavaDoc;
68 import java.security.PrivilegedAction JavaDoc;
69 import java.util.ArrayList JavaDoc;
70 import java.util.HashMap JavaDoc;
71 import java.util.Iterator JavaDoc;
72 import java.util.List JavaDoc;
73 import java.util.StringTokenizer JavaDoc;
74 import java.util.Vector JavaDoc;
75
76 import javax.wsdl.Definition;
77 import javax.wsdl.Input;
78 import javax.wsdl.Operation;
79 import javax.wsdl.Output;
80 import javax.wsdl.Part;
81 import javax.xml.namespace.QName JavaDoc;
82 import javax.xml.parsers.DocumentBuilder JavaDoc;
83
84 import org.apache.soap.Body;
85 import org.apache.soap.Constants;
86 import org.apache.soap.Envelope;
87 import org.apache.soap.Header;
88 import org.apache.soap.SOAPException;
89 import org.apache.soap.encoding.SOAPMappingRegistry;
90 import org.apache.soap.encoding.soapenc.BeanSerializer;
91 import org.apache.soap.messaging.Message;
92 import org.apache.soap.rpc.Call;
93 import org.apache.soap.rpc.Parameter;
94 import org.apache.soap.rpc.Response;
95 import org.apache.soap.rpc.SOAPContext;
96 import org.apache.soap.transport.SOAPTransport;
97 import org.apache.soap.transport.http.SOAPHTTPConnection;
98 import org.apache.soap.util.Bean;
99 import org.apache.soap.util.xml.Deserializer;
100 import org.apache.soap.util.xml.Serializer;
101 import org.apache.soap.util.xml.XMLParserUtils;
102 import org.apache.wsif.WSIFConstants;
103 import org.apache.wsif.WSIFCorrelationId;
104 import org.apache.wsif.WSIFException;
105 import org.apache.wsif.WSIFMessage;
106 import org.apache.wsif.WSIFOperation;
107 import org.apache.wsif.WSIFPort;
108 import org.apache.wsif.WSIFResponseHandler;
109 import org.apache.wsif.base.WSIFDefaultMessage;
110 import org.apache.wsif.base.WSIFDefaultOperation;
111 import org.apache.wsif.logging.MessageLogger;
112 import org.apache.wsif.logging.Trc;
113 import org.apache.wsif.providers.WSIFDynamicTypeMap;
114 import org.apache.wsif.util.WSIFProperties;
115 import org.apache.wsif.util.WSIFUtils;
116 import org.w3c.dom.Document JavaDoc;
117 import org.w3c.dom.Element JavaDoc;
118 import org.xml.sax.InputSource JavaDoc;
119
120 /**
121  * Provide concrete implementation of WSDL operation with Apache SOAP
122  * RPC method invocation.
123  *
124  * @author Alekander Slominski
125  * @author Owen Burroughs <owenb@apache.org>
126  * @author Ant Elder <antelder@apache.org>
127  * @author Jeremy Hughes <hughesj@apache.org>
128  * @author Mark Whitlock <whitlock@apache.org>
129  */

130 public class WSIFOperation_ApacheSOAP
131     extends WSIFDefaultOperation
132     implements WSIFOperation, Serializable JavaDoc {
133         
134     private static final long serialVersionUID = 1L;
135         
136     transient protected String JavaDoc style = null;
137
138     transient protected WSIFPort_ApacheSOAP portInstance;
139     transient protected Operation operation;
140     transient protected Definition definition;
141
142     // cached information to allow efficinet operation calls
143
transient protected List JavaDoc partNames;
144     transient protected String JavaDoc[] names;
145     transient protected Class JavaDoc[] types;
146     transient protected String JavaDoc inputEncodingStyle = Constants.NS_URI_SOAP_ENC;
147     transient protected String JavaDoc inputNamespace;
148
149     transient protected Class JavaDoc returnType;
150     transient protected String JavaDoc actionUri;
151
152     // info for async operation
153
transient protected boolean asyncOperation;
154     transient protected WSIFCorrelationId asyncRequestID;
155     // everything other than what is needed for async response should be transient
156
protected WSIFResponseHandler responseHandler;
157     protected String JavaDoc outputEncodingStyle = Constants.NS_URI_SOAP_ENC;
158     protected String JavaDoc returnName;
159     protected boolean prepared = false;
160     protected WSIFDynamicTypeMap typeMap;
161     protected String JavaDoc inputUse = null;
162     protected String JavaDoc outputUse = null;
163     protected String JavaDoc partSerializerName = null;
164     protected ArrayList JavaDoc wsdlOutParams;
165
166     private static final String JavaDoc HTTP_PROXY_HOST_PROPERTY =
167        "http.proxyHost";
168     private static final String JavaDoc HTTP_PROXY_PORT_PROPERTY =
169        "http.proxyPort";
170     private static final String JavaDoc PROXY_EXCLUDES_PROPERTY =
171        "http.nonProxyHosts";
172        
173     /**
174      * Create Apache SOAP operation instance that encapsultes all necessary
175      * information required to create and execute Apache SOAP Call.
176      */

177     public WSIFOperation_ApacheSOAP(
178         WSIFPort_ApacheSOAP pi,
179         Operation op,
180         WSIFDynamicTypeMap typeMap)
181         throws WSIFException {
182         Trc.entry(this, pi, op, typeMap);
183
184         this.typeMap = typeMap;
185         setDynamicWSIFPort(pi);
186         setOperation(op);
187         setDefinition(pi.getDefinition());
188
189         if (Trc.ON)
190             Trc.exit(deep());
191     }
192
193     /**
194      * Create a new copy of this object. This is not a clone, since
195      * it does not copy the referenced objects as well.
196      */

197     public WSIFOperation_ApacheSOAP copy() throws WSIFException {
198         Trc.entry(this);
199         WSIFOperation_ApacheSOAP op =
200             new WSIFOperation_ApacheSOAP(portInstance, operation, typeMap);
201
202         op.setSoapActionURI(getSoapActionURI());
203         op.setInputNamespace(getInputNamespace());
204         op.setInputEncodingStyle(getInputEncodingStyle());
205         op.setOutputEncodingStyle(getOutputEncodingStyle());
206         op.setPartNames(getPartNames());
207         op.setReturnName(getReturnName());
208         op.setStyle(getStyle());
209         op.setInputUse(getInputUse());
210         op.setOutputUse(getOutputUse());
211         op.setPartSerializerName(getPartSerializerName());
212         op.setResponseHandler(getResponseHandler());
213         op.setInputJmsProperties(getInputJmsProperties());
214         op.setOutputJmsProperties(getOutputJmsProperties());
215         op.setInputJmsPropertyValues(getInputJmsPropertyValues());
216
217         if (Trc.ON)
218             Trc.exit(op.deep());
219         return op;
220     }
221
222     /**
223      * Gets the target namespace URI of this WSIFOperation
224      *
225      * @return the target namespace URI
226      */

227     public String JavaDoc getTargetNamespaceURI() {
228         Trc.entry(this);
229         Definition d = getDefinition();
230         String JavaDoc s = (d == null) ? "" : d.getTargetNamespace();
231         Trc.exit(s);
232         return s;
233     }
234
235     /**
236      * This is utility method that when called initializes operation
237      * (including reconstruction of method signature).
238      */

239     void prepare(WSIFMessage inputMessage, WSIFMessage outputMessage)
240         throws WSIFException {
241         Trc.entry(this, inputMessage, outputMessage);
242         HashMap JavaDoc mapOfUserTypes = portInstance.getLocalTypeMap();
243         SOAPMappingRegistry smr = portInstance.getSOAPMappingRegistry();
244
245         // Instantiate serializers once for the entire prepare
246
BeanSerializer beanSer = new BeanSerializer();
247         PartSerializer partSer = null;
248         if (partSerializerName != null) {
249             try {
250                 partSer =
251                     (PartSerializer) Class
252                         .forName(
253                             partSerializerName,
254                             true,
255                             Thread.currentThread().getContextClassLoader())
256                         .newInstance();
257             } catch (Throwable JavaDoc ignored) {
258                 Trc.ignoredException(ignored);
259             }
260         }
261
262         // first determine list of arguments
263
Input input = operation.getInput();
264         if (input != null) {
265             List JavaDoc parts;
266             if (partNames != null) {
267                 parts = new Vector JavaDoc();
268                 for (Iterator JavaDoc i = partNames.iterator(); i.hasNext();) {
269                     String JavaDoc partName = (String JavaDoc) i.next();
270                     Part part = input.getMessage().getPart(partName);
271                     if (part == null) {
272                         throw new WSIFException(
273                             "no input part named "
274                                 + partName
275                                 + " for binding operation "
276                                 + getName());
277                     }
278                     parts.add(part);
279                 }
280             } else {
281                 parts = input.getMessage().getOrderedParts(null);
282             }
283             int count = parts.size();
284             names = new String JavaDoc[count];
285             types = new Class JavaDoc[count];
286
287             // get parts in correct order
288
for (int i = 0; i < count; ++i) {
289                 Part part = (Part) parts.get(i);
290                 names[i] = part.getName();
291                 QName JavaDoc partType = part.getTypeName();
292                 if (partType == null)
293                     partType = part.getElementName();
294                 if (partType == null) {
295                     throw new WSIFException(
296                         "part " + names[i] + " must have type name declared");
297                 }
298
299                 org.apache.soap.util.xml.QName qname =
300                     new org.apache.soap.util.xml.QName(
301                         partType.getNamespaceURI(),
302                         partType.getLocalPart());
303                 try {
304                     types[i] = (Class JavaDoc) mapOfUserTypes.get(qname);
305                 } catch (Throwable JavaDoc ignored) {
306                     Trc.ignoredException(ignored);
307                 }
308                 if (types[i] == null) {
309                     try {
310                         types[i] =
311                             (Class JavaDoc) smr.queryJavaType(
312                                 qname,
313                                 inputEncodingStyle);
314                     } catch (Throwable JavaDoc exn) {
315                         if (types[i] == null) {
316                             try {
317                                 String JavaDoc packageName =
318                                     WSIFUtils.getPackageNameFromNamespaceURI(
319                                         qname.getNamespaceURI());
320                                 String JavaDoc className =
321                                     WSIFUtils.getJavaClassNameFromXMLName(
322                                         qname.getLocalPart());
323                                 Class JavaDoc inputClass = null;
324                                 try {
325                                     inputClass =
326                                     Class.forName(
327                                         packageName + "." + className,
328                                         true,
329                                         Thread
330                                             .currentThread()
331                                             .getContextClassLoader());
332                                 } catch (ClassNotFoundException JavaDoc exn5) {
333                                     inputClass =
334                                         Class.forName(
335                                             packageName
336                                                 + "."
337                                                 + className
338                                                 + "Element",
339                                             true,
340                                             Thread
341                                                 .currentThread()
342                                                 .getContextClassLoader());
343                                 }
344                                 types[i] = inputClass;
345                                 if ("literal".equals(inputUse)) {
346                                     smr.mapTypes("literal", qname, inputClass, partSer, partSer);
347                                 } else {
348                                 smr.mapTypes(
349                                     Constants.NS_URI_SOAP_ENC,
350                                     qname,
351                                     inputClass,
352                                     beanSer,
353                                     beanSer);
354                                 }
355                                 mapSubtypes(inputClass, beanSer, partSer, smr, inputUse);
356                             } catch (ClassNotFoundException JavaDoc exn1) {
357                                 Trc.ignoredException(exn1);
358                             }
359                         }
360                     }
361
362                 }
363             }
364         } else {
365             names = new String JavaDoc[0];
366             types = new Class JavaDoc[0];
367         }
368
369         // now prepare return value
370
Output output = operation.getOutput();
371         if (output != null) {
372             Part returnPart = null;
373             if (returnName != null) {
374                 returnPart = output.getMessage().getPart(returnName);
375                 if (returnPart == null) {
376                     throw new WSIFException(
377                         "no output part named "
378                             + returnName
379                             + " for bining operation "
380                             + getName());
381                 }
382             } else {
383                 List JavaDoc parts = output.getMessage().getOrderedParts(null);
384                 if (parts.size() > 0) {
385                     returnPart = (Part) parts.get(0);
386                     returnName = returnPart.getName();
387                 }
388             }
389
390             if (returnPart != null) {
391                 QName JavaDoc partType = returnPart.getTypeName();
392                 if (partType == null)
393                     partType = returnPart.getElementName();
394
395                 org.apache.soap.util.xml.QName qname =
396                     new org.apache.soap.util.xml.QName(
397                         partType.getNamespaceURI(),
398                         partType.getLocalPart());
399
400                 try {
401                     returnType = (Class JavaDoc) mapOfUserTypes.get(qname);
402                 } catch (Throwable JavaDoc ignored) {
403                     Trc.ignoredException(ignored);
404                 }
405
406                 if (returnType == null) {
407                     try {
408                         returnType =
409                             (Class JavaDoc) smr.queryJavaType(
410                                 qname,
411                                 outputEncodingStyle);
412                     } catch (Throwable JavaDoc exn) {
413                         if (returnType == null) {
414                             try {
415                                 String JavaDoc packageName =
416                                     WSIFUtils.getPackageNameFromNamespaceURI(
417                                         qname.getNamespaceURI());
418                                 String JavaDoc className =
419                                     WSIFUtils.getJavaClassNameFromXMLName(
420                                         qname.getLocalPart());
421                                 try {
422                                     returnType =
423                                         Class.forName(
424                                             packageName + "." + className,
425                                             true,
426                                             Thread
427                                                 .currentThread()
428                                                 .getContextClassLoader());
429                                 } catch (ClassNotFoundException JavaDoc exn5) {
430                                     returnType =
431                                         Class.forName(
432                                             packageName
433                                                 + "."
434                                                 + className
435                                                 + "Element",
436                                             true,
437                                             Thread
438                                                 .currentThread()
439                                                 .getContextClassLoader());
440                                 }
441                                 if ("literal".equals(outputUse)) {
442                                     smr.mapTypes(
443                                         "literal",
444                                         qname,
445                                         returnType,
446                                         partSer,
447                                         partSer);
448                                 } else {
449                                     smr.mapTypes(
450                                         Constants.NS_URI_SOAP_ENC,
451                                         qname,
452                                         returnType,
453                                         beanSer,
454                                         beanSer);
455                                 }
456                                 mapSubtypes(returnType, beanSer, partSer, smr, outputUse);
457                             } catch (ClassNotFoundException JavaDoc exn1) {
458                                 Trc.ignoredException(exn1);
459                             }
460                         }
461                     }
462
463                 }
464             }
465             // setup any output paramter part names defined in the WSDL
466
List JavaDoc parts = output.getMessage().getOrderedParts(null);
467             if (parts.size() > 1) {
468                 ArrayList JavaDoc al = new ArrayList JavaDoc();
469                 for (int i = 1; i < parts.size(); i++) {
470                     al.add(((Part) parts.get(i)).getName());
471                 }
472                 setWSDLOutParams(al);
473             }
474         }
475         prepared = true;
476         Trc.exit();
477     }
478
479     private void mapSubtypes(
480         Class JavaDoc javaType,
481         BeanSerializer beanSer,
482         PartSerializer partSer,
483         SOAPMappingRegistry smr,
484         String JavaDoc use) {
485
486         BeanInfo JavaDoc beanInfo = null;
487         try {
488             beanInfo = Introspector.getBeanInfo(javaType);
489         } catch (IntrospectionException JavaDoc e) {
490             Trc.ignoredException(e);
491         }
492
493         if (beanInfo != null) {
494             PropertyDescriptor JavaDoc[] properties = beanInfo.getPropertyDescriptors();
495             if (properties != null) {
496                 for (int i = 0; i < properties.length; i++) {
497                     Class JavaDoc propType = properties[i].getPropertyType();
498                     try {
499                         org.apache.soap.util.xml.QName qname =
500                             smr.queryElementType(propType, inputEncodingStyle);
501                     } catch (IllegalArgumentException JavaDoc exn) {
502                         Trc.exception(exn);
503                         // not found in the registry - complex type, not registered
504
// before
505
if (!propType.equals(Class JavaDoc.class)) {
506                             String JavaDoc packageName =
507                                 propType.getPackage().getName();
508                             String JavaDoc fullClassName = propType.getName();
509                             String JavaDoc className =
510                                 fullClassName.substring(
511                                     fullClassName.lastIndexOf(".") + 1);
512                             org.apache.soap.util.xml.QName qname =
513                                 new org.apache.soap.util.xml.QName(
514                                     WSIFUtils.getXSDNamespaceFromPackageName(
515                                         packageName),
516                                     className);
517
518                             if ("literal".equals(use)) {
519                                 smr.mapTypes(
520                                     "literal",
521                                     qname,
522                                     propType,
523                                     partSer,
524                                     partSer);
525                             } else {
526                                 smr.mapTypes(
527                                     Constants.NS_URI_SOAP_ENC,
528                                     qname,
529                                     propType,
530                                     beanSer,
531                                     beanSer);
532                             }
533                             mapSubtypes(propType, beanSer, partSer, smr, use);
534                         }
535                     }
536                 }
537             }
538         }
539     }
540
541     private void setupTypeMappings(
542         HashMap JavaDoc mapOfUserTypes,
543         SOAPMappingRegistry smr)
544         throws WSIFException {
545
546         // Mappings are set in the WSIFPort_ApacheSOAP which created this operation.
547
// However, if this operation was deserialized for an async response then
548
// we will have no reference to a WSIFPort and so we need to explicitly
549
// create the mappings again.
550
if (portInstance == null) {
551             HashMap JavaDoc tempMap = new HashMap JavaDoc();
552             WSIFPort_ApacheSOAP.prepareTypeMappings(
553                 smr,
554                 typeMap,
555                 partSerializerName,
556                 tempMap);
557         }
558     }
559
560     public boolean executeRequestResponseOperation(
561         WSIFMessage input,
562         WSIFMessage output,
563         WSIFMessage fault)
564         throws WSIFException {
565
566         Trc.entry(this, input, output, fault);
567         close();
568
569         setAsyncOperation(false);
570
571         boolean succ;
572         if ("document".equals(style))
573             succ = invokeRequestResponseOperationDocument(input, output, fault);
574         else
575             succ = invokeRequestResponseOperation(input, output, fault);
576
577         Trc.exit(succ);
578         return succ;
579     }
580
581     public void executeInputOnlyOperation(WSIFMessage input)
582         throws WSIFException {
583
584         Trc.entry(this, input);
585         setAsyncOperation(false);
586         invokeRequestResponseOperation(input, null, null);
587         Trc.exit();
588     }
589
590     /**
591      * Invoke RPC operation using ApacheSOAP
592      */

593     public boolean invokeRequestResponseOperation(
594         WSIFMessage input,
595         WSIFMessage output,
596         WSIFMessage fault)
597         throws WSIFException {
598         Trc.entry(this, input, output, fault);
599         if (!prepared)
600             prepare(input, output);
601
602         Call call = portInstance.getCall();
603
604         call.setEncodingStyleURI(getInputEncodingStyle());
605
606         SOAPTransport st = getTransport();
607         if (st != null) {
608             call.setSOAPTransport(st);
609             if (st instanceof SOAPJMSConnection) {
610                 SOAPJMSConnection sjt = (SOAPJMSConnection) st;
611                 sjt.setSyncTimeout(WSIFProperties.getSyncTimeout());
612                 sjt.setAsyncTimeout(WSIFProperties.getAsyncTimeout());
613             }
614         }
615
616         call.setTargetObjectURI(getInputNamespace());
617         call.setMethodName(getName());
618
619         if (inJmsPropVals != null && !inJmsPropVals.isEmpty()) {
620             checkForTimeoutProperties(st, inJmsPropVals);
621             ((SOAPJMSConnection) st).setJmsProperties(inJmsPropVals);
622         }
623
624         Vector JavaDoc params = new Vector JavaDoc();
625         Object JavaDoc partInst;
626         for (int i = 0; i < names.length; ++i) {
627             try {
628                 partInst = input.getObjectPart(names[i]);
629             } catch (WSIFException ex) {
630                 Trc.exception(ex);
631                 partInst = null;
632             }
633             Object JavaDoc value = partInst;
634             // some runtime param validity check
635

636             if (value != null
637                 && !types[i].isPrimitive()
638                 && !(types[i].isAssignableFrom(value.getClass()))) {
639                 throw new WSIFException(
640                     "value "
641                         + value
642                         + " has unexpected type "
643                         + value.getClass()
644                         + " instead of "
645                         + types[i]);
646             }
647
648             if (inJmsProps.containsKey(names[i]) && st != null) {
649                 String JavaDoc name = (String JavaDoc) (inJmsProps.get(names[i]));
650                 if (!timeoutProperty(st, name, value)) {
651                    ((SOAPJMSConnection) st).setJmsProperty(
652                       name,
653                       value);
654                 }
655             } else {
656                 Parameter param =
657                     new Parameter(
658                         names[i],
659                         types[i],
660                         value,
661                         inputEncodingStyle);
662                 params.addElement(param);
663             }
664         }
665
666         call.setParams(params);
667
668         setTransportContext(st);
669
670         setCallContext(call);
671
672         // invoke the operation through ApacheSOAP
673
Response resp;
674         boolean respOK = true;
675         URL JavaDoc locationUri = portInstance.getEndPoint();
676         if ( locationUri != null && !isHostInNonProxyProperty( locationUri ) ) {
677            setSOAPProxy( st );
678         }
679
680         Trc.event(
681             this,
682             "Invoking operation ",
683             getName(),
684             " on ",
685             locationUri,
686             " call object ",
687             call);
688
689         try {
690             resp = call.invoke(locationUri, getSoapActionURI());
691         } catch (SOAPException e) {
692             Trc.exception(e);
693
694             // Log message
695
MessageLogger.log("WSIF.0005E", "ApacheSOAP", getName());
696
697             throw new WSIFException(
698                 "SOAPException: " + e.getFaultCode() + e.getMessage(),
699                 e);
700         }
701
702         Trc.event(this, "Operation returned ", resp);
703
704         // setJMSOutPropsInContext( st ); TODO doesn't work yet
705

706         if (!isAsyncOperation() && returnType != null) {
707             respOK = buildResponseMessages(resp, output, fault);
708         }
709         
710         if (resp instanceof Response) {
711             Header soapHeader = resp.getHeader();
712             addContextResponseSOAPHeaders(soapHeader);
713         }
714
715         Trc.exit(respOK);
716         return respOK;
717     }
718
719     public boolean invokeRequestResponseOperationDocument(
720         WSIFMessage input,
721         WSIFMessage output,
722         WSIFMessage fault)
723         throws WSIFException {
724         Trc.entry(this, input, output, fault);
725
726         if (!prepared)
727             prepare(input, output);
728         Envelope msgEnv = new Envelope();
729         Body msgBody = new Body();
730         Vector JavaDoc vect = new Vector JavaDoc();
731
732         Iterator JavaDoc iterator =
733             operation.getInput().getMessage().getParts().keySet().iterator();
734         while (iterator.hasNext()) {
735             String JavaDoc partName = (String JavaDoc) iterator.next();
736             Object JavaDoc part = input.getObjectPart(partName);
737             String JavaDoc encoding = null;
738             if ("literal".equals(inputUse)) {
739                 // Should also include namespace
740
encoding = "literal";
741             } else {
742                 encoding = this.inputEncodingStyle;
743             }
744
745             PartSerializer partSerializer = null;
746             Object JavaDoc o =
747                 portInstance.getSOAPMappingRegistry().querySerializer(
748                     part.getClass(),
749                     inputUse);
750             if (o instanceof PartSerializer) {
751                 PartSerializer tmp = (PartSerializer) o;
752                 try {
753                     partSerializer =
754                         (PartSerializer) tmp.getClass().newInstance();
755                 } catch (InstantiationException JavaDoc e) {
756                     Trc.ignoredException(e);
757                 } catch (IllegalAccessException JavaDoc e) {
758                     Trc.ignoredException(e);
759                 }
760                 partSerializer.setPart(part);
761                 Part modelPart =
762                     operation.getInput().getMessage().getPart(partName);
763                 javax.xml.namespace.QName JavaDoc partType = modelPart.getTypeName();
764                 if (partType == null)
765                     partType = modelPart.getElementName();
766                 partSerializer.setPartQName(partType);
767             } else // document with soap encoding - never been tried
768
{
769                 partSerializer = new SOAPEncSerializerWrapper();
770                 partSerializer.setPart(part);
771                 (
772                     (
773                         SOAPEncSerializerWrapper) partSerializer)
774                             .setTargetSerializer(
775                     (Serializer) o);
776             }
777
778             Bean bean = new Bean(partSerializer.getClass(), partSerializer);
779             vect.add(bean);
780         }
781
782         // create message envelope and body
783
URL JavaDoc url = portInstance.getEndPoint();
784         Envelope env = null;
785         msgBody.setBodyEntries(vect);
786         msgEnv.setBody(msgBody);
787
788         SOAPTransport st = getTransport();
789
790         if (st instanceof SOAPJMSConnection) {
791            SOAPJMSConnection sjt = (SOAPJMSConnection) st;
792            sjt.setSyncTimeout(WSIFProperties.getSyncTimeout());
793            sjt.setAsyncTimeout(WSIFProperties.getAsyncTimeout());
794         }
795
796         if (inJmsPropVals != null && !inJmsPropVals.isEmpty()) {
797            checkForTimeoutProperties(st, inJmsPropVals);
798            ((SOAPJMSConnection) st).setJmsProperties(inJmsPropVals);
799         }
800
801         //TODO docstyle headers
802
//setCallContext( call );
803

804         if ( url != null && !isHostInNonProxyProperty( url ) ) {
805            setSOAPProxy( st );
806         }
807
808         // create and send message
809
try {
810             Message msg = new Message();
811             if (st != null)
812                 msg.setSOAPTransport(st);
813
814             Trc.event(
815                 this,
816                 "Invoking operation ",
817                 getName(),
818                 " url ",
819                 url,
820                 " soapaction ",
821                 getSoapActionURI(),
822                 " envelope ",
823                 msgEnv,
824                 " message ",
825                 msg);
826
827             msg.send(url, getSoapActionURI(), msgEnv);
828
829             // receive response envelope
830
env = msg.receiveEnvelope();
831         } catch (SOAPException exn) {
832             Trc.exception(exn);
833             WSIFException e =
834                 new WSIFException("SOAP Exception: " + exn.getMessage());
835             e.setTargetException(exn);
836             throw e;
837         }
838
839         Trc.event(this, "Returned from operation, envelope ", env);
840
841         Body retbody = env.getBody();
842         java.util.Vector JavaDoc v = retbody.getBodyEntries();
843         int index = 0;
844
845         String JavaDoc encoding = null;
846         if ("literal".equals(outputUse)) {
847             // Should also include namespace
848
encoding = "literal";
849         } else {
850             encoding = this.outputEncodingStyle;
851         }
852
853         iterator =
854             operation.getOutput().getMessage().getParts().keySet().iterator();
855         while (iterator.hasNext()) {
856             Element JavaDoc element = (Element JavaDoc) v.get(index++);
857             String JavaDoc partName = (String JavaDoc) iterator.next();
858             Part modelPart =
859                 operation.getOutput().getMessage().getPart(partName);
860             javax.xml.namespace.QName JavaDoc partType = modelPart.getTypeName();
861             if (partType == null)
862                 partType = modelPart.getElementName();
863
864             PartSerializer partSerializer = null;
865             Object JavaDoc o =
866                 this.portInstance.getSOAPMappingRegistry().queryDeserializer(
867                     new org.apache.soap.util.xml.QName(
868                         partType.getNamespaceURI(),
869                         partType.getLocalPart()),
870                     encoding);
871
872             if (o instanceof PartSerializer) {
873                 PartSerializer tmp = (PartSerializer) o;
874                 try {
875                     partSerializer =
876                         (PartSerializer) tmp.getClass().newInstance();
877                 } catch (InstantiationException JavaDoc e) {
878                     Trc.ignoredException(e);
879                 } catch (IllegalAccessException JavaDoc e) {
880                     Trc.ignoredException(e);
881                 }
882                 partSerializer.setPartQName(partType);
883                 partSerializer.unmarshall(null, null, element, null, null);
884                 Object JavaDoc retBean = partSerializer.getPart();
885                 output.setObjectPart(partName, retBean);
886             } else // document with soap encoding - never been tried
887
{
888                 Bean bean =
889                     ((Deserializer) o).unmarshall(
890                         null,
891                         null,
892                         element,
893                         null,
894                         null);
895                 Object JavaDoc retBean = bean.value;
896             }
897         }
898         
899         Header soapHeader = env.getHeader();
900         addContextResponseSOAPHeaders(soapHeader);
901
902         Trc.exit(true);
903         return true;
904     }
905
906     /**
907      * Performs a request response operation asynchronously.
908      *
909      * @param input input message to send to the operation
910      * @return the correlation ID or the request. The correlation ID
911      * is used to associate the request with the WSIFOperation.
912      * @exception WSIFException if something goes wrong.
913      * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage)
914      */

915     public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage input)
916         throws WSIFException {
917
918         Trc.entry(this, input);
919         WSIFCorrelationId id = executeRequestResponseAsync(input, null);
920         Trc.exit(id);
921         return id;
922
923     }
924
925     /**
926      * Performs a request response operation asynchronously.
927      *
928      * @param input input message to send to the operation
929      * @param handler the response handler that will be notified
930      * when the asynchronous response becomes available.
931      * @return the correlation ID or the request. The correlation ID
932      * is used to associate the request with the WSIFOperation.
933      * @exception WSIFException if something goes wrong.
934      * @see WSIFOperation#executeRequestResponseAsync(WSIFMessage,WSIFResponseHandler)
935      */

936     public WSIFCorrelationId executeRequestResponseAsync(
937         WSIFMessage input,
938         WSIFResponseHandler handler)
939         throws WSIFException {
940
941         Trc.entry(this, input, handler);
942         close();
943
944         if (!prepared)
945             prepare(input, null);
946
947         if (!portInstance.supportsAsync()) {
948             throw new WSIFException("asynchronous operations not available");
949         }
950
951         if ("document".equals(style)) {
952             throw new WSIFException("docstyle asynchronous operations not implemented");
953         }
954
955         setAsyncOperation(true);
956         setResponseHandler(handler);
957         SOAPJMSConnection transport = (SOAPJMSConnection) getTransport();
958         transport.setWsifOperation(this);
959         transport.setAsyncOperation(true);
960
961         invokeRequestResponseOperation(input, null, null);
962
963         transport.setAsyncOperation(false);
964         WSIFCorrelationId id = getAsyncRequestID();
965         Trc.exit(id);
966         return id;
967
968     }
969
970     /**
971      * fireAsyncResponse is called by an AsyncListener when a response
972      * has been received for a previous executeRequestResponseAsync call.
973      * This WSIFOperation will have been serialized in the correlation
974      * service when the request was sent. When the AsynListener is notified
975      * that a response has arrived for the request it unserializes this
976      * WSIFOperation from the corelation service and calls this method.
977      * This method will then unmarshal the reponse and pass it to the
978      * executeAsyncResponse method of the associated WSIFResponseHandler.
979      * @see WSIFOperation#fireAsyncResponse(Object)
980      * @param response an Object representing the response. The response
981      * will be raw XML
982      */

983     public void fireAsyncResponse(Object JavaDoc response) throws WSIFException {
984         Trc.entry(this, response);
985
986         Response resp = deserialiseResponseObject(response);
987
988         WSIFMessage outMsg = createOutputMessage();
989         WSIFMessage faultMsg = createFaultMessage();
990         buildResponseMessages(resp, outMsg, faultMsg);
991
992         getResponseHandler().executeAsyncResponse(outMsg, faultMsg);
993
994         Trc.exit(outMsg); // , faultMsg } ); ??
995
}
996
997     /**
998      * Processes the response to an asynchronous request.
999      * This is called for when the asynchronous operation was
1000     * initiated without a WSIFResponseHandler, that is, by calling
1001     * the executeRequestResponseAsync(WSIFMessage input) method.
1002     *
1003     * @param response an Object representing the response.
1004     * @param output an empty message which will be filled in if
1005     * the operation invocation succeeds. If it does not
1006     * succeed, the contents of this message are undefined.
1007     * (This is a return value of this method.)
1008     * @param fault an empty message which will be filled in if
1009     * the operation invocation fails. If it succeeds, the
1010     * contents of this message are undefined. (This is a
1011     * return value of this method.)
1012     *
1013     * @return true or false indicating whether a fault message was
1014     * generated or not. The truth value indicates whether
1015     * the output or fault message has useful information.
1016     *
1017     */

1018    public boolean processAsyncResponse(
1019        Object JavaDoc response,
1020        WSIFMessage output,
1021        WSIFMessage fault)
1022        throws WSIFException {
1023        Trc.entry(this, response, output, fault);
1024
1025        Response resp = deserialiseResponseObject(response);
1026        boolean ok = buildResponseMessages(resp, output, fault);
1027
1028        Trc.exit( ok );
1029        return ok;
1030    }
1031
1032    /**
1033     * This deserialises and unmarshalls the response message.
1034     * Its copied, with minor changes, from the 2nd half of
1035     * the SOAP 2.2 Call class invoke method.
1036     */

1037    private Response deserialiseResponseObject(Object JavaDoc msg)
1038        throws WSIFException {
1039
1040        if (msg == null) {
1041            throw new WSIFException("null response to async send");
1042        }
1043
1044        if (!(msg instanceof javax.jms.TextMessage JavaDoc)) {
1045            throw new WSIFException("response not a javax.jms.TextMessage");
1046        }
1047
1048        HashMap JavaDoc mapOfUserTypes = new HashMap JavaDoc();
1049        SOAPMappingRegistry smr =
1050            WSIFPort_ApacheSOAP.createSOAPMappingRegistry(new Call());
1051          
1052        // clear port to ensure setupTypeMappings does something
1053
setDynamicWSIFPort( null );
1054
1055        setupTypeMappings(mapOfUserTypes, smr);
1056
1057        try {
1058
1059            javax.jms.TextMessage JavaDoc m = (javax.jms.TextMessage JavaDoc) msg;
1060            String JavaDoc payloadStr = m.getText();
1061
1062            // Get the response context.
1063
SOAPContext respCtx = new SOAPContext();
1064            respCtx.setRootPart(payloadStr, "text/xml");
1065
1066            // Parse the incoming response stream.
1067
DocumentBuilder JavaDoc xdb = XMLParserUtils.getXMLDocBuilder();
1068            Document JavaDoc respDoc =
1069                xdb.parse(new InputSource JavaDoc(new StringReader JavaDoc(payloadStr)));
1070            Element JavaDoc payload = null;
1071
1072            if (respDoc != null) {
1073                payload = respDoc.getDocumentElement();
1074            } else { //probably does not happen
1075
throw new SOAPException(
1076                    Constants.FAULT_CODE_CLIENT,
1077                    "Parsing error, response was:\n" + payloadStr);
1078            }
1079
1080            // Unmarshall the response envelope.
1081
Envelope respEnv = Envelope.unmarshall(payload, respCtx);
1082
1083            // Extract the response from the response envelope.
1084
Response resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
1085
1086            return resp;
1087
1088        } catch (Exception JavaDoc ex) {
1089            Trc.exception(ex);
1090            throw new WSIFException(ex.getMessage());
1091        }
1092    }
1093
1094    /**
1095     * Extracts the message parts from the response.
1096     */

1097    private boolean buildResponseMessages(
1098        Response resp,
1099        WSIFMessage outMsg,
1100        WSIFMessage faultMsg)
1101        throws WSIFException {
1102
1103        boolean respOK;
1104
1105        if (resp == null) {
1106            throw new WSIFException("soap response is null");
1107        }
1108
1109        if (resp.generatedFault()) {
1110            respOK = false;
1111            if (faultMsg != null) {
1112                org.apache.soap.Fault soapFault = resp.getFault();
1113                faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME);
1114                faultMsg.setObjectPart(
1115                    WSIFConstants.SOAP_FAULT_OBJECT,
1116                    soapFault);
1117            }
1118        } else {
1119            respOK = true;
1120            populateOutMsgReturnPart(resp, outMsg);
1121            populateOutMsgParts(resp, outMsg);
1122        }
1123        return respOK;
1124    }
1125
1126    /**
1127     * Populate the outMessage with the response return value.
1128     */

1129    private void populateOutMsgReturnPart(Response resp, WSIFMessage outMsg)
1130        throws WSIFException {
1131        if (outMsg != null && returnName != null) {
1132            Parameter retValue = resp.getReturnValue();
1133            if (retValue == null) {
1134                throw new WSIFException("return value not found in response message");
1135            }
1136            Object JavaDoc result = retValue.getValue();
1137            if (returnType != null) { // will be null for async responses
1138
if (!returnType.isPrimitive()
1139                    && result != null
1140                    && !(returnType.isAssignableFrom(result.getClass()))) {
1141                    throw new WSIFException(
1142                        "return value "
1143                            + result
1144                            + " has unexpected type "
1145                            + result.getClass()
1146                            + " instead of "
1147                            + returnType);
1148                }
1149            }
1150            outMsg.setObjectPart(returnName, result);
1151        }
1152    }
1153
1154    /**
1155     * Populate the outMessage with the expected parts.
1156     * (this only does the out parameters not the return part)
1157     */

1158    private void populateOutMsgParts(Response resp, WSIFMessage outMsg)
1159        throws WSIFException {
1160        if (outMsg != null) {
1161            Vector JavaDoc respParms = resp.getParams();
1162            ArrayList JavaDoc wsdlOutParameters = getWSDLOutParams();
1163            if (respParms != null) {
1164                Parameter p;
1165                for (Iterator JavaDoc i = respParms.iterator(); i.hasNext();) {
1166                    p = (Parameter) i.next();
1167                    outMsg.setObjectPart(p.getName(), p.getValue());
1168                    wsdlOutParameters.remove(p.getName());
1169                }
1170            }
1171            // missing parts default to null
1172
for (Iterator JavaDoc i = wsdlOutParameters.iterator(); i.hasNext();) {
1173                outMsg.setObjectPart((String JavaDoc) i.next(), null);
1174            }
1175        }
1176    }
1177
1178    /**
1179     * Return name of operation.
1180     */

1181    public String JavaDoc getName() {
1182        Trc.entry(this);
1183        String JavaDoc s = operation.getName();
1184        Trc.exit(s);
1185        return s;
1186    }
1187
1188    public String JavaDoc getSoapActionURI() {
1189        Trc.entry(this);
1190        Trc.exit(actionUri);
1191        return actionUri;
1192    }
1193
1194    public void setSoapActionURI(String JavaDoc value) {
1195        Trc.entry(this, value);
1196        actionUri = value;
1197        Trc.exit();
1198    }
1199
1200    public String JavaDoc getInputNamespace() {
1201        Trc.entry(this);
1202        Trc.exit(inputNamespace);
1203        return inputNamespace;
1204    }
1205
1206    public void setInputNamespace(String JavaDoc value) {
1207        Trc.entry(this, value);
1208        inputNamespace = value;
1209        Trc.exit();
1210    }
1211
1212    public String JavaDoc getInputEncodingStyle() {
1213        Trc.entry(this);
1214        Trc.exit(inputEncodingStyle);
1215        return inputEncodingStyle;
1216    }
1217
1218    public void setInputEncodingStyle(String JavaDoc value) {
1219        Trc.entry(this, value);
1220        inputEncodingStyle = value;
1221        Trc.exit();
1222    }
1223
1224    public String JavaDoc getOutputEncodingStyle() {
1225        Trc.entry(this);
1226        Trc.exit(outputEncodingStyle);
1227        return outputEncodingStyle;
1228    }
1229
1230    public void setOutputEncodingStyle(String JavaDoc value) {
1231        Trc.entry(this, value);
1232        outputEncodingStyle = value;
1233        Trc.exit();
1234    }
1235
1236    public List JavaDoc getPartNames() {
1237        Trc.entry(this);
1238        Trc.exit(partNames);
1239        return partNames;
1240    }
1241
1242    public void setPartNames(List JavaDoc value) {
1243        Trc.entry(this, value);
1244        partNames = value;
1245        Trc.exit();
1246    }
1247
1248    public String JavaDoc getReturnName() {
1249        Trc.entry(this);
1250        Trc.exit(returnName);
1251        return returnName;
1252    }
1253
1254    public void setReturnName(String JavaDoc value) {
1255        Trc.entry(this, value);
1256        returnName = value;
1257        Trc.exit();
1258    }
1259
1260    // where is WSDL defining this abstract mesage
1261
public Operation getOperation() {
1262        Trc.entry(this);
1263        Trc.exit(operation);
1264        return operation;
1265    }
1266
1267    public void setOperation(Operation value) {
1268        Trc.entry(this, value);
1269        operation = value;
1270        Trc.exit();
1271    }
1272
1273    public Definition getDefinition() {
1274        Trc.entry(this);
1275        Trc.exit(definition);
1276        return definition;
1277    }
1278
1279    public void setDefinition(Definition value) {
1280        Trc.entry(this, value);
1281        definition = value;
1282        Trc.exit();
1283    }
1284
1285    // WSIF related
1286
public WSIFPort_ApacheSOAP getDynamicWSIFPort() {
1287        Trc.entry(this);
1288        Trc.exit(portInstance);
1289        return portInstance;
1290    }
1291
1292    public void setDynamicWSIFPort(WSIFPort_ApacheSOAP value) {
1293        Trc.entry(this, value);
1294        portInstance = value;
1295        Trc.exit();
1296    }
1297
1298    /**
1299     * Gets the style.
1300     * @return Returns a String
1301     */

1302    public String JavaDoc getStyle() {
1303        Trc.entry(this);
1304        Trc.exit(style);
1305        return style;
1306    }
1307
1308    /**
1309     * Gets the response handler that will be used to
1310     * process the response to a asynchronous request.
1311     * @return the current response handler.
1312     * (package visable as called from Transport)
1313     */

1314    WSIFResponseHandler getResponseHandler() {
1315        Trc.entry(this);
1316        Trc.exit(responseHandler);
1317        return responseHandler;
1318    }
1319
1320    /**
1321     * Gets the transport being used by this operation
1322     * @return the current transport
1323     */

1324    public SOAPTransport getTransport() {
1325        Trc.entry(this);
1326        SOAPTransport t = portInstance.getSOAPTransport();
1327        Trc.exit(t);
1328        return t;
1329    }
1330
1331    /**
1332     * Gets the correlation ID of the last request sent by the
1333     * executeRequestResponseAsync method.
1334     * @return the corelation ID of the previous request
1335     */

1336    public WSIFCorrelationId getAsyncRequestID() {
1337        Trc.entry(this);
1338        Trc.exit(asyncRequestID);
1339        return asyncRequestID;
1340    }
1341
1342    /**
1343     * Sets the correlation ID of the last request sent by the
1344     * executeRequestResponseAsync method.
1345     * @return the corelation ID of the previous request
1346     * (package visable as its called by WSIFJmsTransport)
1347     */

1348    void setAsyncRequestID(WSIFCorrelationId asyncRequestID) {
1349        Trc.entry(this, asyncRequestID);
1350        this.asyncRequestID = asyncRequestID;
1351        Trc.exit();
1352    }
1353
1354    /**
1355     * Sets if the currently executing request is an asynchronous request.
1356     *
1357     * @param b true if the current request is a asynchronous request,
1358     * otherwise false
1359     */

1360    private void setAsyncOperation(boolean b) {
1361        asyncOperation = b;
1362    }
1363
1364    /**
1365     * Sets the style.
1366     * @param style The style to set
1367     */

1368    public void setStyle(String JavaDoc style) {
1369        Trc.entry(this, style);
1370        this.style = style;
1371        Trc.exit();
1372    }
1373
1374    /**
1375     * Sets the response handler that will be used to
1376     * process the response to an asynchronous request.
1377     * @param responseHandler the responseHandler to use
1378     */

1379    private void setResponseHandler(WSIFResponseHandler responseHandler) {
1380        this.responseHandler = responseHandler;
1381    }
1382
1383    /**
1384     * Gets the inputUse.
1385     * @return Returns a String
1386     */

1387    public String JavaDoc getInputUse() {
1388        Trc.entry(this);
1389        Trc.exit(inputUse);
1390        return inputUse;
1391    }
1392
1393    /**
1394     * Sets the inputUse.
1395     * @param inputUse The inputUse to set
1396     */

1397    public void setInputUse(String JavaDoc inputUse) {
1398        Trc.entry(this, inputUse);
1399        this.inputUse = inputUse;
1400        Trc.exit();
1401    }
1402
1403    /**
1404     * Gets the outputUse.
1405     * @return Returns a String
1406     */

1407    public String JavaDoc getOutputUse() {
1408        Trc.entry(this);
1409        Trc.exit(outputUse);
1410        return outputUse;
1411    }
1412
1413    /**
1414     * Sets the outputUse.
1415     * @param outputUse The outputUse to set
1416     */

1417    public void setOutputUse(String JavaDoc outputUse) {
1418        Trc.entry(this, outputUse);
1419        this.outputUse = outputUse;
1420        Trc.exit();
1421    }
1422
1423    /**
1424     * Gets the partSerializerName.
1425     * @return Returns a String
1426     */

1427    public String JavaDoc getPartSerializerName() {
1428        Trc.entry(this);
1429        Trc.exit(partSerializerName);
1430        return partSerializerName;
1431    }
1432
1433    private ArrayList JavaDoc getWSDLOutParams() {
1434        if (wsdlOutParams == null) {
1435            wsdlOutParams = new ArrayList JavaDoc();
1436        }
1437        return wsdlOutParams;
1438    }
1439
1440    private void setWSDLOutParams(ArrayList JavaDoc al) {
1441        wsdlOutParams = al;
1442    }
1443
1444    public WSIFPort getWSIFPort() {
1445        Trc.entry(this);
1446        Trc.exit(portInstance);
1447        return portInstance;
1448    }
1449    
1450    /**
1451     * Tests if the currently executing request is an asynchronous request.
1452     *
1453     * @return true if the current request is a asynchronous request,
1454     * otherwise false
1455     */

1456    public boolean isAsyncOperation() {
1457        Trc.entry(this);
1458        Trc.exit(asyncOperation);
1459        return asyncOperation;
1460    }
1461
1462    /**
1463     * Sets the partSerializerName.
1464     * @param partSerializerName The partSerializerName to set
1465     */

1466    public void setPartSerializerName(String JavaDoc partSerializerName) {
1467        Trc.entry(this, partSerializerName);
1468        this.partSerializerName = partSerializerName;
1469        Trc.exit();
1470    }
1471
1472    /**
1473     * This sets up the output JMS property values in the context
1474     */

1475    private void setJMSOutPropsInContext(SOAPTransport t)
1476        throws WSIFException {
1477        if (!(t instanceof SOAPJMSConnection)) {
1478            return;
1479        }
1480        HashMap JavaDoc props = ((SOAPJMSConnection) t).getJmsProperties();
1481        if (props != null) {
1482            if (context == null) {
1483                context = new WSIFDefaultMessage();
1484            }
1485            context.setParts(props);
1486        }
1487    }
1488
1489    /**
1490     * This sets up any context property values in the transport
1491     */

1492    private void setTransportContext(SOAPTransport t) {
1493        if (context == null || !(t instanceof SOAPJMSConnection)) {
1494            return;
1495        }
1496        HashMap JavaDoc jmsProps = new HashMap JavaDoc();
1497        for (Iterator JavaDoc i = context.getPartNames(); i.hasNext();) {
1498           try {
1499              String JavaDoc partName = (String JavaDoc) i.next();
1500              Object JavaDoc value = context.getObjectPart(partName);
1501              if (!timeoutProperty(t, partName, value)) {
1502                 if (partName.startsWith(WSIFConstants.CONTEXT_JMS_PREFIX)) {
1503                    jmsProps.put(
1504                        partName.substring(
1505                            WSIFConstants.CONTEXT_JMS_PREFIX.length()),
1506                        value);
1507                 }
1508              }
1509           } catch (WSIFException ex) {
1510              Trc.ignoredException(ex);
1511           }
1512        }
1513        if (jmsProps.size() > 0) {
1514            ((SOAPJMSConnection) t).setJmsProperties(jmsProps);
1515        }
1516    }
1517
1518    /**
1519     * This sets up the context headers in the SOAP
1520     * Call object prior to invoke method being issued.
1521     */

1522    private void setCallContext(Call call) {
1523        Object JavaDoc o;
1524        String JavaDoc name;
1525
1526        // clear out any old header values
1527
call.setHeader(null);
1528        addHTTPHeader(call, WSIFConstants.CONTEXT_HTTP_USER, null);
1529        addHTTPHeader(call, WSIFConstants.CONTEXT_HTTP_PSWD, null);
1530
1531        if (context == null) {
1532            return;
1533        }
1534
1535        name = WSIFConstants.CONTEXT_HTTP_USER;
1536        try {
1537            o = context.getObjectPart(name);
1538            if (o instanceof String JavaDoc) {
1539                addHTTPHeader(call, name, (String JavaDoc) o);
1540            }
1541        } catch (WSIFException ex) {
1542            Trc.ignoredException(ex);
1543            addHTTPHeader(call, name, null);
1544        }
1545
1546        name = WSIFConstants.CONTEXT_HTTP_PSWD;
1547        try {
1548            o = context.getObjectPart(name);
1549            if (o instanceof String JavaDoc) {
1550                addHTTPHeader(call, name, (String JavaDoc) o);
1551            }
1552        } catch (WSIFException ex) {
1553            Trc.ignoredException(ex);
1554            addHTTPHeader(call, name, null);
1555        }
1556
1557        try {
1558            name = WSIFConstants.CONTEXT_REQUEST_SOAP_HEADERS;
1559            o = context.getObjectPart(name);
1560            if (o instanceof List JavaDoc) {
1561                addSOAPHeader(call, name, (List JavaDoc) o);
1562            }
1563        } catch (WSIFException ex) {
1564            Trc.ignoredException(ex);
1565        }
1566    }
1567
1568    /**
1569     * Sets the SOAP headers in the message context.
1570     */

1571    private void addSOAPHeader(Call call, String JavaDoc name, List JavaDoc soapHeaders) {
1572        Header h = new Header();
1573        h.setHeaderEntries(new Vector JavaDoc(soapHeaders));
1574        call.setHeader(h);
1575    }
1576
1577    /**
1578     * Sets the HTTP header value if the underlying transport
1579     * is the SOAP HTTP transport. The only support HTTP headers
1580     * are the basic authentication user id and password.
1581     */

1582    private void addHTTPHeader(Call call, String JavaDoc name, String JavaDoc value) {
1583        SOAPTransport st = call.getSOAPTransport();
1584        if (st instanceof SOAPHTTPConnection) {
1585            SOAPHTTPConnection httpTransport = (SOAPHTTPConnection) st;
1586            if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) {
1587                httpTransport.setUserName(value);
1588            } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) {
1589                httpTransport.setPassword(value);
1590            }
1591        }
1592    }
1593
1594    /**
1595     * This adds any SOAP headers in the response to the context
1596     */

1597    private void addContextResponseSOAPHeaders(Header soapHeader)
1598        throws WSIFException {
1599
1600        if( soapHeader != null ) {
1601            Vector JavaDoc headerEntries = soapHeader.getHeaderEntries();
1602            if (headerEntries != null) {
1603                ArrayList JavaDoc headers = new ArrayList JavaDoc();
1604                for(Iterator JavaDoc i = headerEntries.iterator(); i.hasNext(); ) {
1605                    Object JavaDoc o = i.next();
1606                    if (o instanceof Element JavaDoc) {
1607                        headers.add(o);
1608                    } else {
1609                        Trc.event("unexpected response SOAP header type: ", o);
1610                    }
1611                }
1612                if (headers.size() > 0) {
1613                    WSIFMessage context = getContext();
1614                    context.setObjectPart(
1615                        WSIFConstants.CONTEXT_RESPONSE_SOAP_HEADERS,
1616                        headers);
1617                    setContext(context);
1618                }
1619            }
1620        }
1621    }
1622
1623    private boolean isHostInNonProxyProperty(URL JavaDoc u) {
1624        if ( u != null ) {
1625           String JavaDoc excludeList =
1626              (String JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
1627                 public Object JavaDoc run() {
1628                    return System.getProperty( PROXY_EXCLUDES_PROPERTY );
1629                 }
1630              });
1631           if ( excludeList != null ) {
1632              StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( excludeList, "|" );
1633              while ( st.hasMoreTokens() ) {
1634                 String JavaDoc xhost = st.nextToken().trim();
1635                 if ( WSIFUtils.wildcardCompare( xhost, u.getHost(), '*' ) ) {
1636                    return true;
1637                 }
1638              }
1639           }
1640        }
1641        return false;
1642    }
1643    
1644    /**
1645     * Unike axis, soap doesn't automatically use the Java
1646     * system properties for a proxy server, we need to set
1647     * it up manually.
1648     */

1649    private void setSOAPProxy(SOAPTransport st) {
1650        if (st instanceof SOAPHTTPConnection) {
1651           SOAPHTTPConnection shttpc = (SOAPHTTPConnection) st;
1652           String JavaDoc proxyHost =
1653              (String JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
1654                 public Object JavaDoc run() {
1655                    return System.getProperty( HTTP_PROXY_HOST_PROPERTY );
1656                 }
1657              });
1658           String JavaDoc proxyPort =
1659              (String JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
1660                 public Object JavaDoc run() {
1661                    return System.getProperty( HTTP_PROXY_PORT_PROPERTY );
1662                 }
1663              });
1664           if ( proxyHost != null && proxyHost.length() > 0 ) {
1665              shttpc.setProxyHost( proxyHost );
1666              if ( proxyPort != null && proxyPort.length() > 0 ) {
1667                 try {
1668                    int port = Integer.parseInt( proxyPort );
1669                    shttpc.setProxyPort( port );
1670                 } catch (NumberFormatException JavaDoc ex) {
1671                    Trc.ignoredException(ex);
1672                 }
1673              }
1674           }
1675        }
1676    }
1677
1678    private void checkForTimeoutProperties(SOAPTransport st, HashMap JavaDoc inJmsPropVals) {
1679       if (inJmsPropVals != null) {
1680          for (Iterator JavaDoc i = inJmsPropVals.keySet().iterator(); i.hasNext();) {
1681             String JavaDoc name = (String JavaDoc) i.next();
1682             Object JavaDoc value = inJmsPropVals.get(name);
1683             if (timeoutProperty(st, name, value)) {
1684                i.remove();
1685             }
1686          }
1687       }
1688    }
1689
1690    private boolean timeoutProperty(
1691        SOAPTransport t,
1692        String JavaDoc propertyName,
1693        Object JavaDoc value) {
1694        Trc.entry(this, t, propertyName, value);
1695        boolean isTimeoutProperty = false;
1696        if (t != null
1697        && t instanceof SOAPJMSConnection) {
1698           SOAPJMSConnection st = (SOAPJMSConnection) t;
1699           try {
1700              if (WSIFConstants.WSIF_PROP_SYNC_TIMEOUT.equals(propertyName)) {
1701                 isTimeoutProperty = true;
1702                 long syncTimeout = Long.parseLong(value.toString());
1703                 st.setSyncTimeout(syncTimeout);
1704                 Trc.event(this, "overridding syncTimeout to " + syncTimeout);
1705              } else if (
1706                 WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT.equals(propertyName)) {
1707                 isTimeoutProperty = true;
1708                 long asyncTimeout = Long.parseLong(value.toString());
1709                 st.setAsyncTimeout(asyncTimeout);
1710                 Trc.event(this, "overridding asyncTimeout to " + asyncTimeout);
1711              }
1712           } catch (NumberFormatException JavaDoc ex) {
1713              Trc.ignoredException(ex);
1714           }
1715        }
1716        Trc.exit(isTimeoutProperty);
1717        return isTimeoutProperty;
1718    }
1719
1720    public String JavaDoc deep() {
1721        String JavaDoc buff = "";
1722        try {
1723            buff = new String JavaDoc(super.toString() + ":\n");
1724            buff += " style:" + style;
1725            buff += " portInstance:" + portInstance;
1726            buff += " operation:" + Trc.brief(operation);
1727            buff += " definition:" + Trc.brief(definition);
1728            buff += " context:" + context;
1729            buff += " partNames:" + partNames;
1730            buff += Trc.brief("names", names);
1731            buff += Trc.brief("types", types);
1732            buff += " inputEncodingStyle:" + inputEncodingStyle;
1733            buff += " inputNamespace:" + inputNamespace;
1734            buff += " returnType:" + returnType;
1735            buff += " actionUri:" + actionUri;
1736            buff += " inJmsProps:" + inJmsProps;
1737            buff += " outJmsProps:" + outJmsProps;
1738            buff += " inJmsPropVals:" + inJmsPropVals;
1739            buff += " asyncOperation:" + asyncOperation;
1740            buff += " asyncRequestID:" + asyncRequestID;
1741            buff += " responseHandler:" + responseHandler;
1742            buff += " outputEncodingStyle:" + outputEncodingStyle;
1743            buff += " returnName:" + returnName;
1744            buff += " prepared:" + prepared;
1745            buff += " typeMap:" + typeMap;
1746            buff += " inputUse:" + inputUse;
1747            buff += " outputUse:" + outputUse;
1748            buff += " partSerializerName:" + partSerializerName;
1749        } catch (Exception JavaDoc e) {
1750            Trc.exceptionInTrace(e);
1751        }
1752        return buff;
1753    }
1754}
Popular Tags