soap 0.1.0.1 → 0.1.0.3
raw patch · 2 files changed
+32/−16 lines, 2 filesdep +resourcetdep +tls-extraPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: resourcet, tls-extra
API changes (from Hackage documentation)
+ Web.SOAP.Service: invokeWS' :: (ToNodes h, ToNodes i, FromCursor o) => (Request (ResourceT IO) -> Request (ResourceT IO)) -> SOAPSettings -> Text -> h -> i -> IO o
Files
- soap.cabal +3/−2
- src/Web/SOAP/Service.hs +29/−14
soap.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: soap-version: 0.1.0.1+version: 0.1.0.3 synopsis: SOAP client tools description: Tools to build SOAP clients using xml-conduit. homepage: https://bitbucket.org/dpwiz/haskell-soap@@ -17,13 +17,14 @@ library hs-source-dirs: src/+ ghc-options: -Wall -O2 exposed-modules: Web.SOAP.Service Web.SOAP.Types -- other-modules: build-depends: base ==4.*,- http-conduit,+ http-conduit, resourcet, tls-extra, xml-conduit, iconv, text,
src/Web/SOAP/Service.hs view
@@ -1,12 +1,15 @@-{-# LANGUAGE OverloadedStrings, RecordWildCards #-}+{-# LANGUAGE OverloadedStrings, RecordWildCards, Rank2Types, KindSignatures #-} module Web.SOAP.Service ( SOAPSettings(..) , invokeWS+ , invokeWS' ) where import Text.XML import Text.XML.Cursor import Network.HTTP.Conduit+import Control.Monad.Trans.Resource (ResourceT)+ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as TL@@ -25,7 +28,6 @@ soapCodepage :: IC.EncodingName } deriving (Read, Show) - -- | Query a SOAP service. invokeWS :: (ToNodes h, ToNodes i, FromCursor o) => SOAPSettings -- ^ web service configuration@@ -33,8 +35,17 @@ -> h -- ^ request headers -> i -- ^ request body -> IO o -- ^ response+invokeWS = invokeWS' id -invokeWS SOAPSettings{..} methodHeader h b = do+-- | Query a SOAP service with a customized 'Request'.+invokeWS' :: (ToNodes h, ToNodes i, FromCursor o)+ => (Request (ResourceT IO) -> Request (ResourceT IO)) -- ^ request transformation to apply before sending+ -> SOAPSettings -- ^ web service configuration+ -> Text -- ^ SOAPAction header+ -> h -- ^ request headers+ -> i -- ^ request body+ -> IO o -- ^ response+invokeWS' reqProc SOAPSettings{..} methodHeader h b = do let headerNodes = toNodes h let bodyNodes = map (flowNS $ Just soapNamespace) (toNodes b) @@ -45,13 +56,14 @@ TL.putStrLn . renderText def { rsPretty = True } $! doc request <- parseUrl soapURL- res <- withManager $ httpLbs request { method = "POST"- , responseTimeout = Just 15000000- , requestBody = RequestBodyLBS body- , requestHeaders = [ ("Content-Type", "text/xml; charset=utf-8")- , ("SOAPAction", TE.encodeUtf8 methodHeader)- ]- }+ let request' = request { method = "POST"+ , responseTimeout = Just 15000000+ , requestBody = RequestBodyLBS body+ , requestHeaders = [ ("Content-Type", "text/xml; charset=utf-8")+ , ("SOAPAction", TE.encodeUtf8 methodHeader)+ ]+ }+ res <- withManager $ httpLbs (reqProc request') let resBody = IC.convertFuzzy IC.Transliterate soapCodepage "utf-8" $ responseBody res @@ -75,13 +87,16 @@ document r = Document (Prologue [] Nothing []) r [] envelope :: [Node] -> [Node] -> Element-envelope h b =+envelope header body = Element "{http://schemas.xmlsoap.org/soap/envelope/}Envelope" def- [ NodeElement $! Element "{http://schemas.xmlsoap.org/soap/envelope/}Header" def h- , NodeElement $! Element "{http://schemas.xmlsoap.org/soap/envelope/}Body" def b- ]+ ( if null header+ then [ NodeElement $! Element "{http://schemas.xmlsoap.org/soap/envelope/}Body" def body ]+ else [ NodeElement $! Element "{http://schemas.xmlsoap.org/soap/envelope/}Header" def header+ , NodeElement $! Element "{http://schemas.xmlsoap.org/soap/envelope/}Body" def body+ ]+ ) -- | Little helper to apply default service namespace to body nodes and their descendants. -- This removes the necessity to flood your code with {http://vendor.silly.web/Service.spamx} in element names.