Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPClient.h
1 /*
2  *  Copyright 2001-2007 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/CredentialResolver.h>
27 #include <xmltooling/soap/SOAPTransport.h>
28
29 namespace soap11 {
30
31     class XMLTOOL_API Envelope;
32     class XMLTOOL_API Fault;
33
34     /**
35      * Implements SOAP 1.1 messaging over a transport.
36      * 
37      * In the abstract, this can be a one-way exchange, or use asynchronous
38      * transports, but this is mostly theoretical at this point.
39      */
40     class XMLTOOL_API SOAPClient
41     {
42         MAKE_NONCOPYABLE(SOAPClient);
43     public:
44         /**
45          * Constructor
46          * 
47          * @param validate  true iff schema validation should be used 
48          */
49         SOAPClient(bool validate=false) : m_validate(validate), m_transport(NULL) {}
50         
51         virtual ~SOAPClient();
52         
53         /**
54          * Controls schema validation of incoming XML messages.
55          * This is separate from other forms of programmatic validation of objects,
56          * but can detect a much wider range of syntax errors. 
57          * 
58          * @param validate  true iff the client should use a validating XML parser
59          */
60         void setValidating(bool validate=true) {
61             m_validate = validate;
62         }
63         
64         /**
65          * Sends the supplied envelope to the identified recipient/endpoint.
66          * 
67          * <p>The client object will instantiate a transport layer object
68          * appropriate for the endpoint URL provided and supply it to the
69          * prepareTransport() method below.
70          * 
71          * <p>To authenticate the server end, the transport layer object
72          * exposes a method to load a TrustEngine and CredentialResolver
73          * in a subclass-specific version of the prepareTransport() method.   
74          * 
75          * @param env           SOAP envelope to send
76          * @param peerName      name of peer
77          * @param endpoint      URL of endpoint to recieve message
78          */
79         virtual void send(const Envelope& env, const char* peerName, const char* endpoint);
80         
81         /**
82          * Returns the response message, if any. As long as a response is
83          * "expected" but not available, NULL will be returned. If no response
84          * will be forthcoming, an exception is raised.
85          * 
86          * <p>The caller is responsible for freeing the returned envelope.
87          */
88         virtual Envelope* receive();
89         
90         /**
91          * Resets the object for another call.
92          */
93         virtual void reset();
94
95     protected:
96         /**
97          * Allows client to supply transport-layer settings prior to sending message.
98          * 
99          * @param transport reference to transport layer
100          */
101         virtual void prepareTransport(xmltooling::SOAPTransport& transport) {}
102
103         /**
104          * Handling of SOAP faults.
105          * 
106          * @param fault SOAP Fault received by client
107          * @return true iff the Fault should be treated as a fatal error
108          */
109         virtual bool handleFault(const soap11::Fault& fault);
110             
111         /** Flag controlling schema validation. */
112         bool m_validate;
113
114         /** Holds response until retrieved by caller. */
115         xmltooling::SOAPTransport* m_transport;
116     };
117
118 };
119
120 #endif /* __xmltooling_soap11client_h__ */