Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 1b4ff5caba8efd7a081c033d686c35c212bb3553 0 parents
Devin Torres authored
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "erlsom"]
+ path = deps/erlsom
+ url = git://github.com/dweldon/erlsom.git
5 Makefile
@@ -0,0 +1,5 @@
+all:
+ @(./rebar compile)
+
+clean:
+ @(./rebar clean)
15 README.md
@@ -0,0 +1,15 @@
+Detergent - An emulsifying Erlang SOAP library
+==============================================
+
+## Installing
+ $ git clone git://github.com/devinus/detergent.git
+ $ cd detergent
+ $ git submodule init
+ $ git submodule update
+ $ make
+
+## Testing
+ $ erl -pa ebin deps/erlsom/ebin
+ > inets:start().
+ > l(detergent).
+ > detergent:qtest().
8 ebin/detergent.app
@@ -0,0 +1,8 @@
+% -*- mode: erlang -*-
+{application, detergent,
+ [{description, "An emulsifying Erlang SOAP library"},
+ {vsn, "0.1"},
+ {modules, [detergent, detergent_dime, detergent_server]},
+ {registered, []},
+ {env, []},
+ {applications, [kernel, stdlib, erlsom]}]}.
BIN  ebin/detergent.beam
Binary file not shown
BIN  ebin/detergent_dime.beam
Binary file not shown
BIN  ebin/detergent_server.beam
Binary file not shown
48 include/detergent.hrl
@@ -0,0 +1,48 @@
+-record(wsdl, {operations, model, module}).
+-record(port, {service, port, binding, address}).
+-record(operation, {service, port, operation, binding, address, action}).
+-record('soap:detail', {anyAttribs, choice}).
+-record('soap:Fault', {anyAttribs, 'faultcode', 'faultstring', 'faultactor', 'detail'}).
+-record('soap:Body', {anyAttribs, choice}).
+-record('soap:Header', {anyAttribs, choice}).
+-record('soap:Envelope', {anyAttribs, 'Header', 'Body', choice}).
+-record('wsdl:tExtensibilityElement', {anyAttribs, 'wsdl:required'}).
+-record('wsdl:tPort', {anyAttribs, 'name', 'binding', 'documentation', choice}).
+-record('wsdl:tService', {anyAttribs, 'name', 'documentation', choice, 'port'}).
+-record('wsdl:tBindingOperation', {anyAttribs, 'name', 'documentation', choice, 'input', 'output', 'fault'}).
+-record('wsdl:tBindingOperationFault', {anyAttribs, 'name', 'documentation', choice}).
+-record('wsdl:tBindingOperationMessage', {anyAttribs, 'name', 'documentation', choice}).
+-record('wsdl:tBinding', {anyAttribs, 'name', 'type', 'documentation', choice, 'operation'}).
+-record('wsdl:tFault', {anyAttribs, 'name', 'message', 'documentation'}).
+-record('wsdl:tParam', {anyAttribs, 'name', 'message', 'documentation'}).
+-record('wsdl:solicit-response-or-notification-operation', {anyAttribs, 'output', 'solicit-response-or-notification-operation/SEQ2'}).
+-record('wsdl:solicit-response-or-notification-operation/SEQ2', {anyAttribs, 'input', 'fault'}).
+-record('wsdl:request-response-or-one-way-operation', {anyAttribs, 'input', 'request-response-or-one-way-operation/SEQ1'}).
+-record('wsdl:request-response-or-one-way-operation/SEQ1', {anyAttribs, 'output', 'fault'}).
+-record('wsdl:tOperation', {anyAttribs, 'name', 'parameterOrder', 'documentation', any, choice}).
+-record('wsdl:tPortType', {anyAttribs, 'name', 'documentation', 'operation'}).
+-record('wsdl:tPart', {anyAttribs, 'name', 'element', 'type', 'documentation'}).
+-record('wsdl:tMessage', {anyAttribs, 'name', 'documentation', choice, 'part'}).
+-record('wsdl:tTypes', {anyAttribs, 'documentation', choice}).
+-record('wsdl:tImport', {anyAttribs, 'namespace', 'location', 'documentation'}).
+-record('wsdl:tDefinitions', {anyAttribs, 'targetNamespace', 'name', 'documentation', any, choice}).
+-record('wsdl:anyTopLevelOptionalElement-service', {anyAttribs, 'service'}).
+-record('wsdl:anyTopLevelOptionalElement-binding', {anyAttribs, 'binding'}).
+-record('wsdl:anyTopLevelOptionalElement-portType', {anyAttribs, 'portType'}).
+-record('wsdl:anyTopLevelOptionalElement-message', {anyAttribs, 'message'}).
+-record('wsdl:anyTopLevelOptionalElement-types', {anyAttribs, 'types'}).
+-record('wsdl:anyTopLevelOptionalElement-import', {anyAttribs, 'import'}).
+-record('wsdl:anyTopLevelOptionalElement', {anyAttribs, choice}).
+-record('wsdl:tExtensibleDocumented', {anyAttribs, 'documentation', choice}).
+-record('wsdl:tExtensibleAttributesDocumented', {anyAttribs, 'documentation'}).
+-record('wsdl:tDocumented', {anyAttribs, 'documentation'}).
+-record('wsdl:tDocumentation-any', {anyAttribs, choice}).
+-record('wsdl:tDocumentation', {anyAttribs, choice}).
+-record('soap:tBinding', {anyAttribs, 'wsdl:required', 'transport', 'style'}).
+-record('soap:tOperation', {anyAttribs, 'wsdl:required', 'soapAction', 'style'}).
+-record('soap:tBody', {anyAttribs, 'wsdl:required', 'parts', 'namespace', 'use', 'encodingStyle'}).
+-record('soap:tFaultRes', {anyAttribs, 'wsdl:required', 'parts', 'namespace', 'use', 'encodingStyle'}).
+-record('soap:tFault', {anyAttribs, 'wsdl:required', 'parts', 'namespace', 'use', 'encodingStyle', 'name'}).
+-record('soap:tHeader', {anyAttribs, 'wsdl:required', 'namespace', 'encodingStyle', 'use', 'part', 'message', 'headerfault'}).
+-record('soap:tHeaderFault', {anyAttribs, 'namespace', 'encodingStyle', 'use', 'part', 'message'}).
+-record('soap:tAddress', {anyAttribs, 'wsdl:required', 'location'}).
126 priv/envelope.xsd
@@ -0,0 +1,126 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+
+<!-- Schema for the SOAP/1.1 envelope
+
+Portions © 2001 DevelopMentor.
+© 2001 W3C (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved.
+
+This document is governed by the W3C Software License [1] as described in the FAQ [2].
+[1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
+[2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
+By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions:
+
+Permission to use, copy, modify, and distribute this software and its documentation, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the software and documentation or portions thereof, including modifications, that you make:
+
+1. The full text of this NOTICE in a location viewable to users of the redistributed or derivative work.
+
+2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, a short notice of the following form (hypertext is preferred, text is permitted) should be used within the body of any redistributed or derivative code: "Copyright © 2001 World Wide Web Consortium, (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved. http://www.w3.org/Consortium/Legal/"
+
+3. Notice of any changes or modifications to the W3C files, including the date changes were made. (We recommend you provide URIs to the location from which the code is derived.)
+
+Original W3C files; http://www.w3.org/2001/06/soap-envelope
+Changes made:
+ - reverted namespace to http://schemas.xmlsoap.org/soap/envelope/
+ - reverted mustUnderstand to only allow 0 and 1 as lexical values
+ - made encodingStyle a global attribute 20020825
+ - removed default value from mustUnderstand attribute declaration
+
+THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
+
+COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
+
+The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.
+
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/"
+ targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" >
+
+
+ <!-- Envelope, header and body -->
+ <xs:element name="Envelope" type="tns:Envelope" />
+ <xs:complexType name="Envelope" >
+ <xs:sequence>
+ <xs:element ref="tns:Header" minOccurs="0" />
+ <xs:element ref="tns:Body" minOccurs="1" />
+ <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ <xs:anyAttribute namespace="##other" processContents="lax" />
+ </xs:complexType>
+
+ <xs:element name="Header" type="tns:Header" />
+ <xs:complexType name="Header" >
+ <xs:sequence>
+ <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ <xs:anyAttribute namespace="##other" processContents="lax" />
+ </xs:complexType>
+
+ <xs:element name="Body" type="tns:Body" />
+ <xs:complexType name="Body" >
+ <xs:sequence>
+ <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ <xs:anyAttribute namespace="##any" processContents="lax" >
+ <xs:annotation>
+ <xs:documentation>
+ Prose in the spec does not specify that attributes are allowed on the Body element
+ </xs:documentation>
+ </xs:annotation>
+ </xs:anyAttribute>
+ </xs:complexType>
+
+
+ <!-- Global Attributes. The following attributes are intended to be usable via qualified attribute names on any complex type referencing them. -->
+ <xs:attribute name="mustUnderstand" >
+ <xs:simpleType>
+ <xs:restriction base='xs:boolean'>
+ <xs:pattern value='0|1' />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ <xs:attribute name="actor" type="xs:anyURI" />
+
+ <xs:simpleType name="encodingStyle" >
+ <xs:annotation>
+ <xs:documentation>
+ 'encodingStyle' indicates any canonicalization conventions followed in the contents of the containing element. For example, the value 'http://schemas.xmlsoap.org/soap/encoding/' indicates the pattern described in SOAP specification
+ </xs:documentation>
+ </xs:annotation>
+ <xs:list itemType="xs:anyURI" />
+ </xs:simpleType>
+
+ <xs:attribute name="encodingStyle" type="tns:encodingStyle" />
+ <xs:attributeGroup name="encodingStyle" >
+ <xs:attribute ref="tns:encodingStyle" />
+ </xs:attributeGroup>
+
+ <xs:element name="Fault" type="tns:Fault" />
+ <xs:complexType name="Fault" final="extension" >
+ <xs:annotation>
+ <xs:documentation>
+ Fault reporting structure
+ </xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="faultcode" type="xs:QName" />
+ <xs:element name="faultstring" type="xs:string" />
+ <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
+ <xs:element name="detail" type="tns:detail" minOccurs="0" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="detail">
+ <xs:sequence>
+ <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ <xs:anyAttribute namespace="##any" processContents="lax" />
+ </xs:complexType>
+
+</xs:schema>
+
+
+
+
+
+
149 priv/soap.xsd
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+
+Copyright 2001 - 2005, International Business Machines Corporation and Microsoft Corporation
+All Rights Reserved
+
+License for WSDL Schema Files
+
+The Authors grant permission to copy and distribute the WSDL Schema
+Files in any medium without fee or royalty as long as this notice and
+license are distributed with them. The originals of these files can
+be located at:
+
+http://schemas.xmlsoap.org/wsdl/soap/2003-02-11.xsd
+
+THESE SCHEMA FILES ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS
+OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THESE FILES, INCLUDING, BUT NOT
+LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT,
+INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR
+RELATING TO ANY USE OR DISTRIBUTION OF THESE FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner,
+including advertising or publicity pertaining to these files or any program
+or service that uses these files, written prior permission. Title to copyright
+in these files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ targetNamespace="http://schemas.xmlsoap.org/wsdl/soap/" >
+
+ <xs:import namespace = "http://schemas.xmlsoap.org/wsdl/"/>
+
+ <xs:simpleType name="encodingStyle" >
+ <xs:annotation>
+ <xs:documentation>
+ "encodingStyle" indicates any canonicalization conventions followed in the contents of the containing element. For example, the value "http://schemas.xmlsoap.org/soap/encoding/" indicates the pattern described in SOAP specification
+ </xs:documentation>
+ </xs:annotation>
+ <xs:list itemType="xs:anyURI" />
+ </xs:simpleType>
+
+ <xs:element name="binding" type="soap:tBinding" />
+ <xs:complexType name="tBinding" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibilityElement" >
+ <xs:attribute name="transport" type="xs:anyURI" use="required" />
+ <xs:attribute name="style" type="soap:tStyleChoice" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:simpleType name="tStyleChoice" >
+ <xs:restriction base="xs:string" >
+ <xs:enumeration value="rpc" />
+ <xs:enumeration value="document" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:element name="operation" type="soap:tOperation" />
+ <xs:complexType name="tOperation" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibilityElement" >
+ <xs:attribute name="soapAction" type="xs:anyURI" use="optional" />
+ <xs:attribute name="style" type="soap:tStyleChoice" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="body" type="soap:tBody" />
+ <xs:attributeGroup name="tBodyAttributes" >
+ <xs:attribute name="encodingStyle" type="soap:encodingStyle" use="optional" />
+ <xs:attribute name="use" type="soap:useChoice" use="optional" />
+ <xs:attribute name="namespace" type="xs:anyURI" use="optional" />
+ </xs:attributeGroup>
+ <xs:complexType name="tBody" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibilityElement" >
+ <xs:attribute name="parts" type="xs:NMTOKENS" use="optional" />
+ <xs:attributeGroup ref = "soap:tBodyAttributes" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:simpleType name="useChoice" >
+ <xs:restriction base="xs:string" >
+ <xs:enumeration value="literal" />
+ <xs:enumeration value="encoded" />
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:element name="fault" type="soap:tFault" />
+ <xs:complexType name="tFaultRes" abstract="true" >
+ <xs:complexContent>
+ <xs:restriction base="soap:tBody" >
+ <xs:attribute ref="wsdl:required" use="optional" />
+ <xs:attribute name="parts" type="xs:NMTOKENS" use="prohibited" />
+ <xs:attributeGroup ref="soap:tBodyAttributes" />
+ </xs:restriction>
+ </xs:complexContent>
+ </xs:complexType>
+ <xs:complexType name="tFault" >
+ <xs:complexContent>
+ <xs:extension base="soap:tFaultRes">
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+
+ <xs:element name="header" type="soap:tHeader" />
+ <xs:attributeGroup name="tHeaderAttributes" >
+ <xs:attribute name="message" type="xs:QName" use="required" />
+ <xs:attribute name="part" type="xs:NMTOKEN" use="required" />
+ <xs:attribute name="use" type="soap:useChoice" use="required" />
+ <xs:attribute name="encodingStyle" type="soap:encodingStyle" use="optional" />
+ <xs:attribute name="namespace" type="xs:anyURI" use="optional" />
+ </xs:attributeGroup>
+ <xs:complexType name="tHeader" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibilityElement" >
+ <xs:sequence>
+ <xs:element ref="soap:headerfault" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attributeGroup ref="soap:tHeaderAttributes" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="headerfault" type="soap:tHeaderFault" />
+ <xs:complexType name="tHeaderFault" >
+ <xs:attributeGroup ref="soap:tHeaderAttributes" />
+ </xs:complexType>
+
+ <xs:element name="address" type="soap:tAddress" />
+ <xs:complexType name="tAddress" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibilityElement" >
+ <xs:attribute name="location" type="xs:anyURI" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+</xs:schema>
314 priv/wsdl.xsd
@@ -0,0 +1,314 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+
+Copyright 2001 - 2005, International Business Machines Corporation and Microsoft Corporation
+All Rights Reserved
+
+License for WSDL Schema Files
+
+The Authors grant permission to copy and distribute the WSDL Schema
+Files in any medium without fee or royalty as long as this notice and
+license are distributed with them. The originals of these files can
+be located at:
+
+http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd
+
+THESE SCHEMA FILES ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS
+OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THESE FILES, INCLUDING, BUT NOT
+LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT,
+INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR
+RELATING TO ANY USE OR DISTRIBUTION OF THESE FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner,
+including advertising or publicity pertaining to these files or any program
+or service that uses these files, written prior permission. Title to copyright
+in these files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ targetNamespace="http://schemas.xmlsoap.org/wsdl/"
+ elementFormDefault="qualified" >
+
+ <xs:complexType mixed="true" name="tDocumentation" >
+ <xs:sequence>
+ <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="tDocumented" >
+ <xs:annotation>
+ <xs:documentation>
+ This type is extended by component types to allow them to be documented
+ </xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="documentation" type="wsdl:tDocumentation" minOccurs="0" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="tExtensibleAttributesDocumented" abstract="true" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tDocumented" >
+ <xs:annotation>
+ <xs:documentation>
+ This type is extended by component types to allow attributes from other namespaces to be added.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:anyAttribute namespace="##other" processContents="lax" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tExtensibleDocumented" abstract="true" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tDocumented" >
+ <xs:annotation>
+ <xs:documentation>
+ This type is extended by component types to allow elements from other namespaces to be added.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" />
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="definitions" type="wsdl:tDefinitions" >
+ <xs:key name="message" >
+ <xs:selector xpath="wsdl:message" />
+ <xs:field xpath="@name" />
+ </xs:key>
+ <xs:key name="portType" >
+ <xs:selector xpath="wsdl:portType" />
+ <xs:field xpath="@name" />
+ </xs:key>
+ <xs:key name="binding" >
+ <xs:selector xpath="wsdl:binding" />
+ <xs:field xpath="@name" />
+ </xs:key>
+ <xs:key name="service" >
+ <xs:selector xpath="wsdl:service" />
+ <xs:field xpath="@name" />
+ </xs:key>
+ <xs:key name="import" >
+ <xs:selector xpath="wsdl:import" />
+ <xs:field xpath="@namespace" />
+ </xs:key>
+ </xs:element>
+
+ <xs:group name="anyTopLevelOptionalElement" >
+ <xs:annotation>
+ <xs:documentation>
+ Any top level optional element allowed to appear more then once - any child of definitions element except wsdl:types. Any extensibility element is allowed in any place.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:choice>
+ <xs:element name="import" type="wsdl:tImport" />
+ <xs:element name="types" type="wsdl:tTypes" />
+ <xs:element name="message" type="wsdl:tMessage" >
+ <xs:unique name="part" >
+ <xs:selector xpath="wsdl:part" />
+ <xs:field xpath="@name" />
+ </xs:unique>
+ </xs:element>
+ <xs:element name="portType" type="wsdl:tPortType" />
+ <xs:element name="binding" type="wsdl:tBinding" />
+ <xs:element name="service" type="wsdl:tService" >
+ <xs:unique name="port" >
+ <xs:selector xpath="wsdl:port" />
+ <xs:field xpath="@name" />
+ </xs:unique>
+ </xs:element>
+ </xs:choice>
+ </xs:group>
+
+ <xs:complexType name="tDefinitions" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:group ref="wsdl:anyTopLevelOptionalElement" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="targetNamespace" type="xs:anyURI" use="optional" />
+ <xs:attribute name="name" type="xs:NCName" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tImport" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleAttributesDocumented" >
+ <xs:attribute name="namespace" type="xs:anyURI" use="required" />
+ <xs:attribute name="location" type="xs:anyURI" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tTypes" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" />
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tMessage" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:element name="part" type="wsdl:tPart" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tPart" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleAttributesDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ <xs:attribute name="element" type="xs:QName" use="optional" />
+ <xs:attribute name="type" type="xs:QName" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tPortType" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleAttributesDocumented" >
+ <xs:sequence>
+ <xs:element name="operation" type="wsdl:tOperation" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tOperation" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:choice>
+ <xs:group ref="wsdl:request-response-or-one-way-operation" />
+ <xs:group ref="wsdl:solicit-response-or-notification-operation" />
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ <xs:attribute name="parameterOrder" type="xs:NMTOKENS" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:group name="request-response-or-one-way-operation" >
+ <xs:sequence>
+ <xs:element name="input" type="wsdl:tParam" />
+ <xs:sequence minOccurs='0' >
+ <xs:element name="output" type="wsdl:tParam" />
+ <xs:element name="fault" type="wsdl:tFault" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:sequence>
+ </xs:group>
+
+ <xs:group name="solicit-response-or-notification-operation" >
+ <xs:sequence>
+ <xs:element name="output" type="wsdl:tParam" />
+ <xs:sequence minOccurs='0' >
+ <xs:element name="input" type="wsdl:tParam" />
+ <xs:element name="fault" type="wsdl:tFault" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:sequence>
+ </xs:group>
+
+ <xs:complexType name="tParam" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleAttributesDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="optional" />
+ <xs:attribute name="message" type="xs:QName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tFault" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleAttributesDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ <xs:attribute name="message" type="xs:QName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tBinding" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:element name="operation" type="wsdl:tBindingOperation" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ <xs:attribute name="type" type="xs:QName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tBindingOperationMessage" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="optional" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tBindingOperationFault" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tBindingOperation" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:element name="input" type="wsdl:tBindingOperationMessage" minOccurs="0" />
+ <xs:element name="output" type="wsdl:tBindingOperationMessage" minOccurs="0" />
+ <xs:element name="fault" type="wsdl:tBindingOperationFault" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tService" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:sequence>
+ <xs:element name="port" type="wsdl:tPort" minOccurs="0" maxOccurs="unbounded" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:complexType name="tPort" >
+ <xs:complexContent>
+ <xs:extension base="wsdl:tExtensibleDocumented" >
+ <xs:attribute name="name" type="xs:NCName" use="required" />
+ <xs:attribute name="binding" type="xs:QName" use="required" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:attribute name="arrayType" type="xs:string" />
+ <xs:attribute name="required" type="xs:boolean" />
+ <xs:complexType name="tExtensibilityElement" abstract="true" >
+ <xs:attribute ref="wsdl:required" use="optional" />
+ </xs:complexType>
+
+ <xs:attributeGroup name="ItemDelivery">
+ <xs:attribute name="partNum" type="xs:string" use="required"/>
+ <xs:attribute ref="wsdl:required"/>
+ </xs:attributeGroup>
+</xs:schema>
BIN  rebar
Binary file not shown
3  rebar.config
@@ -0,0 +1,3 @@
+% -*- mode: erlang -*-
+{sub_dirs, ["deps/erlsom"]}.
+{fail_on_warning, true}.
670 src/detergent.erl
@@ -0,0 +1,670 @@
+%%%-------------------------------------------------------------------
+%%% Created : 29 Nov 2006 by Torbjorn Tornkvist <tobbe@tornkvist.org>
+%%% Author : Willem de Jong (w.a.de.jong@gmail.com).
+%%% Desc. : Common SOAP code.
+%%%-------------------------------------------------------------------
+
+%%% modified (WdJ, May 2007): deal with imports in the WSDL.
+%%% modified (WdJ, August 2007): the WSDL can contain more than 1 schema
+
+-module(detergent).
+
+-export([initModel/1, initModel/2,
+ initModelFile/1,
+ config_file_xsd/0,
+ call/3, call/4, call/5, call/6,
+ call_attach/4, call_attach/5, call_attach/7,
+ write_hrl/2, write_hrl/3,
+ findHeader/2,
+ parseMessage/2,
+ makeFault/2,
+ is_wsdl/1, wsdl_model/1, wsdl_op_service/1,
+ wsdl_op_port/1, wsdl_op_operation/1,
+ wsdl_op_binding/1, wsdl_op_address/1,
+ wsdl_op_action/1, wsdl_operations/1,
+ get_operation/2
+ ]).
+
+
+%%% For testing...
+-export([qtest/0]).
+
+
+-include("../include/detergent.hrl").
+-include("../deps/erlsom/src/erlsom.hrl").
+
+
+-define(HTTP_REQ_TIMEOUT, 20000).
+
+%%-define(dbg(X,Y),
+%% error_logger:info_msg("*dbg ~p(~p): " X,
+%% [?MODULE, ?LINE | Y])).
+-define(dbg(X,Y), true).
+
+
+-record(soap_config, {atts, xsd_path, user_module, wsdl_file, add_files}).
+-record(xsd_file, {atts, name, prefix, import_specs}).
+-record(import_specs, {atts, namespace, prefix, location}).
+%% this comes from erlsom_compile. Maybe better to have an accessor function
+%% in erlsom_lib?
+-record(schemaType,
+ {elInfo, targetNamespace, elementFormDefault, attributeFormDefault,
+ blockDefault, finalDefault, version, imports, elements}).
+-define(DefaultPrefix, "p").
+
+
+%%%
+%%% Writes the header file (record definitions) for a WSDL file
+%%%
+write_hrl(WsdlURL, Output) when is_list(WsdlURL) ->
+ write_hrl(initModel(WsdlURL), Output);
+write_hrl(#wsdl{model = Model}, Output) when is_list(Output) ->
+ erlsom:write_hrl(Model, Output).
+
+write_hrl(WsdlURL, Output, Prefix) when is_list(WsdlURL),is_list(Prefix) ->
+ write_hrl(initModel(WsdlURL, Prefix), Output).
+
+
+
+%%% For testing only...
+qtest() ->
+ call("http://www.webservicex.net/WeatherForecast.asmx?WSDL",
+ "GetWeatherByPlaceName",
+ ["Boston"]).
+
+%%% --------------------------------------------------------------------
+%%% Access functions
+%%% --------------------------------------------------------------------
+is_wsdl(Wsdl) when is_record(Wsdl,wsdl) -> true;
+is_wsdl(_) -> false.
+
+wsdl_operations(#wsdl{operations = Ops}) -> Ops.
+
+wsdl_model(#wsdl{model = Model}) -> Model.
+
+wsdl_op_service(#operation{service = Service}) -> Service.
+
+wsdl_op_port(#operation{port = Port}) -> Port.
+
+wsdl_op_operation(#operation{operation = Op}) -> Op.
+
+wsdl_op_binding(#operation{binding = Binding}) -> Binding.
+
+wsdl_op_address(#operation{address = Address}) -> Address.
+
+wsdl_op_action(#operation{action = Action}) -> Action.
+
+
+%%% --------------------------------------------------------------------
+%%% For Quick deployment
+%%% --------------------------------------------------------------------
+call(WsdlURL, Operation, ListOfData) when is_list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, ?DefaultPrefix),
+ call(Wsdl, Operation, ListOfData);
+call(Wsdl, Operation, ListOfData) when is_record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ Msg = mk_msg(?DefaultPrefix, Operation, ListOfData),
+ call(Wsdl, Operation, Op#operation.port,
+ Op#operation.service, [], Msg);
+ Else ->
+ Else
+ end.
+
+%%% --------------------------------------------------------------------
+%%% With additional specified prefix
+%%% --------------------------------------------------------------------
+call(WsdlURL, Operation, ListOfData, prefix, Prefix) when is_list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, Prefix),
+ call(Wsdl, Operation, ListOfData, prefix, Prefix );
+call(Wsdl, Operation, ListOfData, prefix, Prefix) when is_record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ Msg = mk_msg(Prefix, Operation, ListOfData),
+ call(Wsdl, Operation, Op#operation.port,
+ Op#operation.service, [], Msg);
+ Else ->
+ Else
+ end.
+
+
+%%% --------------------------------------------------------------------
+%%% Takes the actual records for the Header and Body message.
+%%% --------------------------------------------------------------------
+call(WsdlURL, Operation, Header, Msg) when is_list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, ?DefaultPrefix),
+ call(Wsdl, Operation, Header, Msg);
+call(Wsdl, Operation, Header, Msg) when is_record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ call(Wsdl, Operation, Op#operation.port, Op#operation.service,
+ Header, Msg);
+ Else ->
+ Else
+ end.
+
+
+mk_msg(Prefix, Operation, ListOfData) ->
+ list_to_tuple([list_to_atom(Prefix++":"++Operation), % record name
+ [] % anyAttribs
+ | ListOfData]). % rest of record data
+
+get_operation([#operation{operation = X} = Op|_], X) ->
+ {ok, Op};
+get_operation([_|T], Op) ->
+ get_operation(T, Op);
+get_operation([], _Op) ->
+ {error, "operation not found"}.
+
+
+%%% --------------------------------------------------------------------
+%%% Make a SOAP request (no attachments)
+%%% --------------------------------------------------------------------
+call(Wsdl, Operation, Port, Service, Headers, Message) ->
+ call_attach(Wsdl, Operation, Port, Service, Headers, Message, []).
+
+
+%%% --------------------------------------------------------------------
+%%% For Quick deployment (with attachments)
+%%% --------------------------------------------------------------------
+call_attach(WsdlURL, Operation, ListOfData, Attachments)
+ when is_list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, ?DefaultPrefix),
+ call_attach(Wsdl, Operation, ListOfData, Attachments);
+call_attach(Wsdl, Operation, ListOfData, Attachments)
+ when is_record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ Msg = mk_msg(?DefaultPrefix, Operation, ListOfData),
+ call_attach(Wsdl, Operation, Op#operation.port,
+ Op#operation.service, [], Msg, Attachments);
+ Else ->
+ Else
+ end.
+
+%%% --------------------------------------------------------------------
+%%% Takes the actual records for the Header and Body message
+%%% (with attachments)
+%%% --------------------------------------------------------------------
+call_attach(WsdlURL, Operation, Header, Msg, Attachments)
+ when is_list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, ?DefaultPrefix),
+ call_attach(Wsdl, Operation, Header, Msg, Attachments);
+call_attach(Wsdl, Operation, Header, Msg, Attachments)
+ when is_record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ call_attach(Wsdl, Operation, Op#operation.port,
+ Op#operation.service,
+ Header, Msg, Attachments);
+ Else ->
+ Else
+ end.
+
+
+%%% --------------------------------------------------------------------
+%%% Make a SOAP request (with attachments)
+%%% --------------------------------------------------------------------
+call_attach(#wsdl{operations = Operations, model = Model},
+ Operation, Port, Service, Headers, Message, Attachments) ->
+ %% find the operation
+ case findOperation(Operation, Port, Service, Operations) of
+ #operation{address = URL, action = SoapAction} ->
+ %% Add the Soap envelope
+ Envelope = mk_envelope(Message, Headers),
+ %% Encode the message
+ case erlsom:write(Envelope, Model) of
+ {ok, XmlMessage} ->
+
+ {ContentType, Request} =
+ make_request_body(XmlMessage, Attachments),
+ HttpHeaders = [],
+ HttpClientOptions = [],
+ ?dbg("+++ Request = ~p~n", [Request]),
+ HttpRes = http_request(URL, SoapAction, Request,
+ HttpClientOptions, HttpHeaders,
+ ContentType),
+ ?dbg("+++ HttpRes = ~p~n", [HttpRes]),
+ case HttpRes of
+ {ok, _Code, _ReturnHeaders, Body} ->
+ parseMessage(Body, Model);
+ Error ->
+ %% in case of HTTP error: return
+ %% {error, description}
+ Error
+ end;
+ {error, EncodingError} ->
+ {error, {encoding_error, EncodingError}}
+ end;
+ false ->
+ {error, {unknown_operation, Operation}}
+ end.
+
+%%%
+%%% returns {ok, Header, Body} | {error, Error}
+%%%
+parseMessage(Message, #wsdl{model = Model}) ->
+ parseMessage(Message, Model);
+%%
+parseMessage(Message, Model) ->
+ case erlsom:scan(Message, Model) of
+ {ok, #'soap:Envelope'{'Body' = #'soap:Body'{choice = Body},
+ 'Header' = undefined}, _} ->
+ {ok, undefined, Body};
+ {ok, #'soap:Envelope'{'Body' = #'soap:Body'{choice = Body},
+ 'Header' = #'soap:Header'{choice = Header}}, _} ->
+ {ok, Header, Body};
+ {error, ErrorMessage} ->
+ {error, {decoding, ErrorMessage}}
+ end.
+
+
+findOperation(_Operation, _Port, _Service, []) ->
+ false;
+findOperation(Operation, Port, Service,
+ [Op = #operation{operation = Operation,
+ port = Port, service = Service} | _]) ->
+ Op;
+findOperation(Operation, Port, Service, [#operation{} | Tail]) ->
+ findOperation(Operation, Port, Service, Tail).
+
+
+mk_envelope(M, H) when is_tuple(M) -> mk_envelope([M], H);
+mk_envelope(M, H) when is_tuple(H) -> mk_envelope(M, [H]);
+%%
+mk_envelope(Messages, []) when is_list(Messages) ->
+ #'soap:Envelope'{'Body' = #'soap:Body'{choice = Messages}};
+mk_envelope(Messages, Headers) when is_list(Messages),is_list(Headers) ->
+ #'soap:Envelope'{'Body' = #'soap:Body'{choice = Messages},
+ 'Header' = #'soap:Header'{choice = Headers}}.
+
+%%% --------------------------------------------------------------------
+%%% Parse a WSDL file and return a 'Model'
+%%% --------------------------------------------------------------------
+initModel(WsdlFile) ->
+ initModel(WsdlFile, ?DefaultPrefix).
+
+initModel(WsdlFile, Prefix) ->
+ PrivDir = priv_dir(),
+ initModel2(WsdlFile, Prefix, PrivDir, undefined, undefined).
+
+initModelFile(ConfigFile) ->
+ {ok, ConfigSchema} = erlsom:compile_xsd(config_file_xsd()),
+ %% read (parse) the config file
+ {ok, Config, _} = erlsom:scan_file(ConfigFile, ConfigSchema),
+ #soap_config{xsd_path = XsdPath,
+ wsdl_file = Wsdl,
+ add_files = AddFiles} = Config,
+ #xsd_file{name = WsdlFile, prefix = Prefix, import_specs = Import} = Wsdl,
+ initModel2(WsdlFile, Prefix, XsdPath, Import, AddFiles).
+
+priv_dir() ->
+ filename:join([filename:dirname(code:which(detergent)),"..", "priv"]).
+
+initModel2(WsdlFile, Prefix, Path, Import, AddFiles) ->
+ WsdlName = filename:join([Path, "wsdl.xsd"]),
+ IncludeWsdl = {"http://schemas.xmlsoap.org/wsdl/", "wsdl", WsdlName},
+ {ok, WsdlModel} = erlsom:compile_xsd_file(filename:join([Path, "soap.xsd"]),
+ [{prefix, "soap"},
+ {include_files, [IncludeWsdl]}]),
+ %% add the xsd model (since xsd is also used in the wsdl)
+ WsdlModel2 = erlsom:add_xsd_model(WsdlModel),
+ Options = makeOptions(Import),
+ %% parse Wsdl
+ {Model, Operations} = parseWsdls([WsdlFile], Prefix, WsdlModel2, Options, {undefined, []}),
+ %% TODO: add files as required
+ %% now compile envelope.xsd, and add Model
+ {ok, EnvelopeModel} = erlsom:compile_xsd_file(filename:join([Path, "envelope.xsd"]),
+ [{prefix, "soap"}]),
+ SoapModel = erlsom:add_model(EnvelopeModel, Model),
+ SoapModel2 = addModels(AddFiles, SoapModel),
+ #wsdl{operations = Operations, model = SoapModel2}.
+
+
+%%% --------------------------------------------------------------------
+%%% Parse a list of WSDLs and import (recursively)
+%%% Returns {Model, Operations}
+%%% --------------------------------------------------------------------
+parseWsdls([], _Prefix, _WsdlModel, _Options, Acc) ->
+ Acc;
+parseWsdls([WsdlFile | Tail], Prefix, WsdlModel, Options, {AccModel, AccOperations}) ->
+ {ok, WsdlFileContent} = get_url_file(rmsp(WsdlFile)),
+ {ok, ParsedWsdl, _} = erlsom:scan(WsdlFileContent, WsdlModel),
+ %% get the xsd elements from this model, and hand it over to erlsom_compile.
+ Xsds = getXsdsFromWsdl(ParsedWsdl),
+ %% Now we need to build a list: [{Namespace, Xsd, Prefix}, ...] for all the Xsds in the WSDL.
+ %% This list is used when a schema inlcudes one of the other schemas. The AXIS java2wsdl
+ %% generates wsdls that depend on this feature.
+ ImportList = makeImportList(Xsds, []),
+ %% TODO: pass the right options here
+ Model2 = addSchemas(Xsds, AccModel, Prefix, Options, ImportList),
+ Ports = getPorts(ParsedWsdl),
+ Operations = getOperations(ParsedWsdl, Ports),
+ Imports = getImports(ParsedWsdl),
+ Acc2 = {Model2, Operations ++ AccOperations},
+ %% process imports (recursively, so that imports in the imported files are
+ %% processed as well).
+ %% For the moment, the namespace is ignored on operations etc.
+ %% this makes it a bit easier to deal with imported wsdl's.
+ Acc3 = parseWsdls(Imports, Prefix, WsdlModel, Options, Acc2),
+ parseWsdls(Tail, Prefix, WsdlModel, Options, Acc3).
+
+%%% --------------------------------------------------------------------
+%%% build a list: [{Namespace, Xsd}, ...] for all the Xsds in the WSDL.
+%%% This list is used when a schema inlcudes one of the other schemas. The AXIS java2wsdl
+%%% generates wsdls that depend on this feature.
+makeImportList([], Acc) ->
+ Acc;
+makeImportList([#schemaType{targetNamespace = Tns} = Xsd | Tail], Acc) ->
+ makeImportList(Tail, [{Tns, undefined, Xsd} | Acc]).
+
+
+%%% --------------------------------------------------------------------
+%%% compile each of the schemas, and add it to the model.
+%%% Returns Model
+%%% (TODO: using the same prefix for all XSDS makes no sense)
+%%% --------------------------------------------------------------------
+addSchemas([], AccModel, _Prefix, _Options, _ImportList) ->
+ AccModel;
+addSchemas([Xsd| Tail], AccModel, Prefix, Options, ImportList) ->
+ Model2 = case Xsd of
+ undefined ->
+ AccModel;
+ _ ->
+ {ok, Model} =
+ erlsom_compile:compile_parsed_xsd(Xsd,
+ [{prefix, Prefix},
+ {include_files, ImportList} |Options]),
+ case AccModel of
+ undefined -> Model;
+ _ -> erlsom:add_model(AccModel, Model)
+ end
+ end,
+ addSchemas(Tail, Model2, Prefix, Options, ImportList).
+
+%%% --------------------------------------------------------------------
+%%% Get a file from an URL spec.
+%%% --------------------------------------------------------------------
+get_url_file("http://"++_ = URL) ->
+ case http:request(URL) of
+ {ok,{{_HTTP,200,_OK}, _Headers, Body}} ->
+ {ok, Body};
+ {ok,{{_HTTP,RC,Emsg}, _Headers, _Body}} ->
+ error_logger:error_msg("~p: http-request got: ~p~n", [?MODULE, {RC, Emsg}]),
+ {error, "failed to retrieve: "++URL};
+ {error, Reason} ->
+ error_logger:error_msg("~p: http-request failed: ~p~n", [?MODULE, Reason]),
+ {error, "failed to retrieve: "++URL}
+ end;
+get_url_file("file://"++Fname) ->
+ {ok, Bin} = file:read_file(Fname),
+ {ok, binary_to_list(Bin)};
+%% added this, since this is what is used in many WSDLs (i.e.: just a filename).
+get_url_file(Fname) ->
+ {ok, Bin} = file:read_file(Fname),
+ {ok, binary_to_list(Bin)}.
+
+
+%%% --------------------------------------------------------------------
+%%% Make a HTTP Request
+%%% --------------------------------------------------------------------
+http_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
+ case code:ensure_loaded(ibrowse) of
+ {module, ibrowse} ->
+ %% If ibrowse exist in the path then let's use it...
+ ibrowse_request(URL, SoapAction, Request, Options, Headers, ContentType);
+ _ ->
+ %% ...otherwise, let's use the OTP http client.
+ inets_request(URL, SoapAction, Request, Options, Headers, ContentType)
+ end.
+
+inets_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
+ NHeaders = [{"SOAPAction", SoapAction}|Headers],
+ NewHeaders = case proplists:get_value("Host", NHeaders) of
+ undefined ->
+ [{"Host", "localhost:8800"}|NHeaders];
+ _ ->
+ NHeaders
+ end,
+ NewOptions = [{cookies, enabled}|Options],
+ http:set_options(NewOptions),
+ case http:request(post,
+ {URL,NewHeaders,
+ ContentType,
+ Request},
+ [{timeout,?HTTP_REQ_TIMEOUT}],
+ [{sync, true}, {full_result, true}, {body_format, string}]) of
+ {ok,{{_HTTP,200,_OK},ResponseHeaders,ResponseBody}} ->
+ {ok, 200, ResponseHeaders, ResponseBody};
+ {ok,{{_HTTP,500,_Descr},ResponseHeaders,ResponseBody}} ->
+ {ok, 500, ResponseHeaders, ResponseBody};
+ {ok,{{_HTTP,ErrorCode,_Descr},ResponseHeaders,ResponseBody}} ->
+ {ok, ErrorCode, ResponseHeaders, ResponseBody};
+ Other ->
+ Other
+ end.
+
+ibrowse_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
+ case start_ibrowse() of
+ ok ->
+ NewHeaders = [{"Content-Type", ContentType}, {"SOAPAction", SoapAction} | Headers],
+ NewOptions = Options,
+ %%[{content_type, "text/xml; encoding=utf-8"} | Options],
+ case ibrowse:send_req(URL, NewHeaders, post, Request, NewOptions) of
+ {ok, Status, ResponseHeaders, ResponseBody} ->
+ {ok, list_to_integer(Status), ResponseHeaders, ResponseBody};
+ {error, Reason} ->
+ {error, Reason}
+ end;
+ error ->
+ {error, "could not start ibrowse"}
+ end.
+
+start_ibrowse() ->
+ case ibrowse:start() of
+ {ok, _} -> ok;
+ {error, {already_started, _}} -> ok;
+ _ -> error
+ end.
+
+
+rmsp(Str) -> string:strip(Str, left).
+
+
+make_request_body(Content, []) ->
+ {"text/xml; charset=utf-8", "<?xml version=\"1.0\" encoding=\"utf-8\"?>"++Content};
+make_request_body(Content, AttachedFiles) ->
+ {"application/dime", detergent_dime:encode("<?xml version=\"1.0\" encoding=\"utf-8\"?>"++Content, AttachedFiles)}.
+
+
+makeFault(FaultCode, FaultString) ->
+ try
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<SOAP-ENV:Body>"
+ "<SOAP-ENV:Fault>"
+ "<faultcode>SOAP-ENV:" ++ FaultCode ++ "</faultcode>" ++
+ "<faultstring>" ++ FaultString ++ "</faultstring>" ++
+ "</SOAP-ENV:Fault>"
+ "</SOAP-ENV:Body>"
+ "</SOAP-ENV:Envelope>"
+ catch
+ _:_ ->
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<SOAP-ENV:Body>"
+ "<SOAP-ENV:Fault>"
+ "<faultcode>SOAP-ENV:Server</faultcode>"
+ "<faultstring>Server error</faultstring>"
+ "</SOAP-ENV:Fault>"
+ "</SOAP-ENV:Body>"
+ "</SOAP-ENV:Envelope>"
+ end.
+
+%% record http_header is not defined??
+findHeader(Label, Headers) ->
+ findHeader0(string:to_lower(Label), Headers).
+
+findHeader0(_Label, []) ->
+ undefined;
+findHeader0(Label, [{_,_,Hdr,_,Val}|T]) ->
+ case {Label, string:to_lower(Hdr)} of
+ {X,X} -> Val;
+ _ -> findHeader0(Label, T)
+ end;
+findHeader0(_Label, undefined) ->
+ undefined.
+
+
+makeOptions(undefined) ->
+ [];
+makeOptions(Import) ->
+ lists:map(fun makeOption/1, Import).
+
+%% -record(import_specs, {atts, namespace, prefix, location}).
+makeOption(#import_specs{namespace = Ns, prefix = Pf, location = Lc}) ->
+ {Ns, Pf, Lc}.
+
+
+addModels(undefined, Model) ->
+ Model;
+addModels(Import, Model) ->
+ lists:foldl(fun addModel/2, Model, Import).
+
+%% -record(xsd_file, {atts, name, prefix, import_specs}).
+addModel(undefined, Acc) ->
+ Acc;
+addModel(#xsd_file{name = XsdFile, prefix = Prefix, import_specs = Import}, Acc) ->
+ Options = makeOptions(Import),
+ {ok, Model2} = erlsom:add_xsd_file(XsdFile, [{prefix, Prefix} | Options], Acc),
+ Model2.
+
+%% returns [#port{}]
+%% -record(port, {service, port, binding, address}).
+getPorts(ParsedWsdl) ->
+ Services = getTopLevelElements(ParsedWsdl, 'wsdl:tService'),
+ getPortsFromServices(Services, []).
+
+getPortsFromServices([], Acc) ->
+ Acc;
+getPortsFromServices([Service|Tail], Acc) ->
+ getPortsFromServices(Tail, getPortsFromService(Service) ++ Acc).
+
+getPortsFromService(#'wsdl:tService'{name = Name, port = Ports}) ->
+ getPortsInfo(Ports, Name, []).
+
+getPortsInfo([], _Name, Acc) ->
+ Acc;
+
+getPortsInfo([#'wsdl:tPort'{name = Name,
+ binding = Binding,
+ choice = [#'soap:tAddress'{location = URL}]} | Tail], ServiceName, Acc) ->
+ getPortsInfo(Tail, ServiceName, [#port{service = ServiceName, port = Name, binding = Binding, address = URL}|Acc]);
+%% non-soap bindings are ignored.
+getPortsInfo([#'wsdl:tPort'{} | Tail], ServiceName, Acc) ->
+ getPortsInfo(Tail, ServiceName, Acc).
+
+
+getTopLevelElements(#'wsdl:tDefinitions'{choice = TLElements}, Type) ->
+ getTopLevelElements(TLElements, Type, []).
+
+getTopLevelElements([], _Type, Acc) ->
+ Acc;
+getTopLevelElements([#'wsdl:anyTopLevelOptionalElement'{choice = Tuple}| Tail], Type, Acc) ->
+ case element(1, Tuple) of
+ Type -> getTopLevelElements(Tail, Type, [Tuple|Acc]);
+ _ -> getTopLevelElements(Tail, Type, Acc)
+ end.
+
+getImports(Definitions) ->
+ Imports = getTopLevelElements(Definitions, 'wsdl:tImport'),
+ lists:map(fun(Import) -> Import#'wsdl:tImport'.location end, Imports).
+
+%% returns [#operation{}]
+getOperations(ParsedWsdl, Ports) ->
+ Bindings = getTopLevelElements(ParsedWsdl, 'wsdl:tBinding'),
+ getOperationsFromBindings(Bindings, Ports, []).
+
+getOperationsFromBindings([], _Ports, Acc) ->
+ Acc;
+getOperationsFromBindings([Binding|Tail], Ports, Acc) ->
+ getOperationsFromBindings(Tail, Ports, getOperationsFromBinding(Binding, Ports) ++ Acc).
+
+getOperationsFromBinding(#'wsdl:tBinding'{name = BindingName,
+ type = BindingType,
+ choice = _Choice,
+ operation = Operations}, Ports) ->
+ %% TODO: get soap info from Choice
+ getOperationsFromOperations(Operations, BindingName, BindingType, Operations, Ports, []).
+
+getOperationsFromOperations([], _BindingName, _BindingType, _Operations, _Ports, Acc) ->
+ Acc;
+
+getOperationsFromOperations([#'wsdl:tBindingOperation'{name = Name, choice = Choice} | Tail],
+ BindingName, BindingType, Operations, Ports, Acc) ->
+ %% get SOAP action from Choice,
+ case Choice of
+ [#'soap:tOperation'{soapAction = Action}] ->
+ %% lookup Binding in Ports, and create a combined result
+ Ports2 = searchPorts(BindingName, Ports),
+ %% for each port, make an operation record
+ CombinedPorts = combinePorts(Ports2, Name, BindingName, Action),
+ getOperationsFromOperations(Tail, BindingName, BindingType, Operations, Ports, CombinedPorts ++ Acc);
+ _ ->
+ getOperationsFromOperations(Tail, BindingName, BindingType, Operations, Ports, Acc)
+ end.
+
+combinePorts(Ports, Name, BindingName, Action) ->
+ combinePorts(Ports, Name, BindingName, Action, []).
+
+combinePorts([], _Name, _BindingName, _Action, Acc) ->
+ Acc;
+combinePorts([#port{service = Service, port = PortName, address = Address} | Tail],
+ Name, BindingName, Action, Acc) ->
+ combinePorts(Tail, Name, BindingName, Action,
+ [#operation{service = Service, port = PortName, operation = Name,
+ binding = BindingName, address = Address, action = Action} | Acc]).
+
+searchPorts(BindingName, Ports) ->
+ searchPorts(BindingName, Ports, []).
+
+searchPorts(_BindingName, [], Acc) ->
+ Acc;
+searchPorts(BindingName, [Port | Tail], Acc) ->
+ case Port of
+ #port{binding = #qname{localPart = BindingName}} ->
+ searchPorts(BindingName, Tail, [Port | Acc]);
+ _ ->
+ searchPorts(BindingName, Tail, Acc)
+ end.
+
+
+getXsdsFromWsdl(Definitions) ->
+ case getTopLevelElements(Definitions, 'wsdl:tTypes') of
+ [#'wsdl:tTypes'{choice = Xsds}] -> Xsds;
+ [] -> undefined
+ end.
+
+config_file_xsd() ->
+"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
+" <xs:element name=\"soap_config\">"
+" <xs:complexType>"
+" <xs:sequence>"
+" <xs:element name=\"xsd_path\" type=\"xs:string\" minOccurs=\"0\"/>"
+" <xs:element name=\"user_module\" type=\"xs:string\"/>"
+" <xs:element name=\"wsdl_file\" type=\"xsd_file\"/>"
+" <xs:element name=\"add_file\" type=\"xsd_file\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>"
+" </xs:sequence>"
+" </xs:complexType>"
+" </xs:element>"
+" <xs:complexType name=\"xsd_file\">"
+" <xs:sequence>"
+" <xs:element name=\"import_specs\" type=\"import_specs\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>"
+" </xs:sequence>"
+" <xs:attribute name=\"name\" type=\"string\" use=\"required\"/>"
+" <xs:attribute name=\"prefix\" type=\"string\"/>"
+" </xs:complexType>"
+" <xs:complexType name=\"import_specs\">"
+" <xs:attribute name=\"namespace\" type=\"string\" use=\"required\"/>"
+" <xs:attribute name=\"prefix\" type=\"string\"/>"
+" <xs:attribute name=\"location\" type=\"string\"/>"
+" </xs:complexType>"
+"</xs:schema>".
221 src/detergent_dime.erl
@@ -0,0 +1,221 @@
+%%%-------------------------------------------------------------------
+%%% @author Anders Nygren <anders.nygren@gmail.com>
+%%% @doc Encoding and decoding of DIME messages.
+%%% The Direct Internet Message Encapsulation (DIME) specification
+%%% defines a mechanism for packaging binary data with SOAP messages.
+%%% http://bgp.potaroo.net/ietf/all-ids/draft-nielsen-dime-02.txt
+%%% Layout of a DIME encoded message is like this
+%%%<pre>
+%%% 0 1 2 3
+%%% 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | |M|M|C| | | |
+%%% | VERSION |B|E|F| TYPE_T| RESRVD| OPTIONS_LENGTH |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | ID_LENGTH | TYPE_LENGTH |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | DATA_LENGTH |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | /
+%%% / OPTIONS + PADDING /
+%%% / |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | /
+%%% / ID + PADDING /
+%%% / |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | /
+%%% / TYPE + PADDING /
+%%% / |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%% | /
+%%% / DATA + PADDING /
+%%% / |
+%%% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+%%%<pre>
+%%% @end
+%%%
+%%% Created : 7 Apr 2008 by Anders Nygren <>
+%%%-------------------------------------------------------------------
+-module(detergent_dime).
+
+%% API
+-export([encode/2,
+ decode/1,
+ pad_len/1]).
+
+
+-include_lib("kernel/include/file.hrl").
+
+-define(VERSION1, 1).
+-define(T_UNCHANGED, 0).
+-define(T_MEDIA_TYPE, 1).
+-define(T_ABS_URI, 2).
+-define(T_UNKNOWN, 3).
+-define(T_NONE, 4).
+-define(SOAP_URI, "http://schemas.xmlsoap.org/soap/envelope").
+%%====================================================================
+%% API
+%%====================================================================
+%%--------------------------------------------------------------------
+%% @spec (Req, Attachments) ->binary()
+%% Description:
+%%--------------------------------------------------------------------
+encode(Req, []) ->
+ encode_part(1, 1, 0, ?T_ABS_URI, <<"">>, <<"">>, <<?SOAP_URI>>, Req);
+encode(Req, As) ->
+ list_to_binary([encode_part(1, 0, 0, ?T_ABS_URI, <<"">>, <<"">>, <<?SOAP_URI>>, Req)|
+ encode_attachments(As)]).
+
+encode_attachments([{attachment, Id, Type, File}]) ->
+ encode_part(0, 1, 0, ?T_ABS_URI, <<"">>, list_to_binary(Id), list_to_binary(Type), File);
+encode_attachments([{attachment, Id, Type, File} | As]) ->
+ [encode_part(0, 0, 0, ?T_ABS_URI, <<"">>, list_to_binary(Id), list_to_binary(Type), File)|
+ encode_attachments(As)].
+
+encode_part(MB, ME, CF, TypeT, Opts, ID, Type, Data) ->
+ Opts_len = size_of(Opts),
+ Opts_pad = pad_len(Opts_len),
+ Id_len = size_of(ID),
+ Id_pad = pad_len(Id_len),
+ Type_len = size_of(Type),
+ Type_pad = pad_len(Type_len),
+ Data_len = size_of(Data),
+ Data_pad = pad_len(Data_len),
+ Data1 = get_data(Data),
+ <<?VERSION1:5, MB:1, ME:1, CF:1, TypeT:4, 0:4,
+ Opts_len:1/big-integer-unit:16,
+ Id_len:1/big-integer-unit:16,
+ Type_len:1/big-integer-unit:16,
+ Data_len:1/big-integer-unit:32,
+ Opts:Opts_len/binary-unit:8, 0:Opts_pad/integer-unit:8,
+ ID:Id_len/binary-unit:8, 0:Id_pad/integer-unit:8,
+ Type:Type_len/binary-unit:8, 0:Type_pad/integer-unit:8,
+ Data1:Data_len/binary-unit:8, 0:Data_pad/integer-unit:8>>.
+
+pad_len(Len) ->
+ case Len rem 4 of
+ 0 ->
+ 0;
+ N ->
+ 4-N
+ end.
+
+size_of(X) when is_list(X) ->
+ length(X);
+size_of(X) when is_binary(X)->
+ size(X);
+size_of({file, File}) ->
+ {ok,R} = file:read_file_info(File),
+ R#file_info.size.
+
+get_data({file, File}) ->
+ {ok, Data} = file:read_file(File),
+ Data;
+get_data(Data) when is_list(Data) ->
+ list_to_binary(Data);
+
+get_data(Data) ->
+ Data.
+%%--------------------------------------------------------------------
+%% @spec (Msg::binary()) ->
+%% @doc Decode a DIME encoded message.
+%%--------------------------------------------------------------------
+decode(Msg) ->
+ decode_recs(Msg, [], []).
+
+decode_recs(<<>>, Acc, _Chunks) ->
+ Acc;
+decode_recs(Msg, Acc, Chunks) ->
+ case {decode_rec(Msg), Chunks} of
+ %% A normal record
+ {{_ME=0, _CF=0, Opts, ID, Type, Chunk, More}, []} ->
+ decode_recs(More, [{Opts, ID, Type, Chunk}|Acc], []);
+
+ %% The last chunk of a block, but not the last record
+ {{_ME=0, _CF=0, Opts, ID, Type, Chunk, More}, Chunks} ->
+ Cs = lists:reverse([{Opts, ID, Type, Chunk}|Chunks]),
+ %% Only the first chunk has values for Opts, Id and Type
+ {ROpts, RID, RType, _Chunk} = hd(Cs),
+ Block = list_to_binary([Ch || {_Opts, _ID, _Type, Ch} <- Cs]),
+ error_logger:info_report([?MODULE, decode_rec, merging,
+ {id, ID},{type, Type},
+ {chunks, length(Cs)}]),
+ decode_recs(More, [{ROpts, RID, RType, Block}|Acc], []);
+
+ %% Last record, but not chunked
+ {{_ME=1, _CF=0, Opts, ID, Type, Data, _More}, []} ->
+ lists:reverse([{Opts, ID, Type, Data}|Acc]);
+
+ %% Last record, and last chunk of block
+ {{_ME=1, _CF=0, Opts, ID, Type, Chunk, _More}, Chunks} ->
+ Cs = lists:reverse([{Opts, ID, Type, Chunk}|Chunks]),
+ {ROpts, RID, RType, _Chunk} = hd(Cs),
+ Block = list_to_binary([Ch || {_Opts, _ID, _Type, Ch} <- Cs]),
+ error_logger:info_report([?MODULE, decode_rec, merging,
+ {id, ID},{type, Type},
+ {chunks, length(Cs)}]),
+ lists:reverse([{ROpts, RID, RType, Block}|Acc]);
+
+ %% First or intermediate chunk, but not the last
+ {{_ME=0, _CF=1, Opts, ID, Type, Data, More}, Chunks} ->
+ decode_recs(More, Acc, [{Opts, ID, Type, Data}|Chunks]);
+
+ %% Something wrong, ME=1 and CF=1
+ ErrorResult ->
+ error_logger:error_report([?MODULE, decode_recs,
+ {result, ErrorResult}])
+ end.
+
+decode_rec(<<?VERSION1:5, _MB:1, ME:1, CF:1, _Type_T:4, _Res:4,
+ Opt_Len:1/big-integer-unit:16,
+ ID_Len:1/big-integer-unit:16,
+ Type_Len:1/big-integer-unit:16,
+ Data_Len:1/big-integer-unit:32,
+ Rest/binary>>=Block) ->
+ error_logger:info_report([?MODULE, decode_rec,
+ {version,1},
+ {mb,_MB},{me,ME},{cf,CF},{type_t,_Type_T},
+ {res,_Res},{opt_len,Opt_Len},{id_len,ID_Len},
+ {type_len,Type_Len},{date_len,Data_Len},
+ {total_rec_size,byte_size(Block)}]),
+ Opt_pad = pad_len(Opt_Len),
+ Id_pad = pad_len(ID_Len),
+ Type_pad = pad_len(Type_Len),
+ Data_pad = pad_len(Data_Len),
+ Header = Opt_Len+Opt_pad+ID_Len+Id_pad+Type_Len+Type_pad,
+ DataTot = Data_Len+Data_pad,
+ case byte_size(Rest) of
+ N when N >= Header+DataTot ->
+ <<Opts:Opt_Len/binary-unit:8, _:Opt_pad/binary-unit:8,
+ ID:ID_Len/binary-unit:8, _:Id_pad/binary-unit:8,
+ Type:Type_Len/binary-unit:8, _:Type_pad/binary-unit:8,
+ Data:Data_Len/binary-unit:8, _:Data_pad/binary-unit:8,
+ More/binary >> = Rest,
+ {ME, CF, Opts, ID, Type, Data, More};
+ N when N > Header->
+ <<Opts:Opt_Len/binary-unit:8, _:Opt_pad/binary-unit:8,
+ ID:ID_Len/binary-unit:8, _:Id_pad/binary-unit:8,
+ Type:Type_Len/binary-unit:8, _:Type_pad/binary-unit:8,
+ Data/binary>> = Rest,
+ error_logger:error_report([?MODULE, decode_rec, short_record,
+ {need, Header+DataTot},
+ {has, N}]),
+ {ME, CF, Opts, ID, Type, Data, <<>>};
+ N ->
+ error_logger:error_report([?MODULE, decode_rec, short_record,
+ {need, Header+DataTot},
+ {has, N}]),
+ {error, not_enough_data}
+ end;
+
+decode_rec(Bin) ->
+ error_logger:error_report([?MODULE, decode_rec, short_record,
+ no_header,
+ {has, byte_size(Bin)}]),
+ {error, no_header}.
+
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
250 src/detergent_server.erl
@@ -0,0 +1,250 @@
+%%%-------------------------------------------------------------------
+%%% Created : 29 Nov 2006 by Torbjorn Tornkvist <tobbe@tornkvist.org>
+%%% Author : Willem de Jong (w.a.de.jong@gmail.com).
+%%% Desc : A SOAP server.
+%%%-------------------------------------------------------------------
+-module(detergent_server).
+
+-behaviour(gen_server).
+
+%% API
+-export([start_link/0, start_link/1,
+ setup/1, setup/2, setup/3
+ ]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-include("../include/detergent.hrl").
+
+-define(SERVER, ?MODULE).
+
+%% State
+-record(s, {
+ wsdl_list = [] % list of {Id, WsdlModel} tuples, where Id == {M,F}
+ }).
+
+-define(OK_CODE, 200).
+-define(BAD_MESSAGE_CODE, 400).
+%% -define(METHOD_NOT_ALLOWED_CODE, 405).
+-define(SERVER_ERROR_CODE, 500).
+
+%%====================================================================
+%% API
+%%====================================================================
+%%--------------------------------------------------------------------
+%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
+%% Description: Starts the server
+%%--------------------------------------------------------------------
+start_link() ->
+ start_link([]).
+start_link(L) ->
+ %% We are dependent on erlsom
+ case code:ensure_loaded(erlsom) of
+ {error, _} ->
+ Emsg = "could not load erlsom",
+ error_logger:error_msg("~p: exiting, reason: ~s~n",
+ [?MODULE, Emsg]),
+ {error, Emsg};
+ {module, erlsom} ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, L, [])
+ end.
+
+%% Setup a SOAP interface according to the config file.
+setup(_ConfigFile) ->
+ tbd.
+
+setup(Id, WsdlFile) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = detergent:initModel(WsdlFile),
+ gen_server:call(?SERVER, {add_wsdl, Id, Wsdl}, infinity).
+
+
+setup(Id, WsdlFile, Prefix) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = detergent:initModel(WsdlFile, Prefix),
+ gen_server:call(?SERVER, {add_wsdl, Id, Wsdl}, infinity).
+
+
+
+%%====================================================================
+%% gen_server callbacks
+%%====================================================================
+
+%%--------------------------------------------------------------------
+%% Function: init(Args) -> {ok, State} |
+%% {ok, State, Timeout} |
+%% ignore |
+%% {stop, Reason}
+%% Description: Initiates the server
+%%--------------------------------------------------------------------
+init(L) -> %% [ {{Mod,Handler}, WsdlFile} ]
+ WsdlList = lists:foldl( fun( SoapSrvMod, OldList) ->
+ setup_on_init( SoapSrvMod, OldList )
+ end,[],L),
+ {ok, #s{wsdl_list = WsdlList}}.
+
+setup_on_init( {Id, WsdlFile}, OldList ) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = detergent:initModel(WsdlFile),
+ uinsert({Id, Wsdl}, OldList);
+setup_on_init( {Id, WsdlFile, Prefix}, OldList ) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = detergent:initModel(WsdlFile, Prefix),
+ uinsert({Id, Wsdl}, OldList).
+
+%%--------------------------------------------------------------------
+%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
+%% {reply, Reply, State, Timeout} |
+%% {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, Reply, State} |
+%% {stop, Reason, State}
+%% Description: Handling call messages
+%%--------------------------------------------------------------------
+handle_call({add_wsdl, Id, WsdlModel}, _From, State) ->
+ NewWsdlList = uinsert({Id, WsdlModel}, State#s.wsdl_list),
+ {reply, ok, State#s{wsdl_list = NewWsdlList}};
+%%
+handle_call( {request, Id, Payload, SessionValue, SoapAction}, _From, State) ->
+ Reply = request(State, Id, Payload, SessionValue, SoapAction),
+ {reply, Reply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: handle_cast(Msg, State) -> {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, State}
+%% Description: Handling cast messages
+%%--------------------------------------------------------------------
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: handle_info(Info, State) -> {noreply, State} |
+%% {noreply, State, Timeout} |
+%% {stop, Reason, State}
+%% Description: Handling all non call/cast messages
+%%--------------------------------------------------------------------
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+%%--------------------------------------------------------------------
+%% Function: terminate(Reason, State) -> void()
+%% Description: This function is called by a gen_server when it is about to
+%% terminate. It should be the opposite of Module:init/1 and do any necessary
+%% cleaning up. When it returns, the gen_server terminates with Reason.
+%% The return value is ignored.
+%%--------------------------------------------------------------------
+terminate(_Reason, _State) ->
+ ok.
+
+%%--------------------------------------------------------------------
+%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
+%% Description: Convert process state when code is changed
+%%--------------------------------------------------------------------
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%--------------------------------------------------------------------
+%%% Internal functions
+%%--------------------------------------------------------------------
+
+request(State, {M,F} = Id, {Req, Attachments}, SessionValue, Action) ->
+ {ok, Model} = get_model(State, Id),
+ %%error_logger:info_report([?MODULE, {payload, Req}]),
+ case catch detergent:parseMessage(Req, Model) of
+ {ok, Header, Body} ->
+ %% call function
+ result(Model, catch apply(M, F, [Header, Body,
+ Action, SessionValue,
+ Attachments]));
+ {error, Error} ->
+ cli_error(Error);
+ OtherError ->
+ srv_error(io_lib:format("Error parsing message: ~p", [OtherError]))
+ end;
+request(State, {M,F} = Id, Req, SessionValue, Action) ->
+ %%error_logger:info_report([?MODULE, {payload, Req}]),
+ {ok, Model} = get_model(State, Id),
+ Umsg = (catch erlsom_lib:toUnicode(Req)),
+ case catch detergent:parseMessage(Umsg, Model) of
+ {ok, Header, Body} ->
+ %% call function
+ result(Model, catch apply(M, F, [Header, Body,
+ Action, SessionValue]));
+ {error, Error} ->
+ cli_error(Error);
+ OtherError ->
+ srv_error(io_lib:format("Error parsing message: ~p", [OtherError]))
+ end.
+
+%%% Analyse the result and produce some output
+result(Model, {ok, ResHeader, ResBody, ResCode, SessVal}) ->
+ return(Model, ResHeader, ResBody, ResCode, SessVal, undefined);
+result(Model, {ok, ResHeader, ResBody}) ->
+ return(Model, ResHeader, ResBody, ?OK_CODE, undefined, undefined);
+result(Model, {ok, ResHeader, ResBody, Files}) ->
+ return(Model, ResHeader, ResBody, ?OK_CODE, undefined, Files);
+result(_Model, {error, client, ClientMssg}) ->
+ cli_error(ClientMssg);
+result(_Model, false) -> % soap notify !
+ false;
+result(_Model, Error) ->
+ srv_error(io_lib:format("Error processing message: ~p", [Error])).
+
+return(#wsdl{model = Model}, ResHeader, ResBody, ResCode, SessVal, Files) ->
+ return(Model, ResHeader, ResBody, ResCode, SessVal, Files);
+return(Model, ResHeader, ResBody, ResCode, SessVal, Files) when not is_list(ResBody) ->
+ return(Model, ResHeader, [ResBody], ResCode, SessVal, Files);
+return(Model, ResHeader, ResBody, ResCode, SessVal, Files) ->
+ %% add envelope
+ Header2 = case ResHeader of
+ undefined -> undefined;
+ _ -> #'soap:Header'{choice = ResHeader}
+ end,
+ Envelope = #'soap:Envelope'{'Body' = #'soap:Body'{choice = ResBody},
+ 'Header' = Header2},
+ case catch erlsom:write(Envelope, Model) of
+ {ok, XmlDoc} ->
+ case Files of
+ undefined ->
+ {ok, XmlDoc, ResCode, SessVal};
+ _ ->
+ DIME = detergent_dime:encode(XmlDoc, Files),
+ {ok, DIME, ResCode, SessVal}
+ end;
+ {error, WriteError} ->
+ srv_error(f("Error writing XML: ~p", [WriteError]));
+ OtherWriteError ->
+ error_logger:error_msg("~p(~p): OtherWriteError=~p~n",
+ [?MODULE, ?LINE, OtherWriteError]),
+ srv_error(f("Error writing XML: ~p", [OtherWriteError]))
+ end.
+
+f(S,A) -> lists:flatten(io_lib:format(S,A)).
+
+cli_error(Error) ->
+ error_logger:error_msg("~p(~p): Cli Error: ~p~n",
+ [?MODULE, ?LINE, Error]),
+ Fault = detergent:makeFault("Client", "Client error"),
+ {error, Fault, ?BAD_MESSAGE_CODE}.
+
+srv_error(Error) ->
+ error_logger:error_msg("~p(~p): Srv Error: ~p~n",
+ [?MODULE, ?LINE, Error]),
+ Fault = detergent:makeFault("Server", "Server error"),
+ {error, Fault, ?SERVER_ERROR_CODE}.
+
+
+
+
+get_model(State, Id) ->
+ case lists:keysearch(Id, 1, State#s.wsdl_list) of
+ {value, {_, Model}} -> {ok, Model};
+ _ -> {error, "model not found"}
+ end.
+
+uinsert({K,_} = E, [{K,_}|T]) -> [E|T];
+uinsert(E, [H|T]) -> [H|uinsert(E,T)];
+uinsert(E, []) -> [E].
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.