KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > MessageContext


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 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 "Axis" 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. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis;
57
58 import java.io.File JavaDoc;
59 import java.util.ArrayList JavaDoc;
60 import java.util.HashMap JavaDoc;
61 import java.util.Hashtable JavaDoc;
62
63 import javax.xml.namespace.QName JavaDoc;
64 import javax.xml.rpc.Call JavaDoc;
65 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
66
67 import org.jboss.axis.attachments.Attachments;
68 import org.jboss.axis.client.AxisClient;
69 import org.jboss.axis.description.OperationDesc;
70 import org.jboss.axis.description.ServiceDesc;
71 import org.jboss.axis.encoding.TypeMapping;
72 import org.jboss.axis.encoding.TypeMappingRegistry;
73 import org.jboss.axis.enums.Style;
74 import org.jboss.axis.enums.Use;
75 import org.jboss.axis.handlers.soap.SOAPService;
76 import org.jboss.axis.schema.SchemaVersion;
77 import org.jboss.axis.session.Session;
78 import org.jboss.axis.soap.SOAPConstants;
79 import org.jboss.axis.utils.JavaUtils;
80 import org.jboss.axis.utils.LockableHashtable;
81 import org.jboss.axis.utils.Messages;
82 import org.jboss.logging.Logger;
83
84 /**
85  * A MessageContext is the Axis implementation of the javax
86  * SOAPMessageContext class, and is core to message processing
87  * in handlers and other parts of the system.
88  * <p/>
89  * This class also contains constants for accessing some
90  * well-known properties. Using a hierarchical namespace is
91  * strongly suggested in order to lower the chance for
92  * conflicts.
93  * <p/>
94  * (These constants should be viewed as an explicit list of well
95  * known and widely used context keys, there's nothing wrong
96  * with directly using the key strings. This is the reason for
97  * the hierarchical constant namespace.
98  * <p/>
99  * Actually I think we might just list the keys in the docs and
100  * provide no such constants since they create yet another
101  * namespace, but we'd have no compile-time checks then.
102  * <p/>
103  * Whaddya think? - todo by Jacek)
104  *
105  * @author Doug Davis (dug@us.ibm.com)
106  * @author Jacek Kopecky (jacek@idoox.com)
107  */

