27f262267bf8f7ec45e39361123b12c5c5dab4dd
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPClient.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/soap/SOAPClient.h
19  * 
20  * Implements SOAP 1.1 messaging over a transport.
21  */
22
23 #ifndef __xmltooling_soap11client_h__
24 #define __xmltooling_soap11client_h__
25
26 #include <xmltooling/soap/SOAPTransport.h>
27
28 namespace soap11 {
29
30     class XMLTOOL_API Envelope;
31     class XMLTOOL_API Fault;
32
33     /**
34      * Implements SOAP 1.1 messaging over a transport.
35      * 
36      * In the abstract, this can be a one-way exchange, or use asynchronous
37      * transports, but this is mostly theoretical at this point.
38      */
39     class XMLTOOL_API SOAPClient
40     {
41         MAKE_NONCOPYABLE(SOAPClient);
42     public:
43         /**
44          * Constructor
45          * 
46          * @param validate  true iff schema validation should be used 
47          */
48         SOAPClient(bool validate=false);
49         
50         virtual ~SOAPClient();
51         
52         /**
53          * Controls schema validation of incoming XML messages.
54          * This is separate from other forms of programmatic validation of objects,
55          * but can detect a much wider range of syntax errors. 
56          * 
57          * @param validate  true iff the client should use a validating XML parser
58          */
59         void setValidating(bool validate=true);
60         
61         /**
62          * Sends the supplied envelope to the identified recipient/endpoint.
63          *
64          * <p>The client object will instantiate a transport layer object
65          * appropriate for the endpoint URL provided and supply it to the
66          * prepareTransport() method below.
67          * 
68          * <p>To authenticate the server end, the transport layer object
69          * exposes a method to load a TrustEngine and CredentialResolver
70          * in a subclass-specific version of the prepareTransport() method.   
71          * 
72          * @param env           SOAP envelope to send
73          * @param addr          addressing information
74          */
75         virtual void send(const Envelope& env, const xmltooling::SOAPTransport::Address& addr);
76         
77         /**
78          * Returns the response message, if any. As long as a response is
79          * "expected" but not available, nullptr will be returned. If no response
80          * will be forthcoming, an exception is raised.
81          * 
82          * <p>The caller is responsible for freeing the returned envelope.
83          */
84         virtual Envelope* receive();
85         
86         /**
87          * Resets the object for another call.
88          */
89         virtual void reset();
90
91     protected:
92         /**
93          * Allows client to supply transport-layer settings prior to sending message.
94          * 
95          * @param transport reference to transport layer
96          */
97         virtual void prepareTransport(xmltooling::SOAPTransport& transport);
98
99         /**
100          * Handling of SOAP faults.
101          * 
102          * @param fault SOAP Fault received by client
103          * @return true iff the Fault should be treated as a fatal error
104          */
105         virtual bool handleFault(const soap11::Fault& fault);
106             
107         /** Flag controlling schema validation. */
108         bool m_validate;
109
110         /** Holds response until retrieved by caller. */
111         xmltooling::SOAPTransport* m_transport;
112     };
113
114 };
115
116 #endif /* __xmltooling_soap11client_h__ */