Skip to content
Browse files

Adding SOAP processing capabilities to Yaws.

Read the www/soap_intro.yaws for more info.


git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@1044 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 9605d55 commit c332fc225f2fae7659809b99bedd287bddaa6466 Tobbe Tornquist committed
Showing with 1,856 additions and 40 deletions.
  1. +28 −0 include/erlsom.hrl
  2. +48 −0 include/soap.hrl
  3. +2 −1 include/yaws.hrl
  4. +126 −0 priv/envelope.xsd
  5. +149 −0 priv/soap.xsd
  6. +314 −0 priv/wsdl.xsd
  7. +2 −1 src/Makefile
  8. +5 −1 src/yaws.erl
  9. +23 −0 src/yaws_config.erl
  10. +71 −34 src/yaws_rpc.erl
  11. +489 −0 src/yaws_soap_lib.erl
  12. +233 −0 src/yaws_soap_srv.erl
  13. +1 −0 www/TAB.inc
  14. +6 −3 www/json_intro.yaws
  15. +359 −0 www/soap_intro.yaws
View
28 include/erlsom.hrl
@@ -0,0 +1,28 @@
+%%% ====================================================================
+%%% Header file for erlsom
+%%%
+%%% Copyright (C) 2006 Willem de Jong
+%%%
+%%% This program is free software; you can redistribute it and/or modify
+%%% it under the terms of the GNU General Public License as published by
+%%% the Free Software Foundation; either version 2 of the License, or
+%%% (at your option) any later version.
+%%%
+%%% This program is distributed in the hope that it will be useful, but
+%%% WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%%% General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU General Public License
+%%% along with this program; if not, write to the Free Software
+%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+%%% USA
+%%%
+%%% Author contact: w.a.de.jong@gmail.com
+%%% ====================================================================
+
+%%% version: 0.0.2
+
+%% prefix=the prefix that will be used in the result
+-record(ns, {uri, prefix}).
+-record(qname, {uri, localPart, prefix, mappedPrefix}).
View
48 include/soap.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'}).
View
3 include/yaws.hrl
@@ -89,7 +89,8 @@
%username, %% maybe run as a different user than root
%uid, %% unix uid of user that started yaws
id = "default", %% string identifying this instance of yaws
- tmpdir
+ tmpdir,
+ enable_soap = false %% start yaws_soap_srv iff true
}).
View
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>
+
+
+
+
+
+
View
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>
View
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>
View
3 src/Makefile
@@ -34,7 +34,8 @@ MODULES=yaws \
yaws_dav \
yaws_pam \
json jsonrpc yaws_jsonrpc yaws_xmlrpc\
- haxe yaws_rpc
+ haxe yaws_rpc \
+ yaws_soap_srv yaws_soap_lib
EBIN_FILES=$(MODULES:%=../ebin/%.$(EMULATOR)) ../ebin/yaws.app
View
6 src/yaws.erl
@@ -44,7 +44,9 @@ start_embedded(DocRoot, SL, GL) when list(DocRoot),list(SL),list(GL) ->
application:start(yaws),
GC = setup_gconf(GL, yaws_config:make_default_gconf(false, "")),
SC = setup_sconf(DocRoot, #sconf{}, SL),
+ yaws_config:add_yaws_soap_srv(GC),
yaws_api:setconf(GC, [[SC]]).
+
setup_gconf([], GC) -> GC;
setup_gconf(GL, GC) ->
@@ -83,7 +85,9 @@ setup_gconf(GL, GC) ->
id = lkup(id, GL,
GC#gconf.id),
tmpdir = lkup(tmpdir, GL,
- GC#gconf.tmpdir)
+ GC#gconf.tmpdir),
+ enable_soap = lkup(enable_soap, GL,
+ GC#gconf.enable_soap)
}.
set_gc_flags([{tty_trace, Bool}|T], Flags) ->
View
23 src/yaws_config.erl
@@ -68,6 +68,7 @@ load(E) ->
{ok, GC5, Cs} ->
yaws:mkdir(GC#gconf.tmpdir),
Cs2 = add_yaws_auth(Cs),
+ add_yaws_soap_srv(GC5),
validate_cs(GC5, Cs2);
Err ->
Err
@@ -77,6 +78,19 @@ load(E) ->
end.
+add_yaws_soap_srv(GC) when GC#gconf.enable_soap == true ->
+ SoapStarted = (whereis(yaws_soap_srv) /= undefined),
+ if (SoapStarted == false) ->
+ Spec = {yaws_soap_srv, {yaws_soap_srv, start_link, []},
+ permanent, 5000, worker, [yaws_soap_srv]},
+ spawn(fun() -> supervisor:start_child(yaws_sup, Spec) end);
+ true ->
+ ok
+ end;
+add_yaws_soap_srv(_GC) ->
+ ok.
+
+
add_yaws_auth(SCs) ->
lists:map(
fun(SC) ->
@@ -367,6 +381,15 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
fload(FD, globals, GC#gconf{runmods = [Mod|GC#gconf.runmods]},
C, Cs, Lno+1, Next);
+ ["enable_soap", '=', Bool] ->
+ if (Bool == "true") ->
+ fload(FD, globals, GC#gconf{enable_soap = true},
+ C, Cs, Lno+1, Next);
+ true ->
+ fload(FD, globals, GC#gconf{enable_soap = false},
+ C, Cs, Lno+1, Next)
+ end;
+
["log_wrap_size", '=', Int] ->
case (catch list_to_integer(Int)) of
I when integer(I) ->
View
105 src/yaws_rpc.erl
@@ -36,7 +36,8 @@
%% modified by Yariv Sadan (yarivvv@gmail.com)
-module(yaws_rpc).
--author("Gaspar Chilingarov <nm@web.am>, Gurgen Tumanyan <barbarian@armkb.com>"). -modified_by("Yariv Sadan <yarivvv@gmail.com>").
+-author("Gaspar Chilingarov <nm@web.am>, Gurgen Tumanyan <barbarian@armkb.com>").
+-modified_by("Yariv Sadan <yarivvv@gmail.com>").
-export([handler/2]).
-export([handler_session/2, handler_session/3]).
@@ -124,18 +125,21 @@ handle_payload(Args, Handler, Type) -> % {{{
eval_payload(Args, Handler, DecodedPayload, Type, ID, RpcType);
{error, Reason} ->
?ERROR_LOG({html, client2erl, Payload, Reason}),
- send(Args, 400)
+ send(Args, 400, RpcType)
end. % }}}
%%% Identify the RPC type. We first try recognize haXe by the
-%%% "X-Haxe-Remoting" HTTP header, and if it's absent we
-%%% assume the request is JSON.
+%%% "X-Haxe-Remoting" HTTP header, then the "SOAPAction" header,
+%%% and if those are absent we assume the request is JSON.
recognize_rpc_type(Args) ->
OtherHeaders = ((Args#arg.headers)#headers.other),
- case lists:any(fun(A) -> element(3, A) == "X-Haxe-Remoting" end, OtherHeaders) of
- true -> haxe;
- _ -> json
- end.
+ recognize_rpc_hdr([{X,Y,yaws:to_lower(Z),Q,W} || {X,Y,Z,Q,W} <- OtherHeaders]).
+
+recognize_rpc_hdr([{_,_,"x-haxe-remoting",_,_}|_]) -> haxe;
+recognize_rpc_hdr([{_,_,"soapaction",_,_}|_]) -> soap;
+recognize_rpc_hdr([_|T]) -> recognize_rpc_hdr(T);
+recognize_rpc_hdr([]) -> json.
+
%%%
%%% call handler/3 and provide session support
@@ -152,32 +156,31 @@ eval_payload(Args, {M, F}, Payload, {session, CookieName}, ID, RpcType) -> % {{{
{undefined, undefined}
end
end,
- case catch M:F(Args#arg.state, Payload, SessionValue) of
+ CbackFun = callback_fun(M, F, Args, Payload, SessionValue, RpcType),
+ case catch CbackFun() of
{'EXIT', Reason} ->
?ERROR_LOG({M, F, {'EXIT', Reason}}),
- send(Args, 500);
+ send(Args, 500, RpcType);
{error, Reason} ->
?ERROR_LOG({M, F, Reason}),
- send(Args, 500);
+ send(Args, 500, RpcType);
+ {error, Reason, Rc} ->
+ ?ERROR_LOG({M, F, Reason}),
+ send(Args, Rc, Reason, [], RpcType);
{false, ResponsePayload} ->
% do not have updates in session data
encode_send(Args, 200, ResponsePayload, [], ID, RpcType);
+ {false, ResponsePayload, RespCode} ->
+ % do not have updates in session data
+ encode_send(Args, RespCode, ResponsePayload, [], ID, RpcType);
+ false -> % soap notify
+ false;
{true, _NewTimeout, NewSessionValue, ResponsePayload} -> % be compatible with xmlrpc module
- CO = case NewSessionValue of
- undefined when Cookie == undefined -> []; % nothing to do
- undefined -> % rpc handler requested session delete
- yaws_api:delete_cookie_session(Cookie), []; % XXX: may be return set-cookie with empty val?
- _ -> % any other value will stored in session
- case SessionValue of
- undefined -> % got session data and should start new session now
- Cookie1 = yaws_api:new_cookie_session(NewSessionValue),
- yaws_api:setcookie(CookieName, Cookie1, "/"); % return set_cookie header
- _ ->
- yaws_api:replace_cookie_session(Cookie, NewSessionValue),
- [] % nothing to add to yaws data
- end
- end,
- encode_send(Args, 200, ResponsePayload, CO, ID, RpcType)
+ CO = handle_cookie(Cookie, CookieName, SessionValue, NewSessionValue),
+ encode_send(Args, 200, ResponsePayload, CO, ID, RpcType);
+ {true, _NewTimeout, NewSessionValue, ResponsePayload, RespCode} -> % be compatible with xmlrpc module
+ CO = handle_cookie(Cookie, CookieName, SessionValue, NewSessionValue),
+ encode_send(Args, RespCode, ResponsePayload, CO, ID, RpcType)
end; % }}}
%%%
@@ -193,10 +196,33 @@ eval_payload(Args, {M, F}, Payload, simple, ID, RpcType) -> % {{{
send(Args, 500);
{false, ResponsePayload} ->
encode_send(Args, 200, ResponsePayload, [], ID, RpcType);
+ false -> % Soap notify !?
+ false;
{true, _NewTimeout, _NewState, ResponsePayload} ->
encode_send(Args, 200, ResponsePayload, [], ID, RpcType)
end. % }}}
+handle_cookie(Cookie, CookieName, SessionValue, NewSessionValue) ->
+ case NewSessionValue of
+ undefined when Cookie == undefined -> []; % nothing to do
+ undefined -> % rpc handler requested session delete
+ yaws_api:delete_cookie_session(Cookie), []; % XXX: may be return set-cookie with empty val?
+ _ -> % any other value will stored in session
+ case SessionValue of
+ undefined -> % got session data and should start new session now
+ Cookie1 = yaws_api:new_cookie_session(NewSessionValue),
+ yaws_api:setcookie(CookieName, Cookie1, "/"); % return set_cookie header
+ _ ->
+ yaws_api:replace_cookie_session(Cookie, NewSessionValue),
+ [] % nothing to add to yaws data
+ end
+ end.
+
+callback_fun(M, F, Args, Payload, SessionValue, soap) ->
+ fun() -> yaws_soap_srv:handler(Args, {M,F}, Payload, SessionValue) end;
+callback_fun(M, F, Args, Payload, SessionValue, _RpcType) ->
+ fun() -> M:F(Args#arg.state, Payload, SessionValue) end.
+
%%% XXX compatibility with XMLRPC handlers
%%% XXX - potential bug here?
@@ -208,26 +234,34 @@ encode_send(Args, StatusCode, Payload, AddOn, ID, RpcType) -> % {{{
case encode_handler_payload(Payload, ID, RpcType) of
{ok, EncodedPayload} ->
% ?Debug("rpc encoded response ~p ~n", [EncodedPayload]),
- send(Args, StatusCode, EncodedPayload, AddOn);
+ send(Args, StatusCode, EncodedPayload, AddOn, RpcType);
{error, Reason} ->
?ERROR_LOG({rpc_encode, payload, Payload, Reason}),
- send(Args, 500)
+ send(Args, 500, RpcType)
end. % }}}
-send(Args, StatusCode) -> send(Args, StatusCode, "", []). % {{{
+send(Args, StatusCode) -> send(Args, StatusCode, json).
+
+send(Args, StatusCode, RpcType) -> send(Args, StatusCode, "", [], RpcType). % {{{
-send(Args, StatusCode, Payload, AddOnData) when not is_list(AddOnData) ->
- send(Args, StatusCode, Payload, [AddOnData]);
+send(Args, StatusCode, Payload, AddOnData, RpcType) when not is_list(AddOnData) ->
+ send(Args, StatusCode, Payload, [AddOnData], RpcType);
-send(_Args, StatusCode, Payload, AddOnData) ->
+send(_Args, StatusCode, Payload, AddOnData, RpcType) ->
A = [
{status, StatusCode},
- {content, "text/xml", Payload},
+ content_hdr(RpcType, Payload),
{header, {content_length, lists:flatlength(Payload) }}
] ++ AddOnData,
A
. % }}}
+content_hdr(json, Payload) -> {content, "application/json", Payload};
+content_hdr(_, Payload) -> {content, "text/xml", Payload}. % FIXME would like to add charset info here !!
+
+encode_handler_payload(Xml, _ID, soap) -> % {{{
+ {ok, Xml};
+
encode_handler_payload({response, [ErlStruct]}, ID, RpcType) -> % {{{
encode_handler_payload({response, ErlStruct}, ID, RpcType);
@@ -262,7 +296,10 @@ decode_handler_payload(haxe, [$_, $_, $x, $= | HaxeStr]) ->
error:Err -> {error, Err}
end;
decode_handler_payload(haxe, _HaxeStr) ->
- {error, missing_haxe_prefix}.
+ {error, missing_haxe_prefix};
+
+decode_handler_payload(soap, Payload) ->
+ {ok, Payload, undefined}.
% vim: tabstop=4 ft=erlang
View
489 src/yaws_soap_lib.erl
@@ -0,0 +1,489 @@
+%%%-------------------------------------------------------------------
+%%% Created : 29 Nov 2006 by Torbjorn Tornkvist <tobbe@tornkvist.org>
+%%% Author : Willem de Jong (w.a.de.jong@gmail.com).
+%%% Desc. : Common SOAP code.
+%%%-------------------------------------------------------------------
+-module(yaws_soap_lib).
+
+-export([initModel/1, initModel/2,
+ initModelFile/1,
+ config_file_xsd/0,
+ call/3, call/5, call/6,
+ 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/soap.hrl").
+-include("../include/erlsom.hrl"). % FIXME a better solution ?
+
+-record(yaws_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}).
+
+-define(DefaultPrefix, "p").
+
+
+%%%
+%%% Writes the header file (record definitions) for a WSDL file
+%%%
+write_hrl(WsdlURL, Output) when list(WsdlURL) ->
+ write_hrl(initModel(WsdlURL), Output);
+write_hrl(#wsdl{model = Model}, Output) when list(Output) ->
+ erlsom:write_hrl(Model, Output).
+
+write_hrl(WsdlURL, Output, Prefix) when list(WsdlURL),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 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 list(WsdlURL) ->
+ Wsdl = initModel(WsdlURL, ?DefaultPrefix),
+ call(Wsdl, Operation, ListOfData);
+call(Wsdl, Operation, ListOfData) when record(Wsdl, wsdl) ->
+ case get_operation(Wsdl#wsdl.operations, Operation) of
+ {ok, Op} ->
+ Msg = mk_msg(?DefaultPrefix, Operation, ListOfData),
+ call(Operation, Op#operation.port, Op#operation.service, Msg, Wsdl);
+ 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
+%%% --------------------------------------------------------------------
+call(Operation, Port, Service, Message, WSDL) ->
+ call(Operation, Port, Service, Message, WSDL, []).
+
+call(Operation, Port, Service, Message, #wsdl{operations = Operations, model = Model}, Headers) ->
+ %% 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} ->
+ Request = make_request_body(XmlMessage),
+ HttpHeaders = [],
+ HttpClientOptions = [],
+ HttpRes = http_request(URL, SoapAction, Request, HttpClientOptions, HttpHeaders),
+ 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:parse(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(Message, []) ->
+ #'soap:Envelope'{'Body' = #'soap:Body'{choice = [Message]}};
+mk_envelope(Message, Headers) ->
+ #'soap:Envelope'{'Body' = #'soap:Body'{choice = [Message]},
+ '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:parse_file(ConfigFile, ConfigSchema),
+ #yaws_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(yaws)),"..", "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),
+ %% parse Wsdl
+ {ok, WsdlFileContent} = get_url_file(rmsp(WsdlFile)),
+ {ok, ParsedWsdl} = erlsom:parse(WsdlFileContent, WsdlModel2),
+ %% get the xsd elements from this model, and hand it over to erlsom_compile.
+ Xsd = getXsdFromWsdl(ParsedWsdl),
+ %% Ns = [#ns{prefix="xsd", uri="http://www.w3.org/2001/XMLSchema"}],
+ %% TODO: pass the right options here
+ Options = makeOptions(Import),
+ {ok, Model} = erlsom_compile:compile_parsed_xsd(Xsd, [{prefix, Prefix} | Options]),
+ %% 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),
+ Ports = getPorts(ParsedWsdl),
+ Operations = getOperations(ParsedWsdl, Ports),
+ #wsdl{operations = Operations, model = SoapModel2}.
+
+
+
+%%% --------------------------------------------------------------------
+%%% Get a file from an URL spec.
+%%% --------------------------------------------------------------------
+get_url_file("http://"++_ = URL) ->
+ case http:request(URL) of
+ {ok,{{_HTTP,200,_OK}, _Headers, Body}} ->
+ case http_uri:parse(URL) of
+ {_Method, _Host, _Port, _Path, _Qargs} ->
+ {ok, Body};
+ _ ->
+ {error, "failed to retrieve: "++URL}
+ end
+ end;
+get_url_file("file://"++Fname) ->
+ {ok, Bin} = file:read_file(Fname),
+ {ok, binary_to_list(Bin)}.
+
+
+%%% --------------------------------------------------------------------
+%%% Make a HTTP Request
+%%% --------------------------------------------------------------------
+http_request(URL, SoapAction, Request, Options, Headers) ->
+ 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);
+ _ ->
+ %% ...otherwise, let's use the OTP http client.
+ inets_request(URL, SoapAction, Request, Options, Headers)
+ end.
+
+inets_request(URL, SoapAction, Request, Options, Headers) ->
+ NewHeaders = [{"Host", "localhost:8800"}, {"SOAPAction", SoapAction}|Headers],
+ NewOptions = [{cookies, enabled}|Options],
+ http:set_options(NewOptions),
+ case http:request(post,
+ {URL,NewHeaders,
+ "text/xml; charset=utf-8",
+ Request},
+ [{http_timeout,20000}],
+ [{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) ->
+ case start_ibrowse() of
+ ok ->
+ NewHeaders = [{"SOAPAction", SoapAction} | Headers],
+ NewOptions = [{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) ->
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>"++Content.
+
+
+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(yaws:to_lower(Label), Headers).
+
+findHeader0(_Label, []) ->
+ undefined;
+findHeader0(Label, [{_,_,Hdr,_,Val}|T]) ->
+ case {Label, yaws: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.
+
+%% 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)
+ end.
+
+
+getXsdFromWsdl(Definitions) ->
+ [#'wsdl:tTypes'{choice = [Xsd]}] = getTopLevelElements(Definitions, 'wsdl:tTypes'),
+ Xsd.
+
+config_file_xsd() ->
+"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
+" <xs:element name=\"yaws_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>".
View
233 src/yaws_soap_srv.erl
@@ -0,0 +1,233 @@
+%%%-------------------------------------------------------------------
+%%% 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(yaws_soap_srv).
+
+-behaviour(gen_server).
+
+%% API
+-export([start_link/0,
+ setup/1, setup/2, setup/3,
+ handler/4
+ ]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-include("../include/yaws_api.hrl").
+-include("../include/yaws.hrl").
+-include("../include/soap.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() ->
+ %% 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, [], [])
+ end.
+
+%%% To be called from yaws_rpc.erl
+%%% Return according to yaws_rpc:eval_payload/6
+handler(Args, Id, Payload, SessionValue) ->
+ Headers = Args#arg.headers,
+ SoapAction = yaws_soap_lib:findHeader("SOAPAction", Headers#headers.other),
+ case gen_server:call(?SERVER, {request, Id, Payload, SessionValue, SoapAction}) of
+ {ok, XmlDoc, ResCode, undefined} ->
+ {false, XmlDoc, ResCode};
+ {ok, XmlDoc, ResCode, SessVal} ->
+ {true, 0, SessVal, XmlDoc, ResCode};
+ {error, _, _} = Error ->
+ Error;
+ false ->
+ false % soap notify
+ end.
+
+%% Setup a SOAP interface according to the config file.
+setup(ConfigFile) ->
+ tbd.
+
+setup(Id, WsdlFile) when tuple(Id),size(Id)==2 ->
+ Wsdl = yaws_soap_lib:initModel(WsdlFile),
+ gen_server:call(?SERVER, {add_wsdl, Id, Wsdl}).
+
+
+setup(Id, WsdlFile, Prefix) when tuple(Id),size(Id)==2 ->
+ Wsdl = yaws_soap_lib:initModel(WsdlFile, Prefix),
+ gen_server:call(?SERVER, {add_wsdl, Id, Wsdl}).
+
+
+
+%%====================================================================
+%% gen_server callbacks
+%%====================================================================
+
+%%--------------------------------------------------------------------
+%% Function: init(Args) -> {ok, State} |
+%% {ok, State, Timeout} |
+%% ignore |
+%% {stop, Reason}
+%% Description: Initiates the server
+%%--------------------------------------------------------------------
+init([]) ->
+ {ok, #s{}}.
+
+%%--------------------------------------------------------------------
+%% 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, Payload, SessionValue, Action) ->
+ {ok, Model} = get_model(State, Id),
+ Umsg = (catch erlsom_lib:toUnicode(Payload)),
+ case catch yaws_soap_lib: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);
+result(Model, {ok, ResHeader, ResBody}) ->
+ return(Model, ResHeader, ResBody, ?OK_CODE, undefined);
+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) ->
+ return(Model, ResHeader, ResBody, ResCode, SessVal);
+return(Model, ResHeader, ResBody, ResCode, SessVal) when not is_list(ResBody) ->
+ return(Model, ResHeader, [ResBody], ResCode, SessVal);
+return(Model, ResHeader, ResBody, ResCode, SessVal) ->
+ %% 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} ->
+ {ok, XmlDoc, ResCode, SessVal};
+ {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 = yaws_soap_lib: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 = yaws_soap_lib: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].
+
+
+
+
View
1 www/TAB.inc
@@ -52,6 +52,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<div class="%%embed%%"> <a href="/embed.yaws">Embedding Yaws</a></div>
<div class="%%json_intro%%"> <a href="/json_intro.yaws">AJAX/Json RPC</a></div>
<div class="%%haxe_intro%%"> <a href="/haxe_intro.yaws">haXe remoting</a></div>
+<div class="%%soap_intro%%"> <a href="/soap_intro.yaws">SOAP with Yaws</a></div>
<div class="%%yapp_intro%%"> <a href="/yapp_intro.yaws">Yaws applications</a></div>
<h4> Misc </h4>
<div class="%%internals%%"> <a href="/internals.yaws">Internals</a> </div>
View
9 www/json_intro.yaws
@@ -30,11 +30,14 @@ out(A) ->
[{h1, [], "AJAX through JSON RPC"},
{p, [],
- {i, [], "Note: this documentation used to refer to the module "
+ {i, [],
+ ["Note: this documentation used to refer to the module "
"'yaws_jsonrpc'. This module has been depracated in favor "
- "of 'yaws_rpc', which handles both JSON RPC and haXe "
+ "of 'yaws_rpc', which handles both JSON RPC, haXe and SOAP "
"remoting. All references to 'yaws_jsonrpc' on this page "
- "were therefore changed to 'yaws_rpc'."}},
+ "were therefore changed to 'yaws_rpc'. For more specific "
+ "information about SOAP, refer to ",
+ {a, [{href, "/soap_intro.yaws"}], "the SOAP page."}]}},
{p, [],
["The Yaws Json binding is a way to have Javascript code in the "
"browser evaluate a remote procedure call in the Yaws server."
View
359 www/soap_intro.yaws
@@ -0,0 +1,359 @@
+
+<erl>
+
+
+box(Str) ->
+ {'div',[{class,"box"}],
+ {pre,[], yaws_api:htmlize(Str)}}.
+
+tbox(T) ->
+ box(lists:flatten(io_lib:format("~p",[T]))).
+
+
+ssi(File) ->
+ {'div',[{class,"box"}],
+ {pre,[],
+ {ssi, File,[],[]}}}.
+
+ss(A, File) ->
+ {ok, B} = file:read_file(
+ filename:join([A#arg.docroot, File])),
+ box(binary_to_list(B)).
+
+
+
+out(A) ->
+ [{ssi, "TAB.inc", "%%",[{"soap_intro", "choosen"}]},
+ {ehtml,
+ {'div', [{id, "entry"}],
+
+ [{h1, [], "SOAP with Yaws"},
+
+ {p, [],
+ ["SOAP is an XML-based protocol for communication over a network "
+ "connection. The main focus of SOAP is remote procedure calls (RPCs) "
+ "transported via HTTP. "
+ "SOAP is similar to XML-RPC but makes use of XML Schema to define "
+ "the data types it is making use of. "
+ ]},
+
+ {h2, [], "Preparations"},
+
+ {p, [],
+ ["Yaws is making use of the 'erlsom' XML Schema "
+ "parser and some SOAP specific library code. "
+ "Thus, to be able to use SOAP with Yaws you need to have "
+ "'erlsom' installed. Currently, the easiest way of installing "
+ "'erlsom' is to check out the library from Sourceforge and "
+ "install it from there. "]},
+
+ {p,[],"To install 'erlsom' do:"},
+
+ box("cvs -d:pserver:anonymous@erlsom.cvs.sourceforge.net:/cvsroot/erlsom login\n"
+ " cvs -z3 -d:pserver:anonymous@erlsom.cvs.sourceforge.net:/cvsroot/erlsom co -P erlsom\n"
+ "cd erlsom; make\n"
+ "sudo make install # iff you want to install as root\n"
+ ),
+
+ {h2, [], "The SOAP client side"},
+
+ {p, [],
+ ["The SOAP interface is defined by a WSDL specification, which "
+ "simply is a (rather verbose) piece of XML document that specifies "
+ "the public interface for a web service. As a client, "
+ "we don't need to understand everything in the WSDL specification "
+ "The parts that are most interesting is the name of the operation "
+ "we want to perform (i.e the function we want to call) and what "
+ "input data it expects."
+ ]},
+
+ {p,[],
+ ["As an example, lets have a look at a public SOAP service that "
+ "returns some weather data for the location we send to it. "
+ "The WSDL specification can be found here: ",
+ {a, [{href, "http://www.webservicex.net/WeatherForecast.asmx?WSDL"}],
+ "http://www.webservicex.net/WeatherForecast.asmx?WSDL "}
+ ]},
+
+ {p,[],
+ ["We start by finding the operation named: ",
+ {i, [], "GetWeatherByPlaceName, "},
+ "which is the operation we want to invoke. As can be seen, we have "
+ "one input message and one output message defined. The input message is "
+ "the one we (as a client) will send to the server. "
+ ]},
+
+ box("<wsdl:operation name=\"GetWeatherByPlaceName\">\n"
+ " <documentation>\n"
+ " Get one week weather forecast for a place name(USA)\n"
+ " </documentation>\n"
+ " <wsdl:input message=\"tns:GetWeatherByPlaceNameSoapIn\"/>\n"
+ " <wsdl:output message=\"tns:GetWeatherByPlaceNameSoapOut\"/>\n"
+ "</wsdl:operation>\n"),
+
+ {p,[],
+ ["Now, follow the reference to the message: ",
+ {i, [], "tns:GetWeatherByPlaceNameSoapIn, "},
+ "to where it is defined: "
+ ]},
+
+ box("<wsdl:message name=\"GetWeatherByPlaceNameSoapIn\">\n"
+ "<wsdl:part name=\"parameters\" element=\"tns:GetWeatherByPlaceName\"/>\n"
+ "</wsdl:message>\n"),
+
+ {p,[],
+ ["Continue by following the reference to: ",
+ {i, [], "tns:GetWeatherByPlaceName, "},
+ "and you will end up with an XML Schema type definition: "
+ ]},
+
+ box("<s:element name=\"GetWeatherByPlaceName\">\n"
+ "<s:complexType>\n"
+ "<s:sequence>\n"
+ "<s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"PlaceName\" type=\"s:string\"/>\n"
+ "</s:complexType>\n"
+ "</s:sequence>\n"
+ "</s:element>\n"),
+
+ {p,[],
+ "This tells us that the function we want to call takes one argument "
+ "of a string type (which apparently denotes a Name of a place in the US). "
+ "Left for us is just to call the function from an Erlang shell which has "
+ "got the Yaws ebin directory in the path:"
+ },
+
+ box("1> yaws_soap_lib:call(\n"
+ " \"http://www.webservicex.net/WeatherForecast.asmx?WSDL\"\n"
+ " \"GetWeatherByPlaceName\"\n"
+ " [\"Boston\"]).\n"
+ "{ok,undefined,\n"
+ " [{'p:GetWeatherByPlaceNameResponse',\n"
+ " [],\n"
+ " {'p:WeatherForecasts',[],\n"
+ " \"40.3044128\",\n"
+ " \"79.81284\",\n"
+ " \"0.000453\",\n"
+ " \"42\",\n"
+ " \"BOSTON\",\n"
+ " \"PA\",\n"
+ " undefined,\n"
+ " {'p:ArrayOfWeatherData',\n"
+ " [],\n"
+ " [{'p:WeatherData',\n"
+ " [],\n"
+ " \"Friday, December 08, 2006\"|...},\n"
+ " .....\n"),
+
+ {p,[],
+ "So what happend here? We specified the URL to the WSDL file. "
+ "The yaws_soap_lib:call/3 function then went to retrieve the file, parsed it, "
+ "created a proper message, sent off the message, waited for the "
+ "reply and finally returned a parsed reply as Erlang records. "
+ },
+
+ {p,[],
+ "Eventhough this was very convenient, we probably want do more thnn just one call "
+ "to the web service. So to avoid retrieving and parsing the WSDL file for every "
+ "call. We can do it in two steps: "
+ },
+
+ box("1> Wsdl = yaws_soap_lib:initModel(\n"
+ " \"http://www.webservicex.net/WeatherForecast.asmx?WSDL\").\n"
+ "...\n"
+ "2> yaws_soap_lib:call(\n"
+ " Wsdl,\n"
+ " \"GetWeatherByPlaceName\"\n"
+ " [\"Boston\"]).\n"
+ ),
+
+ {p,[],
+ "To be able to work with the records that we get in the response, "
+ "we can create a header file that we can include in our source code. In our example "
+ "the generated '.hrl' file will look like this: "
+ },
+
+ box("3> yaws_soap_lib:write_hrl(Wsdl, \"/tmp/wfc.hrl\").\n"
+ "...\n"
+ "4> {ok,Bin}=file:read_file(\"/tmp/wfc.hrl\"),io:fwrite(binary_to_list(Bin)).\n"
+ "-record('soap:detail', {anyAttribs, choice}).\n"
+ "-record('soap:Fault', {anyAttribs, 'faultcode', 'faultstring', 'faultactor', 'detail'}).\n"
+ "-record('soap:Body', {anyAttribs, choice}).\n"
+ "-record('soap:Header', {anyAttribs, choice}).\n"
+ "-record('soap:Envelope', {anyAttribs, 'Header', 'Body', choice}).\n"
+ "-record('p:GetWeatherByPlaceNameResponse', {anyAttribs, 'GetWeatherByPlaceNameResult'}).\n"
+ "-record('p:GetWeatherByPlaceName', {anyAttribs, 'PlaceName'}).\n"
+ "-record('p:WeatherData', {anyAttribs, 'Day', 'WeatherImage', 'MaxTemperatureF', \n"
+ " 'MinTemperatureF', 'MaxTemperatureC', 'MinTemperatureC'}).\n"
+ "-record('p:ArrayOfWeatherData', {anyAttribs, 'WeatherData'}).\n"
+ "-record('p:WeatherForecasts', {anyAttribs, 'Latitude', 'Longitude', 'AllocationFactor', \n"
+ " 'FipsCode', 'PlaceName', 'StateCode', 'Status', 'Details'}).\n"
+ "-record('p:GetWeatherByZipCodeResponse', {anyAttribs, 'GetWeatherByZipCodeResult'}).\n"
+ "-record('p:GetWeatherByZipCode', {anyAttribs, 'ZipCode'}).\n"
+ ),
+
+ {p,[],
+ "As you can see, every record in our header has an XML namespace prefix prepended "
+ "in the name of the record. The prefix 'p' as shown above is the default prefix you'll "
+ "get if you don't specify a prefix yourself. This is probably good enough, but if you "
+ "want to set it to something else, you can do it as shown below:"
+ },
+
+ box("5> yaws_soap_lib:initModel(... , \"foo\"). % foo is my prefix\n"
+ "6> yaws_soap_lib:write_hrl(... , ... , \"foo\").\n"
+ ),
+
+ {p,[],
+ ["Some final notes:",
+ {ul, [],
+ [{li, [],
+ "The \"http://...\" URL given as the first argument to the "
+ "functions above may as well be a local file, and thus written as \"file://....\". "},
+ {li, [],
+ "When we retrieve a HTTP located file, we will use 'ibrowse' if it exist "
+ "in the code path. Otherwise we will use the OTP 'http' client."}
+ ]}]},
+
+ {h2, [], "The SOAP server side"},
+
+ {p,[],
+ "If we want to run our own weather service we need to take the WSDL "
+ "and add our own location to it. Either we can just study the WSDL file to "
+ "see which URL we need to change in the 'service' part of the document, or "
+ "we can make use of some nice access functions, that work on the "
+ "#wsdl{} record that yaws_soap_lib:initModel/2 returned, as shown below: "
+ },
+
+ box("7> Ops = yaws_soap_lib:wsdl_operations(Wsdl).\n"
+ "8> {ok,Op} = yaws_soap_lib:get_operation(Ops, \"GetWeatherByPlaceName\").\n"
+ "9> yaws_soap_lib:wsdl_op_address(Op).\n"
+ "\"http://www.webservicex.net/WeatherForecast.asmx\"\n"
+ ),
+
+ {p,[],
+ "Now, edit the WSDL file and change the above URL to something like this:"
+ },
+
+ box("<wsdl:service name=\"WeatherForecast\">\n"
+ " <documentation xmlns=......\n"
+ " <wsdl:port name=\"WeatherForecastSoap\".....\n"
+ " <soap:address location=\"http://localhost:8181/WeatherForecast.yaws\" />\n"
+ " </wsdl:port>\n"
+ ".....\n"
+ ),
+
+
+ {p,[],
+ "Next, start an Erlang shell and start Yaws with SOAP enabled. We need to write "
+ "the code that returns the weather info. This is done in a callback module that "
+ "the Yaws SOAP code will call with the incoming message. The message will be an "
+ "Erlang record and what we return must also be an Erlang record. So we will need "
+ "to create a .hrl containing the record definitions that we can include: "
+ },
+
+ box("1> Docroot = \"/tmp\".\n"
+ "\n"
+ "2> GL = [{enable_soap,true}, % <== THIS WILL ENABLE SOAP IN A YAWS SERVER!!\n"
+ " {trace, false},\n"
+ " {tmpdir,\"/tmp\"},{logdir,\"/tmp\"},\n"
+ " {flags,[{auth_log,false},{tty_trace, false},{copy_errlog, true}]}].\n"
+ "\n"
+ "3> SL = [{port,8181},{servername,\"localhost\"},{dir_listings, true},\n"
+ " {listen,{127,0,0,1}},{flags,[{access_log,false}]}].\n"
+ "\n"
+ "% BELOW, WE CREATE THE .hrl FILE!!\n"
+ "4> yaws_soap_lib:write_hrl(\"file:///tmp/MyWeatherService.wsdl\", \"/tmp/my_soap.hrl\").\n"
+ "\n"
+ "% WE MUST ADD A PATH TO OUR CALLBACK CODE!!\n"
+ "5> code:add_path(\"/tmp\").\n"
+ ),
+
+ {p,[],
+ "We continue by writing our weather forecast callback module:"
+ },
+
+ box("# cat /tmp/my_soap.erl\n"
+ "-module(my_soap).\n"
+ "-export([handler/4]).\n"
+ "-include(\"my_soap.hrl\"). % .hrl file generated by erlsom\n"
+ "\n"
+ "handler(_Header,\n"
+ " [#'p:GetWeatherByPlaceName'{'PlaceName' = Place}],\n"
+ " _Action, \n"
+ " _SessionValue) ->\n"
+ " {ok, undefined, get_weather_info(Place)}.\n"
+ "\n"
+ "get_weather_info(Place) -> \n"
+ " [{'p:GetWeatherByPlaceNameResponse', [],\n"
+ " {'p:WeatherForecasts',[],\n"
+ " \"40.3044128\",\n"
+ " \"79.81284\",\n"
+ " \"0.000453\",\n"
+ " \"42\",\n"
+ " Place,\n"
+ " \"PA\",\n"
+ " undefined,\n"
+ " {'p:ArrayOfWeatherData', [],\n"
+ " [{'p:WeatherData', [],\n"
+ " \"Sunday, December 10, 2006\",\n"
+ " \"http://www.nws.noaa.gov/weather/images/fcicons/nfew.jpg\",\n"
+ " \"51\",\n"
+ " \"28\",\n"
+ " \"11\",\n"
+ " \"-2\"}]}}}].\n"
+ ),
+
+ {p,[],
+ "The final piece on the server side is the '.yaws' file that invokes the "
+ "Yaws SOAP server (note that we are using the same way of hooking in our "
+ "callback module as for Json and HaXe):"
+ },
+
+ box("# cat /tmp/WeatherForecast.yaws\n"
+ "<erl>\n"
+ "out(A) ->\n"
+ " yaws_rpc:handler_session(A, {my_soap, handler}).\n"
+ "</erl>\n"
+ ),
+
+ {p,[],
+ "We are now ready to try it out. Start another Erlang shell and call it: "
+ },
+
+ box("1> yaws_soap_lib:call(\"file:///tmp/MyWeatherService.wsdl\",\n"
+ " \"GetWeatherByPlaceName\",\n"
+ " [\"Stockholm\"]).\n"
+ "{ok,undefined,\n"
+ " [{'p:GetWeatherByPlaceNameResponse', [],\n"
+ " {'p:WeatherForecasts',[],\n"
+ " \"40.3044128\",\n"
+ " \"79.81284\",\n"
+ " \"0.000453\",\n"
+ " \"42\",\n"
+ " \"Stockholm\", % <=== Yippie, it works !!\n"
+ " \"PA\",\n"
+ " undefined,\n"
+ " {'p:ArrayOfWeatherData', [],\n"
+ " [{'p:WeatherData', [],\n"
+ " \"Sunday, December 10, 2006\"|...}]}}}]}\n"
+ "\n"
+ ),
+
+ {p,[],
+ "There you have it! "
+ },
+
+
+ {ssi, "END2",[],[]}
+ ]}}].
+
+
+
+
+</erl>
+
+
+
+
+
+
+

0 comments on commit c332fc2

Please sign in to comment.
Something went wrong with that request. Please try again.