Requirement is read data from file and invoke webservice. Target webservice can handle one payload at a time but there will be multiple payload in source.
So am using while loop to process payload one by one.
Issue: In target service EarningTypeInclusion is optional element, so in source some payload this element will be present and in some payload this option element will not be present.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
</thresholdRequestInterface>
If am using assign activity, then selection failure fault will come when optional elements are not present in source payload. We are using BPEL 10g, no option in assign activity to supress selection failure fault.
So decided to use transformation inside while loop .
logic used
Read from file
assign Loop counter=1
Count of payload(read from file)
While loop counter<= Count of payload
pass loop counter param value to transform
transform source i.e thresholdRequest[loopcounter] to target
Invoke target web service
increment loop counter
end loop;
Problem is same data is getting trsnformed.
In the below example, referral 11 data is loading 3 times. I have checked conter value, its getting incremented but inside transformation same values are getting transformed.
<thresholdRequestInterface xmlns:xs="http://www.sample.com/ns/LMSReferrals">
<thresholdRequest>
<Referral>11</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
<thresholdRequest>
<Referral>12</Referral>
<thresholdValue>100</thresholdValue>
</thresholdRequest>
<thresholdRequest>
<Referral>13</Referral>
<thresholdValue>100</thresholdValue>
<EarningTypeInclusion>
<earningType>positive</earningType>
<ProvisionId>1000</ProvisionId>
</EarningTypeInclusion>
</thresholdRequest>
</thresholdRequestInterface>
Source
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequestInterface">
<xs:complexType>
<xs:sequence>
<xs:element name="thresholdRequest" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please find the schema structure for source and target
Target
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://www.sample.com/ns/LMSReferrals" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.sample.com/ns/LMSReferrals" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="thresholdRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Referral" type="xs:string"/>
<xs:element name="thresholdValue" type="xs:int"/>
<xs:element name="EarningTypeInclusion" minOccurs="0" maxOccurs="1" >
<xs:complexType>
<xs:sequence>
<xs:element name="earningType" type="xs:stirng" />
<xs:element name="ProvisionId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Please note schema validation is enabled at target webservice.
Is there a specific reason that you are using Transform.Try using ora:getElement('/thresholdRequestInterface /thresholdRequest',bpws:getVariable(loopCounter))
Related
I have the following XSD to validate this XML, but I don't know why it says that is valid. Notice that the pattern only checks for date, not date + time. Do you know how can I put a pattern to take only as valid the date + time? Thank you very much in advance.
XML:
<IN_PARAM>
<DATE_FROM>20/01/2018 10:35:00</DATE_FROM>
<DATE_TO>31/12/2019 18:40:00</DATE_TO>
</IN_PARAM>
XSD:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IN_PARAM">
<xs:complexType>
<xs:sequence>
<xs:element name="DATE_FROM" minOccurs="1" maxOccurs="1" />
<xs:element name="DATE_TO" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DATE_FROM">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DATE_TO">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
I got it. You have to define a type, and that type must have the pattern do you want.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IN_PARAM">
<xs:complexType>
<xs:sequence>
<xs:element name="DATE_FROM" type="DateTimeType" minOccurs="1" maxOccurs="1" />
<xs:element name="DATE_TO" type="DateTimeType" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="DateTimeType">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{2}/[0-9]{2}/[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
And of course, if you need it, here is the pattern for dd/MM/yyyy hh:mm:ss:
<xs:pattern value="(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4} (0[0-9]|[1][0-9]|2[1-3]):([0-5][0-9]):([0-5][0-9])"/>
It seems that I am facing some problem while validating this XML
This is XML ,which I have created.
<?xml version="1.0" encoding="UTF-8"?>
<emp_comp xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-04-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
</emp>
</emp_comp>
Corresponding schema is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="emp_comp">
<xs:complexType>
<xs:sequence>
<xs:element name="emp" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="row_id" type="xs:int" />
<xs:element name="emp_code" type="xs:string"
minOccurs="0" />
<xs:element name="emp_compdt"
minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="|([0-3][0-9][\-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[\-][0-9]{4})" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="emp_cdata" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="emp_cname"
type="xs:string" minOccurs="0" />
<xs:element name="emp_ccurr"
type="xs:string" minOccurs="0" />
<xs:element name="emp_camt" minOccurs="0" > <!-- ^\d+\.\d{0,2}$ -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+(\.[0-9][0-9]?)?" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Error which I am getting is Cannot find the declaration of element 'emp_comp'
what could be the reason for this.
Change:
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
To:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Then, provided that you do really have your XSD at http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd, it will work. Pull it up in a browser to be sure.
Problem
The problem is on first tag, remove this declaration xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd" and and fix <emp_compdt>01-APR-2014</emp_compdt>
Possible Solution
Define a namespace on XSD targetNamespace="http://namespace"
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://namespace">
<xs:element name="emp_comp">
<xs:complexType>
<xs:sequence>
<xs:element name="emp" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="row_id" type="xs:int" />
<xs:element name="emp_code" type="xs:string"
minOccurs="0" />
<xs:element name="emp_compdt"
minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern
value="|([0-3][0-9][\-](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[\-][0-9]{4})" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="emp_cdata" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="emp_cname"
type="xs:string" minOccurs="0" />
<xs:element name="emp_ccurr"
type="xs:string" minOccurs="0" />
<xs:element name="emp_camt" minOccurs="0" > <!-- ^\d+\.\d{0,2}$ -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+(\.[0-9][0-9]?)?" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
the XML could be
<ns1:emp_comp xmlns:ns1="http://namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://namespace http://localhost:9080/ermWeb/WebContent/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-APR-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
</emp>
</ns1:emp_comp>
Ok, this might be first I am answering my own Question
<?xml version="1.0" encoding="UTF-8"?>
<emp_comp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost:9080/ermWeb/XSD/Compensation.xsd">
<emp>
<row_id>0</row_id>
<emp_code>002</emp_code>
<emp_compdt>01-Jan-2014</emp_compdt>
<emp_cdata>
<emp_cname>Basic</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>100.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>VPF</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>120.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>Employer NPS</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>130.00</emp_camt>
</emp_cdata>
<emp_cdata>
<emp_cname>Employee NPS</emp_cname>
<emp_ccurr>INR</emp_ccurr>
<emp_camt>140.00</emp_camt>
</emp_cdata>
</emp>
</emp_comp>
there were 3 errors as they are pointed out by other answers.
1)01-04-2014 is incorrect, 04 must be replaced by APR
2)xmlns:xsi="http://www.w3.org/2001/XMLSchema" , must add -instance in the end
and
3) I need to use the XSD resource with the nameSpace ,to do that I have to add noNamespace before SchemaLocation in xsi:
Now XML is getting validated in accordance with XSD.
I do not know how to write xsd for this request down.
Method POST
Request Parameters
all required
Tag Name
publicId type String
publicIdType type String
actorType type String
startDate type Date
endDate type Date
example
<actor>
<actorPublicId>2424252</actorPublicId>
<actorPublicIdType>1341416</actorPublicIdType>
<actorType>test</actorType>
<startDate>2014-03-10T22:34:34.999+2:00</startDate>
<endDate>2014-03-10T22:34:34.999+2:00</endDate>
</actor>
Your XSD is ..
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="yourNamespace"
xmlns:pref="yourNamespace">
<xs:element name="actor" type="pref:actor"/>
<xs:complexType name="actor">
<xs:sequence>
<xs:element type="xs:string" name="actorPublicId"/>
<xs:element type="xs:string" name="actorPublicIdType"/>
<xs:element type="xs:string" name="actorType"/>
<xs:element type="xs:dateTime" name="startDate"/>
<xs:element type="xs:dateTime" name="endDate"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I am trying to insert primary and foreign keys in XSD schema file below :-
Primary key is StudentID and Foreign Keys are courseID, AddressID, GradeID.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However above code is not working in my setup please help me in tracing the issue,
In general you would need to put more details in a question... So this should be enough to understand what else you might need to define, and how. I'll tackle what's needed to understand how to define a primary key/foreign key by illustrating an assumed student/address relationship.
First you need to define a context where these constraints hold true. In my modified XSD, I call it the "World".
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="World">
<xs:complexType>
<xs:sequence>
<xs:element ref="Student" maxOccurs="unbounded"/>
<xs:element ref="Address" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="PKStudents">
<xs:selector xpath="Student/StudentID"/>
<xs:field xpath="."/>
</xs:key>
<xs:key name="PKAddresses">
<xs:selector xpath="Address/AddressID"/>
<xs:field xpath="."/>
</xs:key>
<xs:keyref name="FKStudentToAddress" refer="PKAddresses">
<xs:selector xpath="Student/AddressID"/>
<xs:field xpath="."/>
</xs:keyref>
</xs:element>
<xs:element name="Student">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="Dateborn" type="xs:date"/>
<xs:element name="Gender" type="xs:string"/>
<xs:element name="StudentID" type="xs:string"/>
<xs:element name="AddressID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="AddressID" type="xs:string"/>
<xs:element name="Street" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="Province" type="xs:string" minOccurs="0"/>
<xs:element name="Country" type="xs:date" minOccurs="0"/>
<xs:element name="PostalCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Then an XML like this would pass or fail, depending on what you do with the values in the StudentID and AddressID fields.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<World xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID1</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Student>
<Title>Title1</Title>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Dateborn>1900-01-01</Dateborn>
<Gender>Gender1</Gender>
<StudentID>StudentID2</StudentID>
<AddressID>AddressID1</AddressID>
</Student>
<Address>
<AddressID>AddressID1</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
<Address>
<AddressID>AddressID2</AddressID>
<Street>Street1</Street>
<City>City1</City>
<Province>Province1</Province>
<Country>1900-01-01</Country>
<PostalCode>PostalCode1</PostalCode>
</Address>
</World>
To finish your solution, you would need to define the Course and Grade "entities" in your "world", define the xs:key for each, similar to Student/*Address*, then add CourseID and GradeID attributes to the entities that need them, and finally, define the keyref, as above, for Entity to Grade and Entity to Course.
I am creating a new web service in which the data format should have to made strict using XMLSchema. But I could not find a way to apply detail xml schema in Coldfusion web service
the web service is passing information as XML and they need to be in a strict format which sould be spedicied in the XML Schema , so that No wrong information is passed.
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UpdatePendingTicketsRequest">
<xs:complexType>
<xs:sequence>
<xs:element ref="SIMS_REPLY_NAVISION_TO_INTOUCH">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UpdatePendingTicketsResponse">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OK"/>
<xs:enumeration value="ERROR_PROCESSING"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:simpleType name="ST_STATUS">
<xs:restriction base="xs:integer">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="99"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="TRANSACTIONS">
<xs:complexType>
<xs:sequence>
<xs:element ref="TRANSACTION" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="TRANSACTION">
<xs:complexType>
<xs:sequence>
<xs:element ref="ORIGINAL_TRANSACTION_ID"/>
<xs:element ref="STATUS"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="STATUS">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="ST_STATUS">
<xs:attribute name="description" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="DUPLICATE"/>
<xs:enumeration value="OK"/>
<xs:enumeration value="PROBLEM"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="SIMS_REPLY_NAVISION_TO_INTOUCH">
<xs:complexType>
<xs:sequence>
<xs:element ref="DATETIME"/>
<xs:element ref="TRANSACTIONS"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ORIGINAL_TRANSACTION_ID" type="xs:string"/>
<xs:element name="DATETIME" type="xs:dateTime"/>
<xs:element name="FaultStructure">
<xs:complexType >
<xs:sequence>
<xs:element type="xs:string" name="FaultCode"/>
<xs:element type="xs:string" name="FaultString"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
This is the sample XML Schema which is used to validate the payload. But when i create the same in Coldfusion, this is all i get.
<wsdl:types>
<schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://xml.apache.org/xml-soap"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="CFCInvocationException">
<sequence/>
</complexType>
</schema>
</wsdl:types>
I did a lot of search and never found a concrete solution for it.
This might not be answer but I always recommend that do not build webservice in ColdFusion to receive xml document as arguments. Instead use xml string as argument which later you can convert to xml document using xmlParse(). I had such experience in past and later I need to convert it to xml string argument.
Thanks
Pritesh