108 public class MessageContext implements SOAPMessageContext JavaDoc
109 {
110    private static Logger log = Logger.getLogger(MessageContext.class.getName());
111
112    /**
113     * The request message. If we're on the client, this is the outgoing
114     * message heading to the server. If we're on the server, this is the
115     * incoming message we've received from the client.
116     */

117    private Message requestMessage;
118
119    /**
120     * The response message. If we're on the server, this is the outgoing
121     * message heading back to the client. If we're on the client, this is the
122     * incoming message we've received from the server.
123     */

124    private Message responseMessage;
125
126    /**
127     * That unique key/name that the next router/dispatch handler should use
128     * to determine what to do next.
129     */

130    private String JavaDoc targetService;
131
132    /**
133     * The name of the Transport which this message was received on (or is
134     * headed to, for the client).
135     */

136    private String JavaDoc transportName;
137
138    /**
139     * The default classloader that this service should use
140     */

141    private ClassLoader JavaDoc classLoader;
142
143    /**
144     * The AxisEngine which this context is involved with
145     */

146    private AxisEngine axisEngine;
147
148    /**
149     * A Session associated with this request.
150     */

151    private Session session;
152
153    /**
154     * Should we track session state, or not?
155     * default is not.
156     * Could potentially refactor this so that
157     * maintainSession iff session != null...
158     */

159    private boolean maintainSession = false;
160
161    /**
162     * Are we doing request stuff, or response stuff?
163     */

164    private boolean havePassedPivot = false;
165
166    /**
167     * Maximum amount of time to wait on a request, in milliseconds.
168     */

169    private int timeout = 60 * 1000; // 60 seconds
170

171    /**
172     * An indication of whether we require "high fidelity" recording of
173     * deserialized messages for this interaction. Defaults to true for
174     * now, and can be set to false, usually at service-dispatch time.
175     */

176    private boolean highFidelity = true;
177
178    /**
179     * Storage for an arbitrary bag of properties associated with this
180     * MessageContext.
181     */

182    private LockableHashtable bag = new LockableHashtable();
183
184    /**
185     * These variables are logically part of the bag, but are separated
186     * because they are used often and the Hashtable is more expensive.
187     */

188    private String JavaDoc username = null;
189    private String JavaDoc password = null;
190    private String JavaDoc encodingStyle = Use.ENCODED.getEncoding();
191    private boolean useSOAPAction = false;
192    private String JavaDoc SOAPActionURI = null;
193
194    /**
195     * Our SOAP namespaces and such
196     */

197    private SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION;
198
199    /**
200     * Schema version information - defaults to 2001
201     */

202    private SchemaVersion schemaVersion = SchemaVersion.SCHEMA_2001;
203
204    /**
205     * what is our current operation
206     */

207    private OperationDesc currentOperation = null;
208
209    /**
210     * Transport specific options, null is not allowed.
211     */

212    private HashMap JavaDoc transportOptions = new HashMap JavaDoc();
213
214    /**
215     * the current operation
216     *
217     * @return the current operation; may be null
218     */

219    public OperationDesc getOperation()
220    {
221       return currentOperation;
222    }
223
224    /**
225     * set the current operation
226     *
227     * @param operation
228     */

229    public void setOperation(OperationDesc operation)
230    {
231       currentOperation = operation;
232    }
233
234    /**
235     * getPossibleOperationsByQName
236     * Returns a list of operation descriptors that could may
237     * possibly match a body containing an element of the given QName.
238     * For non-DOCUMENT, the list of operation descriptors that match
239     * the name is returned. For DOCUMENT, all the operations that have
240     * qname as a parameter are returned
241     *
242     * @param qname of the first element in the body
243     * @return list of operation descriptions
244     */

245    public OperationDesc[] getPossibleOperationsByQName(QName JavaDoc qname) throws AxisFault
246    {
247       if (currentOperation != null)
248       {
249          return new OperationDesc[]{currentOperation};
250       }
251
252       OperationDesc[] possibleOperations = null;
253
254       if (serviceHandler == null)
255       {
256          try
257          {
258             if (log.isDebugEnabled())
259             {
260                log.debug(Messages.getMessage("dispatching00",
261                        qname.getNamespaceURI()));
262             }
263
264             // Try looking this QName up in our mapping table...
265
setService(axisEngine.getConfig().
266                     getServiceByNamespaceURI(qname.getNamespaceURI()));
267          }
268          catch (ConfigurationException e)
269          {
270             // Didn't find one...
271
}
272
273       }
274
275       if (serviceHandler != null)
276       {
277          ServiceDesc desc = serviceHandler.getInitializedServiceDesc(this);
278
279          if (desc != null)
280          {
281             if (desc.getStyle() != Style.DOCUMENT)
282             {
283                possibleOperations = desc.getOperationsByQName(qname);
284             }
285             else
286             {
287                // DOCUMENT Style
288
// Get all of the operations that have qname as
289
// a possible parameter QName
290
ArrayList JavaDoc allOperations = desc.getOperations();
291                ArrayList JavaDoc foundOperations = new ArrayList JavaDoc();
292                for (int i = 0; i < allOperations.size(); i++)
293                {
294                   OperationDesc tryOp = (OperationDesc)allOperations.get(i);
295                   if (tryOp.getParamByQName(qname) != null)
296                   {
297                      foundOperations.add(tryOp);
298                   }
299                   // try again, using just localPart this time
300
else if (tryOp.getParamByQName(new QName JavaDoc(null, qname.getLocalPart())) != null)
301                   {
302                      foundOperations.add(tryOp);
303                   }
304                }
305
306                if (foundOperations.size() == 0)
307                   log.debug("Cannot find any doc style operations with param: " + qname);
308
309                // Convert list to array
310
if (foundOperations.size() > 0)
311                {
312                   possibleOperations = (OperationDesc[])JavaUtils.convert(foundOperations, OperationDesc[].class);
313                }
314             }
315          }
316       }
317
318       if (possibleOperations == null)
319          log.debug("Cannot find any operations for: " + qname);
320
321       return possibleOperations;
322    }
323
324    /**
325     * get the first possible operation that could match a
326     * body containing an element of the given QName. Sets the currentOperation
327     * field in the process; if that field is already set then its value
328     * is returned instead
329     *
330     * @param qname name of the message body
331     * @return an operation or null
332     * @throws AxisFault
333     */

334    public OperationDesc getOperationByQName(QName JavaDoc qname) throws AxisFault
335    {
336       if (currentOperation == null)
337       {
338          OperationDesc[] possibleOperations = getPossibleOperationsByQName(qname);
339          if (possibleOperations != null && possibleOperations.length > 0)
340          {
341             currentOperation = possibleOperations[0];
342          }
343       }
344
345       return currentOperation;
346    }
347
348    /**
349     * Get the active message context.
350     *
351     * @return the current active message context
352     */

353    public static MessageContext getCurrentContext()
354    {
355       return AxisEngine.getCurrentMessageContext();
356    }
357
358    /**
359     * temporary directory to store attachments
360     */

361    protected static String JavaDoc systemTempDir = null;
362    /**
363     * set the temp dir
364     * TODO: move this piece of code out of this class and into a utilities
365     * class.
366     */

367    static
368    {
369       try
370       {
371          //get the temp dir from the engine
372
systemTempDir = AxisProperties.getProperty(AxisEngine.ENV_ATTACHMENT_DIR);
373       }
374       catch (Throwable JavaDoc t)
375       {
376          systemTempDir = null;
377       }
378
379       if (systemTempDir == null)
380       {
381          try
382          {
383             //or create and delete a file in the temp dir to make
384
//sure we have write access to it.
385
File JavaDoc tf = File.createTempFile("Axis", "Axis");
386             File JavaDoc dir = tf.getParentFile();
387             if (tf.exists())
388             {
389                tf.delete();
390             }
391             if (dir != null)
392             {
393                systemTempDir = dir.getCanonicalPath();
394             }
395          }
396          catch (Throwable JavaDoc t)
397          {
398             log.debug("Unable to find a temp dir with write access");
399             systemTempDir = null;
400          }
401       }
402    }
403
404    /**
405     * Create a message context.
406     *
407     * @param engine the controlling axis engine. Null is actually accepted here,
408     * though passing a null engine in is strongly discouraged as many of the methods
409     * assume that it is in fact defined.
410     */

411    public MessageContext(AxisEngine engine)
412    {
413       this.axisEngine = engine;
414
415       if (null != engine)
416       {
417          java.util.Hashtable JavaDoc opts = engine.getOptions();
418          String JavaDoc attachmentsdir = null;
419          if (null != opts)
420          {
421             attachmentsdir = (String JavaDoc)opts.get(AxisEngine.PROP_ATTACHMENT_DIR);
422          }
423          if (null == attachmentsdir)
424          {
425             attachmentsdir = systemTempDir;
426          }
427          if (attachmentsdir != null)
428          {
429             setProperty(ATTACHMENTS_DIR, attachmentsdir);
430          }
431
432          // If SOAP 1.2 has been specified as the default for the engine,
433
// switch the constants over.
434
String JavaDoc defaultSOAPVersion = (String JavaDoc)engine.getOption(AxisEngine.PROP_SOAP_VERSION);
435          if (defaultSOAPVersion != null && "1.2".equals(defaultSOAPVersion))
436          {
437             setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
438          }
439
440          String JavaDoc singleSOAPVersion = (String JavaDoc)engine.getOption(AxisEngine.PROP_SOAP_ALLOWED_VERSION);
441          if (singleSOAPVersion != null)
442          {
443             if ("1.2".equals(singleSOAPVersion))
444             {
445                setProperty(Constants.MC_SINGLE_SOAP_VERSION,
446                        SOAPConstants.SOAP12_CONSTANTS);
447             }
448             else if ("1.1".equals(singleSOAPVersion))
449             {
450                setProperty(Constants.MC_SINGLE_SOAP_VERSION,
451                        SOAPConstants.SOAP11_CONSTANTS);
452             }
453          }
454       }
455    }
456
457    /**
458     * Mappings of QNames to serializers/deserializers (and therfore
459     * to Java types).
460     */

461    private TypeMappingRegistry mappingRegistry = null;
462
463    /**
464     * replace the engine's type mapping registry with a local one
465     *
466     * @param reg
467     */

468    public void setTypeMappingRegistry(TypeMappingRegistry reg)
469    {
470       mappingRegistry = reg;
471    }
472
473    /**
474     * Get the currently in-scope type mapping registry.
475     * <p/>
476     * By default, will return a reference to the AxisEngine's TMR until
477     * someone sets our local one (usually as a result of setting the
478     * serviceHandler).
479     *
480     * @return the type mapping registry to use for this request.
481     */

482    public TypeMappingRegistry getTypeMappingRegistry()
483    {
484       if (mappingRegistry == null)
485       {
486          return axisEngine.getTypeMappingRegistry();
487       }
488
489       return mappingRegistry;
490    }
491
492    /**
493     * Return the type mapping currently in scope for our encoding style
494     */

495    public TypeMapping getTypeMapping()
496    {
497       return (TypeMapping)getTypeMappingRegistry().
498               getTypeMapping(encodingStyle);
499    }
500
501    /**
502     * Transport
503     */

504    public String JavaDoc getTransportName()
505    {
506       return transportName;
507    }
508
509    public void setTransportName(String JavaDoc transportName)
510    {
511       this.transportName = transportName;
512    }
513
514    /**
515     * SOAP constants
516     */

517    public SOAPConstants getSOAPConstants()
518    {
519       return soapConstants;
520    }
521
522    public void setSOAPConstants(SOAPConstants soapConstants)
523    {
524       // when changing SOAP versions, remember to keep the encodingURI
525
// in synch.
526
if (this.soapConstants.getEncodingURI().equals(encodingStyle))
527       {
528          encodingStyle = soapConstants.getEncodingURI();
529       }
530
531       this.soapConstants = soapConstants;
532    }
533
534    /**
535     * Schema version information
536     */

537
538    public SchemaVersion getSchemaVersion()
539    {
540       return schemaVersion;
541    }
542
543    public void setSchemaVersion(SchemaVersion schemaVersion)
544    {
545       this.schemaVersion = schemaVersion;
546    }
547
548    /**
549     * Sessions
550     */

551    public Session getSession()
552    {
553       return session;
554    }
555
556    public void setSession(Session session)
557    {
558       this.session = session;
559    }
560
561    /**
562     * Encoding
563     */

564    public boolean isEncoded()
565    {
566       return (getOperationUse() == Use.ENCODED);
567       //return soapConstants.getEncodingURI().equals(encodingStyle);
568
}
569
570    /**
571     * Set whether we are maintaining session state
572     *
573     * @param yesno flag to set to true to maintain sessions
574     */

575    public void setMaintainSession(boolean yesno)
576    {
577       maintainSession = yesno;
578    }
579
580    /**
581     * Are we maintaining session state?
582     */

583    public boolean getMaintainSession()
584    {
585       return maintainSession;
586    }
587
588    /**
589     * Get the request message.
590     *
591     * @return the request message (may be null).
592     */

593    public Message getRequestMessage()
594    {
595       return requestMessage;
596    };
597
598    /**
599     * Set the request message, and make sure that message is associated
600     * with this MessageContext.
601     *
602     * @param reqMsg the new request Message.
603     */

604    public void setRequestMessage(Message reqMsg)
605    {
606       requestMessage = reqMsg;
607       if (requestMessage != null)
608       {
609          requestMessage.setMessageContext(this);
610       }
611    };
612
613    /**
614     * Get the response message.
615     *
616     * @return the response message (may be null).
617     */

618    public Message getResponseMessage()
619    {
620       return responseMessage;
621    }
622
623    /**
624     * Set the response message, and make sure that message is associated
625     * with this MessageContext.
626     *
627     * @param respMsg the new response Message.
628     */

629    public void setResponseMessage(Message respMsg)
630    {
631       responseMessage = respMsg;
632       if (responseMessage != null)
633       {
634          responseMessage.setMessageContext(this);
635
636          //if we have received attachments of a particular type
637
// than that should be the default type to send.
638
Message reqMsg = getRequestMessage();
639          if (null != reqMsg)
640          {
641             Attachments reqAttch = reqMsg.getAttachmentsImpl();
642             Attachments respAttch = respMsg.getAttachmentsImpl();
643             if (null != reqAttch && null != respAttch)
644             {
645                if (respAttch.getSendType() == Attachments.SEND_TYPE_NOTSET)
646                //only if not explicity set.
647
respAttch.setSendType(reqAttch.getSendType());
648             }
649          }
650       }
651    }
652
653    /**
654     * Return the current (i.e. request before the pivot, response after)
655     * message.
656     */

657    public Message getCurrentMessage()
658    {
659       return (havePassedPivot ? responseMessage : requestMessage);
660    }
661
662    /**
663     * Gets the SOAPMessage from this message context
664     *
665     * @return Returns the SOAPMessage; returns null if no request
666     * SOAPMessage is present in this SOAPMessageContext
667     */

668    public javax.xml.soap.SOAPMessage JavaDoc getMessage()
669    {
670       return getCurrentMessage();
671    }
672
673    /**
674     * Set the current (i.e. request before the pivot, response after)
675     * message.
676     */

677    public void setCurrentMessage(Message curMsg)
678    {
679       curMsg.setMessageContext(this);
680
681       if (havePassedPivot)
682       {
683          responseMessage = curMsg;
684       }
685       else
686       {
687          requestMessage = curMsg;
688       }
689    }
690
691    /**
692     * Sets the SOAPMessage for this message context
693     *
694     * @param message Request SOAP message
695     * @throws java.lang.UnsupportedOperationException
696     * If this
697     * operation is not supported
698     */

699    public void setMessage(javax.xml.soap.SOAPMessage JavaDoc message)
700    {
701       setCurrentMessage((Message)message);
702    }
703
704    /**
705     * Determine when we've passed the pivot
706     */

707    public boolean getPastPivot()
708    {
709       return havePassedPivot;
710    }
711
712    /**
713     * Indicate when we've passed the pivot
714     */

715    public void setPastPivot(boolean pastPivot)
716    {
717       havePassedPivot = pastPivot;
718    }
719
720    /**
721     * Set timeout in our MessageContext.
722     *
723     * @param value the maximum amount of time, in milliseconds
724     */

725    public void setTimeout(int value)
726    {
727       timeout = value;
728    }
729
730    /**
731     * Get timeout from our MessageContext.
732     *
733     * @return value the maximum amount of time, in milliseconds
734     */

735    public int getTimeout()
736    {
737       return timeout;
738    }
739
740    public Object JavaDoc getTransportOption(String JavaDoc name)
741    {
742       Object JavaDoc transOpt = transportOptions.get(name);
743       return transOpt;
744    }
745
746    public void setTransportOption(String JavaDoc name, Object JavaDoc value)
747    {
748       transportOptions.put(name, value);
749    }
750
751    public HashMap JavaDoc getTransportOptions()
752    {
753       return transportOptions;
754    }
755
756    /**
757     * get the classloader, implicitly binding to the thread context
758     * classloader if an override has not been supplied
759     *
760     * @return
761     */

762    public ClassLoader JavaDoc getClassLoader()
763    {
764       if (classLoader == null)
765       {
766          classLoader = Thread.currentThread().getContextClassLoader();
767       }
768       return (classLoader);
769    }
770
771    /**
772     * set a new classloader
773     *
774     * @param cl
775     */

776    public void setClassLoader(ClassLoader JavaDoc cl)
777    {
778       classLoader = cl;
779    }
780
781    public String JavaDoc getTargetService()
782    {
783       return (targetService);
784    }
785
786    /**
787     * get the axis engine. Will be null if the message was created outside
788     * an engine
789     *
790     * @return the current axis engine
791     */

792    public AxisEngine getAxisEngine()
793    {
794       return axisEngine;
795    }
796
797    /**
798     * Set the target service for this message.
799     * <p/>
800     * This looks up the named service in the registry, and has
801     * the side effect of setting our TypeMappingRegistry to the
802     * service's.
803     *
804     * @param tServ the name of the target service.
805     */

806    public void setTargetService(String JavaDoc tServ) throws AxisFault
807    {
808       log.debug("MessageContext: setTargetService(" + tServ + ")");
809
810       if (tServ == null)
811       {
812          setService(null);
813       }
814       else
815       {
816          try
817          {
818             SOAPService service = getAxisEngine().getService(tServ);
819             setService(service);
820          }
821          catch (AxisFault fault)
822          {
823             // If we're on the client, don't throw this fault...
824
if (!isClient())
825             {
826                throw fault;
827             }
828          }
829       }
830       targetService = tServ;
831    }
832
833    /**
834     * ServiceHandler is the handler that is the "service". This handler
835     * can (and probably will actually be a chain that contains the
836     * service specific request/response/pivot point handlers
837     */

838    private SOAPService serviceHandler;
839
840    public SOAPService getService()
841    {
842       return (serviceHandler);
843    }
844
845    public void setService(SOAPService sh) throws AxisFault
846    {
847       log.debug("MessageContext: setServiceHandler(" + sh + ")");
848       serviceHandler = sh;
849       if (sh != null)
850       {
851          targetService = sh.getName();
852          SOAPService service = sh;
853          TypeMappingRegistry tmr = service.getTypeMappingRegistry();
854          setTypeMappingRegistry(tmr);
855
856          // styles are not "soap version aware" so compensate...
857
setEncodingStyle(service.getUse().getEncoding());
858
859          // This MessageContext should now defer properties it can't find
860
// to the Service's options.
861
bag.setParent(sh.getOptions());
862
863          // Note that we need (or don't need) high-fidelity SAX recording
864
// of deserialized messages according to the setting on the
865
// new service.
866
highFidelity = service.needsHighFidelityRecording();
867
868          service.getInitializedServiceDesc(this);
869       }
870    }
871
872    /**
873     * Let us know whether this is the client or the server.
874     */

875    public boolean isClient()
876    {
877       return (axisEngine instanceof AxisClient);
878    }
879
880    /**
881     * Contains an instance of Handler, which is the
882     * ServiceContext and the entrypoint of this service.
883     * <p/>
884     * (if it has been so configured - will our deployment
885     * tool do this by default? - todo by Jacek)
886     */

887    public final static String JavaDoc ENGINE_HANDLER = "engine.handler";
888
889    /**
890     * This String is the URL that the message came to
891     */

892    public final static String JavaDoc TRANS_URL = "transport.url";
893
894    /**
895     * Has a quit been requested? Hackish... but useful... -- RobJ
896     */

897    public final static String JavaDoc QUIT_REQUESTED = "quit.requested";
898
899    /**
900     * Place to store an AuthenticatedUser
901     */

902    public final static String JavaDoc AUTHUSER = "authenticatedUser";
903
904    /**
905     * If on the client - this is the Call object
906     */

907    public final static String JavaDoc CALL = "call_object";
908
909    /**
910     * Are we doing Msg vs RPC? - For Java Binding
911     */

912    public final static String JavaDoc IS_MSG = "isMsg";
913
914    /**
915     * The directory where in coming attachments are created.
916     */

917    public final static String JavaDoc ATTACHMENTS_DIR = "attachments.directory";
918
919    /**
920     * A boolean param, to control whether we accept missing parameters
921     * as nulls or refuse to acknowledge them.
922     */

923    public final static String JavaDoc ACCEPTMISSINGPARAMS = "acceptMissingParams";
924
925    /**
926     * The value of the property is used by service WSDL generation (aka ?WSDL)
927     * For the service's interface namespace if not set TRANS_URL property is used.
928     */

929    public final static String JavaDoc WSDLGEN_INTFNAMESPACE = "axis.wsdlgen.intfnamespace";
930
931    /**
932     * The value of the property is used by service WSDL generation (aka ?WSDL)
933     * For the service's location if not set TRANS_URL property is used.
934     * (helps provide support through proxies.
935     */

936    public final static String JavaDoc WSDLGEN_SERV_LOC_URL = "axis.wsdlgen.serv.loc.url";
937
938    /**
939     * The value of the property is used by service WSDL generation (aka ?WSDL)
940     * If the wsdl documnet contains imports, this property is the relative path to the imported artifact.
941     */

942    public final static String JavaDoc WSDLGEN_RESOURCE = "axis.wsdlgen.resource";
943
944    /**
945     * The value of the property is used by service WSDL generation (aka ?WSDL)
946     * Set this property to request a certain level of HTTP.
947     * The values MUST use org.jboss.axis.transport.http.HTTPConstants.HEADER_PROTOCOL_10
948     * for HTTP 1.0
949     * The values MUST use org.jboss.axis.transport.http.HTTPConstants.HEADER_PROTOCOL_11
950     * for HTTP 1.1
951     */

952    public final static String JavaDoc HTTP_TRANSPORT_VERSION = "axis.transport.version";
953
954    public static final String JavaDoc SECURITY_PROVIDER = "securityProvider";
955
956    /*
957     * IMPORTANT.
958     * If adding any new constants to this class. Make them final. The
959     * ones above are left non-final for compatibility reasons.
960     */

961
962    /**
963     * Just a util so we don't have to cast the result
964     */

965    public String JavaDoc getStrProp(String JavaDoc propName)
966    {
967       return ((String JavaDoc)getProperty(propName));
968    }
969
970    /**
971     * Tests to see if the named property is set in the 'bag'.
972     * If not there then 'false' is returned.
973     * If there, then...
974     * if its a Boolean, we'll return booleanValue()
975     * if its an Integer, we'll return 'false' if its '0' else 'true'
976     * if its a String, we'll return 'false' if its 'false' or '0' else 'true'
977     * All other types return 'true'
978     */

979    public boolean isPropertyTrue(String JavaDoc propName)
980    {
981       return isPropertyTrue(propName, false);
982    }
983
984    /**
985     * Tests to see if the named property is set in the 'bag'.
986     * If not there then 'defaultVal' will be returned.
987     * If there, then...
988     * if its a Boolean, we'll return booleanValue()
989     * if its an Integer, we'll return 'false' if its '0' else 'true'
990     * if its a String, we'll return 'false' if its 'false', 'no', or '0' - else 'true'
991     * All other types return 'true'
992     */

993    public boolean isPropertyTrue(String JavaDoc propName, boolean defaultVal)
994    {
995       return JavaUtils.isTrue(getProperty(propName), defaultVal);
996    }
997
998    /**
999     * Allows you to set a named property to the passed in value.
1000    * There are a few known properties (like username, password, etc)
1001    * that are variables in Call. The rest of the properties are
1002    * stored in a Hashtable. These common properties should be
1003    * accessed via the accessors for speed/type safety, but they may
1004    * still be obtained via this method. It's up to one of the
1005    * Handlers (or the Axis engine itself) to go looking for
1006    * one of them.
1007    *
1008    * @param name Name of the property
1009    * @param value Value of the property
1010    */

1011   public void setProperty(String JavaDoc name, Object JavaDoc value)
1012   {
1013      if (name == null || value == null)
1014      {
1015         return;
1016         // Is this right? Shouldn't we throw an exception like:
1017
// throw new IllegalArgumentException(msg);
1018
}
1019      else if (name.equals(Call.USERNAME_PROPERTY))
1020      {
1021         if (!(value instanceof String JavaDoc))
1022         {
1023            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]{
1024               name, "java.lang.String", value.getClass().getName()}));
1025         }
1026         setUsername((String JavaDoc)value);
1027      }
1028      else if (name.equals(Call.PASSWORD_PROPERTY))
1029      {
1030         if (!(value instanceof String JavaDoc))
1031         {
1032            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]{
1033               name, "java.lang.String", value.getClass().getName()}));
1034         }
1035         setPassword((String JavaDoc)value);
1036      }
1037      else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY))
1038      {
1039         if (!(value instanceof Boolean JavaDoc))
1040         {
1041            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]
1042            {name,
1043             "java.lang.Boolean",
1044             value.getClass().getName()}));
1045         }
1046         setMaintainSession(((Boolean JavaDoc)value).booleanValue());
1047      }
1048      else if (name.equals(Call.SOAPACTION_USE_PROPERTY))
1049      {
1050         if (!(value instanceof Boolean JavaDoc))
1051         {
1052            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]
1053            {name,
1054             "java.lang.Boolean",
1055             value.getClass().getName()}));
1056         }
1057         setUseSOAPAction(((Boolean JavaDoc)value).booleanValue());
1058      }
1059      else if (name.equals(Call.SOAPACTION_URI_PROPERTY))
1060      {
1061         if (!(value instanceof String JavaDoc))
1062         {
1063            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]
1064            {name,
1065             "java.lang.String",
1066             value.getClass().getName()}));
1067         }
1068         setSOAPActionURI((String JavaDoc)value);
1069      }
1070      else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY))
1071      {
1072         if (!(value instanceof String JavaDoc))
1073         {
1074            throw new IllegalArgumentException JavaDoc(Messages.getMessage("badProp00", new String JavaDoc[]
1075            {name,
1076             "java.lang.String",
1077             value.getClass().getName()}));
1078         }
1079         setEncodingStyle((String JavaDoc)value);
1080      }
1081      else
1082      {
1083         bag.put(name, value);
1084      }
1085   } // setProperty
1086

