1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.web.soap.client.soapclient;
7 
8 import diamond.http;
9 import diamond.web.soap.client.envelope;
10 
11 /// Wrapper around a soap client.
12 final class SoapClient
13 {
14   public:
15   final:
16   /// Creates a new soap client.
17   this() { }
18 
19   /**
20   * Sends a soap envelope to the specified url over HTTP.
21   * Params:
22   *   url =        The url of the soap method.
23   *   envelope =   The envelope to send.
24   *   soapAction = The soap action.
25   */
26   void sendHttp(string url, SoapEnvelope envelope, string soapAction = null)
27   {
28     sendHttp(HttpMethod.POST, url, envelope, soapAction);
29   }
30 
31   /**
32   * Sends a soap envelope to the specified url over HTTP.
33   * Params:
34   *   method =     The http method to send the soap envelope over.
35   *   url =        The url of the soap method.
36   *   envelope =   The envelope to send.
37   *   soapAction = The soap action.
38   */
39   void sendHttp(HttpMethod method, string url, SoapEnvelope envelope, string soapAction = null)
40   {
41     remoteRequest(url, method,
42       (scope responder)
43       {
44         // TODO: Convert the response into a proper soap response object ...
45         // TODO: Callback for the response creation
46         // TODO: Callback for the request creation
47       },
48       (scope requester)
49       {
50         import std..string : toLower;
51 
52         requester.contentType = "application/soap+xml; charset=" ~ envelope.xmlEncoding.toLower();
53 
54         if (soapAction && soapAction.length)
55         {
56           requester.headers["SOAPAction"] = soapAction;
57         }
58 
59         requester.bodyWriter.write(envelope.toString);
60       }
61     );
62   }
63 }