You've already forked lazarus-ccr
+ runtime WSDL generation : SOAP Header blocks should not derive from THeaderBlock
+ test case git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@862 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1594,6 +1594,7 @@ const
|
|||||||
sXSD = 'xsd';
|
sXSD = 'xsd';
|
||||||
sSOAP_ENV = 'http://schemas.xmlsoap.org/soap/envelope/';
|
sSOAP_ENV = 'http://schemas.xmlsoap.org/soap/envelope/';
|
||||||
sSOAP_ENV_ABR = 'SOAP-ENV';
|
sSOAP_ENV_ABR = 'SOAP-ENV';
|
||||||
|
sWST_BASE_NS_ABR = 'wst';
|
||||||
sWST_BASE_NS = 'urn:wst_base';
|
sWST_BASE_NS = 'urn:wst_base';
|
||||||
|
|
||||||
PROP_LIST_DELIMITER = ';';
|
PROP_LIST_DELIMITER = ';';
|
||||||
|
@ -171,6 +171,8 @@ const
|
|||||||
sWSDL_TARGET_NS = 'targetNamespace';
|
sWSDL_TARGET_NS = 'targetNamespace';
|
||||||
sWSDL_TYPE = sTYPE;
|
sWSDL_TYPE = sTYPE;
|
||||||
sWSDL_TYPES = 'types';
|
sWSDL_TYPES = 'types';
|
||||||
|
|
||||||
|
sWST_HEADER_BLOCK = 'wst_headerBlock';
|
||||||
|
|
||||||
sFORMAT_Input_EncodingStyle = 'FORMAT_Input_EncodingStyle';
|
sFORMAT_Input_EncodingStyle = 'FORMAT_Input_EncodingStyle';
|
||||||
sFORMAT_Input_EncodingStyleURI = 'FORMAT_Input_EncodingStyleURI';
|
sFORMAT_Input_EncodingStyleURI = 'FORMAT_Input_EncodingStyleURI';
|
||||||
@ -332,20 +334,29 @@ end;
|
|||||||
|
|
||||||
function GetNameSpaceShortName(
|
function GetNameSpaceShortName(
|
||||||
const ANameSpace : string;
|
const ANameSpace : string;
|
||||||
AWsdlDocument : TXMLDocument;
|
ANode : TDOMElement;
|
||||||
const APreferedShortName : string = ''
|
const APreferedShortName : string = ''
|
||||||
):string;//inline;
|
) : string; overload;
|
||||||
begin
|
begin
|
||||||
if FindAttributeByValueInNode(ANameSpace,AWsdlDocument.DocumentElement,Result,0,sXMLNS) then begin
|
if FindAttributeByValueInNode(ANameSpace,ANode,Result,0,sXMLNS) then begin
|
||||||
Result := Copy(Result,Length(sXMLNS+':')+1,MaxInt);
|
Result := Copy(Result,Length(sXMLNS+':')+1,MaxInt);
|
||||||
end else begin
|
end else begin
|
||||||
Result := Trim(APreferedShortName);
|
Result := Trim(APreferedShortName);
|
||||||
if ( Length(Result) = 0 ) then
|
if ( Length(Result) = 0 ) then
|
||||||
Result := Format('ns%d',[GetNodeListCount(AWsdlDocument.DocumentElement.Attributes)]) ;
|
Result := Format('ns%d',[GetNodeListCount(ANode.Attributes)]) ;
|
||||||
AWsdlDocument.DocumentElement.SetAttribute(Format('%s:%s',[sXMLNS,Result]),ANameSpace);
|
ANode.SetAttribute(Format('%s:%s',[sXMLNS,Result]),ANameSpace);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function GetNameSpaceShortName(
|
||||||
|
const ANameSpace : string;
|
||||||
|
AWsdlDocument : TXMLDocument;
|
||||||
|
const APreferedShortName : string = ''
|
||||||
|
) : string; overload;
|
||||||
|
begin
|
||||||
|
Result := GetNameSpaceShortName(ANameSpace,AWsdlDocument.DocumentElement,APreferedShortName);
|
||||||
|
end;
|
||||||
|
|
||||||
type TServiceElementType = ( setPortType, setBinding, setPort, setService,setAddress );
|
type TServiceElementType = ( setPortType, setBinding, setPort, setService,setAddress );
|
||||||
function GetServicePartName(AService : PService; const AServicePart : TServiceElementType):string;
|
function GetServicePartName(AService : PService; const AServicePart : TServiceElementType):string;
|
||||||
const PART_NAME_MAP : array[TServiceElementType] of shortstring = ('', 'Binding', 'Port', '','');
|
const PART_NAME_MAP : array[TServiceElementType] of shortstring = ('', 'Binding', 'Port', '','');
|
||||||
@ -690,13 +701,34 @@ procedure TBaseComplexRemotable_TypeHandler.Generate(
|
|||||||
if ( AClass <> nil ) and ( AClass.ClassParent <> nil ) then begin
|
if ( AClass <> nil ) and ( AClass.ClassParent <> nil ) then begin
|
||||||
locRes := ATypeRegistry.Find(PTypeInfo(AClass.ClassParent.ClassInfo),False);
|
locRes := ATypeRegistry.Find(PTypeInfo(AClass.ClassParent.ClassInfo),False);
|
||||||
end;
|
end;
|
||||||
if ( locRes <> nil ) then begin
|
{if ( locRes <> nil ) then begin
|
||||||
if ( GetTypeData(locRes.DataType)^.ClassType = TBaseComplexRemotable ) then
|
if ( locRes.NameSpace = sSOAP_ENV ) or
|
||||||
|
( GetTypeData(locRes.DataType)^.ClassType = TBaseComplexRemotable )
|
||||||
|
then
|
||||||
locRes := nil;
|
locRes := nil;
|
||||||
end;
|
end;}
|
||||||
Result := locRes;
|
Result := locRes;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function IsParentVisible(const AParentRegItem : TTypeRegistryItem) : Boolean;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
( AParentRegItem <> nil ) and
|
||||||
|
( ( AParentRegItem.NameSpace <> sSOAP_ENV ) and
|
||||||
|
( GetTypeData(AParentRegItem.DataType)^.ClassType <> TBaseComplexRemotable )
|
||||||
|
)
|
||||||
|
end;
|
||||||
|
|
||||||
|
function IsInheritedPropertyAlreadyPublished(
|
||||||
|
const AProperty : PPropInfo;
|
||||||
|
const AParentClass : TClass
|
||||||
|
) : Boolean;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
( AParentClass = THeaderBlock ) and
|
||||||
|
( SameText('mustUnderstand',AProperty^.Name) );
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
typItm, propTypItm : TTypeRegistryItem;
|
typItm, propTypItm : TTypeRegistryItem;
|
||||||
s, prop_ns_shortName : string;
|
s, prop_ns_shortName : string;
|
||||||
@ -734,14 +766,20 @@ begin
|
|||||||
cplxNode.SetAttribute(sNAME, typItm.DeclaredName);
|
cplxNode.SetAttribute(sNAME, typItm.DeclaredName);
|
||||||
extNode := cplxNode;
|
extNode := cplxNode;
|
||||||
if ( parentClss <> nil ) then begin
|
if ( parentClss <> nil ) then begin
|
||||||
if ( parentRegItem.NameSpace = typItm.NameSpace ) then begin
|
if ( parentClss = THeaderBlock ) then begin
|
||||||
s := Format('%s:%s',[sTNS,parentRegItem.DeclaredName]);
|
s := Format('%s:%s',[GetNameSpaceShortName(sWST_BASE_NS,defSchemaNode,sWST_BASE_NS_ABR),sWST_HEADER_BLOCK]);
|
||||||
end else begin
|
cplxNode.SetAttribute(s, 'true');
|
||||||
s := Format('%s:%s',[GetNameSpaceShortName(parentRegItem.NameSpace,AWsdlDocument),parentRegItem.DeclaredName]);
|
end;
|
||||||
|
if IsParentVisible(parentRegItem) then begin
|
||||||
|
if ( parentRegItem.NameSpace = typItm.NameSpace ) then begin
|
||||||
|
s := Format('%s:%s',[sTNS,parentRegItem.DeclaredName]);
|
||||||
|
end else begin
|
||||||
|
s := Format('%s:%s',[GetNameSpaceShortName(parentRegItem.NameSpace,AWsdlDocument),parentRegItem.DeclaredName]);
|
||||||
|
end;
|
||||||
|
cplxContentNode := CreateElement(Format('%s:%s',[sXSD,sCOMPLEX_CONTENT]),cplxNode,AWsdlDocument);
|
||||||
|
extNode := CreateElement(Format('%s:%s',[sXSD,sEXTENSION]),cplxContentNode,AWsdlDocument);
|
||||||
|
extNode.SetAttribute(sBASE,s);
|
||||||
end;
|
end;
|
||||||
cplxContentNode := CreateElement(Format('%s:%s',[sXSD,sCOMPLEX_CONTENT]),cplxNode,AWsdlDocument);
|
|
||||||
extNode := CreateElement(Format('%s:%s',[sXSD,sEXTENSION]),cplxContentNode,AWsdlDocument);
|
|
||||||
extNode.SetAttribute(sBASE,s);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
sqcNode := CreateElement(Format('%s:%s',[sXSD,sSEQUENCE]),extNode,AWsdlDocument);
|
sqcNode := CreateElement(Format('%s:%s',[sXSD,sSEQUENCE]),extNode,AWsdlDocument);
|
||||||
@ -751,7 +789,11 @@ begin
|
|||||||
try
|
try
|
||||||
for i := 0 to Pred(propCount) do begin
|
for i := 0 to Pred(propCount) do begin
|
||||||
p := propList^[i];
|
p := propList^[i];
|
||||||
if ( parentClss = nil ) or ( not IsPublishedProp(parentClss,p^.Name) ) then begin
|
if ( parentClss = nil ) or
|
||||||
|
( not ( IsPublishedProp(parentClss,p^.Name) or IsInheritedPropertyAlreadyPublished(p,parentClss) )
|
||||||
|
|
||||||
|
)
|
||||||
|
then begin
|
||||||
persistType := IsStoredPropClass(objTypeData^.ClassType,p);
|
persistType := IsStoredPropClass(objTypeData^.ClassType,p);
|
||||||
if ( persistType in [pstOptional,pstAlways] ) then begin
|
if ( persistType in [pstOptional,pstAlways] ) then begin
|
||||||
attProp := clsTyp.IsAttributeProperty(p^.Name);
|
attProp := clsTyp.IsAttributeProperty(p^.Name);
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<definitions name="runtime_generator"
|
||||||
|
xmlns="http://schemas.xmlsoap.org/wsdl/"
|
||||||
|
xmlns:tns="urn:sample-namespace"
|
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||||
|
targetNamespace="urn:sample-namespace">
|
||||||
|
<types>
|
||||||
|
<xsd:schema
|
||||||
|
xmlns="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:wst="urn:wst_base"
|
||||||
|
targetNamespace="urn:sample-namespace">
|
||||||
|
<xsd:complexType name="TLoginHeader" wst:wst_headerBlock="true">
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="Login" type="xsd:string" maxOccurs="1" minOccurs="1"/>
|
||||||
|
<xsd:element name="Password" type="xsd:string" maxOccurs="1" minOccurs="1"/>
|
||||||
|
</xsd:sequence>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:schema>
|
||||||
|
</types>
|
||||||
|
</definitions>
|
@ -977,7 +977,7 @@ begin
|
|||||||
locDoc := CreateDoc();
|
locDoc := CreateDoc();
|
||||||
g := CreateGenerator(locDoc);
|
g := CreateGenerator(locDoc);
|
||||||
g.Execute(tr,mdl.Name);
|
g.Execute(tr,mdl.Name);
|
||||||
WriteXMLFile(locDoc,wstExpandLocalFileName('type_hint_record_item.xsd'));
|
//WriteXMLFile(locDoc,wstExpandLocalFileName('type_hint_record_item.xsd'));
|
||||||
locExistDoc := LoadXmlFromFilesList('type_hint_record_item.xsd');
|
locExistDoc := LoadXmlFromFilesList('type_hint_record_item.xsd');
|
||||||
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
|
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
|
||||||
finally
|
finally
|
||||||
|
@ -70,7 +70,16 @@ type
|
|||||||
fieldWord : Word;
|
fieldWord : Word;
|
||||||
fieldString : string;
|
fieldString : string;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TLoginHeader = class(THeaderBlock)
|
||||||
|
private
|
||||||
|
FLogin: string;
|
||||||
|
FPassword: string;
|
||||||
|
published
|
||||||
|
property Login : string read FLogin write FLogin;
|
||||||
|
property Password : string read FPassword write FPassword;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TTestWSDLGenerator }
|
{ TTestWSDLGenerator }
|
||||||
|
|
||||||
TTestWSDLGenerator= class(TTestCase)
|
TTestWSDLGenerator= class(TTestCase)
|
||||||
@ -81,6 +90,7 @@ type
|
|||||||
procedure generate_enum();
|
procedure generate_enum();
|
||||||
procedure generate_array();
|
procedure generate_array();
|
||||||
procedure generate_record();
|
procedure generate_record();
|
||||||
|
procedure generate_soap_headerblock();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -257,6 +267,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestWSDLGenerator.generate_soap_headerblock();
|
||||||
|
var
|
||||||
|
locRep : PServiceRepository;
|
||||||
|
locDoc, locExistDoc : TXMLDocument;
|
||||||
|
typeReg : TTypeRegistry;
|
||||||
|
handlerReg : IWsdlTypeHandlerRegistry;
|
||||||
|
begin
|
||||||
|
locExistDoc := nil;
|
||||||
|
typeReg := nil;
|
||||||
|
locDoc := nil;
|
||||||
|
locRep := CreateRepository();
|
||||||
|
try
|
||||||
|
typeReg := TTypeRegistry.Create();
|
||||||
|
RegisterStdTypes(typeReg);
|
||||||
|
typeReg.Register(sNAMESPACE_SAMPLE,TypeInfo(TLoginHeader));
|
||||||
|
handlerReg := CreateWsdlTypeHandlerRegistry(typeReg);
|
||||||
|
RegisterFondamentalTypesHandler(handlerReg);
|
||||||
|
locDoc := CreateDoc();
|
||||||
|
GenerateWSDL(locRep,locDoc,typeReg,handlerReg);
|
||||||
|
//WriteXML(locDoc,wstExpandLocalFileName('generate_soap_headerblock.wsdl'));
|
||||||
|
ReadXMLFile(locExistDoc,wstExpandLocalFileName(TestFilesPath + 'wsdl_gen_soap_headerblock.wsdl'));
|
||||||
|
Check(CompareNodes(locExistDoc.DocumentElement,locDoc.DocumentElement),'generated document differs from the existent one.');
|
||||||
|
finally
|
||||||
|
typeReg.Free();
|
||||||
|
ReleaseDomNode(locExistDoc);
|
||||||
|
ReleaseDomNode(locDoc);
|
||||||
|
Dispose(locRep);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
TClass_ABC.RegisterAttributeProperty('ABC_EnumAttProp');
|
TClass_ABC.RegisterAttributeProperty('ABC_EnumAttProp');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user