1087   /**
1088    * Returns true if the MessageContext contains a property with the specified name.
1089    *
1090    * @param name Name of the property whose presense is to be tested
1091    * @return Returns true if the MessageContext contains the
1092    * property; otherwise false
1093    */

1094   public boolean containsProperty(String JavaDoc name)
1095   {
1096      Object JavaDoc propertyValue = getProperty(name);
1097      return (propertyValue != null);
1098   }
1099
1100   /**
1101    * Returns an Iterator view of the names of the properties in this MessageContext
1102    *
1103    * @return Iterator for the property names
1104    */

1105   public java.util.Iterator JavaDoc getPropertyNames()
1106   {
1107      return bag.keySet().iterator();
1108   }
1109
1110   /**
1111    * Returns the value associated with the named property - or null if not
1112    * defined/set.
1113    *
1114    * @return Object value of the property - or null
1115    */

1116   public Object JavaDoc getProperty(String JavaDoc name)
1117   {
1118      if (name != null)
1119      {
1120         if (name.equals(Call.USERNAME_PROPERTY))
1121         {
1122            return getUsername();
1123         }
1124         else if (name.equals(Call.PASSWORD_PROPERTY))
1125         {
1126            return getPassword();
1127         }
1128         else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY))
1129         {
1130            return new Boolean JavaDoc(getMaintainSession());
1131         }
1132         else if (name.equals(Call.OPERATION_STYLE_PROPERTY))
1133         {
1134            return (getOperationStyle() == null) ? null : getOperationStyle().getName();
1135         }
1136         else if (name.equals(Call.SOAPACTION_USE_PROPERTY))
1137         {
1138            return new Boolean JavaDoc(useSOAPAction());
1139         }
1140         else if (name.equals(Call.SOAPACTION_URI_PROPERTY))
1141         {
1142            return getSOAPActionURI();
1143         }
1144         else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY))
1145         {
1146            return getEncodingStyle();
1147         }
1148         else if (bag == null)
1149         {
1150            return null;
1151         }
1152         else
1153         {
1154            return bag.get(name);
1155         }
1156      }
1157      else
1158      {
1159         return null;
1160      }
1161   }
1162
1163   public void setPropertyParent(Hashtable JavaDoc parent)
1164   {
1165      bag.setParent(parent);
1166   }
1167
1168   /**
1169    * Set the username.
1170    */

