Basic SOAP client, reworked transport streams.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPClient.h
1 /*
2  *  Copyright 2001-2006 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/security/KeyInfoSource.h>
27 #include <xmltooling/soap/SOAPTransport.h>
28
29 namespace soap11 {
30
31     class XMLTOOL_API Envelope;
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         SOAPClient() : m_validate(false), m_transport(NULL) {}
44         virtual ~SOAPClient();
45         
46         /**
47          * Controls schema validation of incoming XML messages.
48          * This is separate from other forms of programmatic validation of objects,
49          * but can detect a much wider range of syntax errors. 
50          * 
51          * @param validate  true iff the client should use a validating XML parser
52          */
53         void setValidating(bool validate=true) {
54             m_validate = validate;
55         }
56         
57         /**
58          * Sends the supplied envelope to the identified recipient/endpoint.
59          * 
60          * <p>The client object will instantiate a transport layer object
61          * appropriate for the endpoint URL provided and supply it to the
62          * prepareTransport() method below.
63          * 
64          * @param env       SOAP envelope to send
65          * @param peer      peer to send message to, expressed in TrustEngine terms
66          * @param endpoint  URL of endpoint to recieve message
67          */
68         virtual void send(const Envelope* env, const xmltooling::KeyInfoSource& peer, const char* endpoint);
69         
70         /**
71          * Returns the response message, if any. As long as a response is
72          * "expected" but not available, NULL will be returned. If no response
73          * will be forthcoming, an exception is raised.
74          * 
75          * <p>The caller is responsible for freeing the returned envelope.
76          * 
77          * <p>Once a response is returned, the object will be reset for a subsequent call.
78          */
79         virtual Envelope* receive();
80         
81         /**
82          * Resets the object for another call.
83          */
84         virtual void reset();
85
86     protected:
87         /**
88          * Allows client to supply transport-layer settings prior to sending message.
89          * 
90          * @param transport reference to transport layer
91          */
92         virtual void prepareTransport(const xmltooling::SOAPTransport& transport) {}
93         
94         /** Flag controlling schema validation. */
95         bool m_validate;
96
97         /** Holds response until retrieved by caller. */
98         xmltooling::SOAPTransport* m_transport;
99     };
100
101 };
102
103 #endif /* __xmltooling_soap11client_h__ */