1171   public void setUsername(String JavaDoc username)
1172   {
1173      this.username = username;
1174   } // setUsername
1175

1176   /**
1177    * Get the user name
1178    */

1179   public String JavaDoc getUsername()
1180   {
1181      return username;
1182   } // getUsername
1183

1184   /**
1185    * Set the password.
1186    */

1187   public void setPassword(String JavaDoc password)
1188   {
1189      this.password = password;
1190   } // setPassword
1191

1192   /**
1193    * Get the password
1194    */

1195   public String JavaDoc getPassword()
1196   {
1197      return password;
1198   } // getPassword
1199

1200   /**
1201    * Get the operation style.
1202    */

1203   public Style getOperationStyle()
1204   {
1205      if (currentOperation != null)
1206      {
1207         return currentOperation.getStyle();
1208      }
1209
1210      if (serviceHandler != null)
1211      {
1212         return serviceHandler.getStyle();
1213      }
1214
1215      return Style.RPC;
1216   } // getOperationStyle
1217

1218   /**
1219    * Get the operation use.
1220    */

1221   public Use getOperationUse()
1222   {
1223      if (currentOperation != null)
1224      {
1225         return currentOperation.getUse();
1226      }
1227
1228      if (serviceHandler != null)
1229      {
1230         return serviceHandler.getUse();
1231      }
1232
1233      return Use.ENCODED;
1234   } // getOperationUse
1235

1236   /**
1237    * Should soapAction be used?
1238    */

1239   public void setUseSOAPAction(boolean useSOAPAction)
1240   {
1241      this.useSOAPAction = useSOAPAction;
1242   } // setUseSOAPAction
1243

1244   /**
1245    * Are we using soapAction?
1246    */

1247   public boolean useSOAPAction()
1248   {
1249      return useSOAPAction;
1250   } // useSOAPAction
1251

1252   /**
1253    * Set the soapAction URI.
1254    */

1255   public void setSOAPActionURI(String JavaDoc SOAPActionURI)
1256           throws IllegalArgumentException JavaDoc
1257   {
1258      this.SOAPActionURI = SOAPActionURI;
1259   } // setSOAPActionURI
1260

1261   /**
1262    * Get the soapAction URI.
1263    */

1264   public String JavaDoc getSOAPActionURI()
1265   {
1266      return SOAPActionURI;
1267   } // getSOAPActionURI
1268

1269   /**
1270    * Sets the encoding style to the URI passed in.
1271    *
1272    * @param namespaceURI URI of the encoding to use.
1273    */

1274   public void setEncodingStyle(String JavaDoc namespaceURI)
1275   {
1276      if (namespaceURI == null)
1277      {
1278         namespaceURI = Constants.URI_LITERAL_ENC;
1279      }
1280      else if (Constants.isSOAP_ENC(namespaceURI))
1281      {
1282         namespaceURI = soapConstants.getEncodingURI();
1283      }
1284
1285      encodingStyle = namespaceURI;
1286   } // setEncodingStype
1287

1288   /**
1289    * Returns the encoding style as a URI that should be used for the SOAP
1290    * message.
1291    *
1292    * @return String URI of the encoding style to use
1293    */

1294   public String JavaDoc getEncodingStyle()
1295   {
1296      return encodingStyle;
1297   } // getEncodingStyle
1298

1299   public void removeProperty(String JavaDoc propName)
1300   {
1301      if (bag != null)
1302      {
1303         bag.remove(propName);
1304      }
1305   }
1306
1307   public void reset()
1308   {
1309      if (bag != null)
1310      {
1311         bag.clear();
1312      }
1313      serviceHandler = null;
1314      havePassedPivot = false;
1315      currentOperation = null;
1316   }
1317
1318   public boolean isHighFidelity()
1319   {
1320      return highFidelity;
1321   }
1322
1323   public void setHighFidelity(boolean highFidelity)
1324   {
1325      this.highFidelity = highFidelity;
1326   }
1327
1328   /**
1329    * <i>Not (yet) implemented method in the SOAPMessageContext interface</i>
1330    * <p/>
1331    * Gets the SOAP actor roles associated with an execution of the HandlerChain and its contained Handler instances.
1332    * Note that SOAP actor roles apply to the SOAP node and are managed using HandlerChain.setRoles and
1333    * HandlerChain.getRoles. Handler instances in the HandlerChain use this information about the SOAP actor roles
1334    * to process the SOAP header blocks. Note that the SOAP actor roles are invariant during the processing of
1335    * SOAP message through the HandlerChain.
1336    *
1337    * @return Array of URIs for SOAP actor roles
1338    * @see javax.xml.rpc.handler.HandlerChain#setRoles(java.lang.String[]) HandlerChain.setRoles(java.lang.String[])
1339    * @see javax.xml.rpc.handler.HandlerChain#getRoles() HandlerChain.getRoles()
1340    */

1341   public String JavaDoc[] getRoles()
1342   {
1343      //TODO: Flesh this out.
1344
return null;
1345   }
1346}
1347
Popular Tags