membrane / soa-model

Toolkit and Java API for WSDL, WADL and XML Schema.
http://www.membrane-soa.org/soa-model/
Apache License 2.0
93 stars 73 forks source link

Problem creating request with more when one item. #241

Open kkirakosyan opened 9 years ago

kkirakosyan commented 9 years ago

I am trying the CreateSOAPRequest example that I got from downloads part on 1.5.4 version of soa-model-core. So I have problems related multiple items of same type: for example

formParams.put("xpath:/create/article[1]/price[1]/amount", "10.00");

we have multiple articles and multiple prices. After running example I got this result

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'>
      <article>
<!-- This element is required and should be filled. -->
        <ns2:name xmlns:ns2='http://predic8.com/material/1/' />
<!-- This element is required and should be filled. -->
        <ns2:description xmlns:ns2='http://predic8.com/material/1/' />
        <ns2:price xmlns:ns2='http://predic8.com/material/1/'>
<!-- This element is required and should be filled. -->
          <ns3:amount xmlns:ns3='http://predic8.com/common/1/' />
          <ns3:currency xmlns:ns3='http://predic8.com/common/1/'></ns3:currency>
        </ns2:price>
        <ns2:id xmlns:ns2='http://predic8.com/material/1/'></ns2:id>
      </article>
    </ns1:create>
  </s11:Body>
</s11:Envelope>

but it should be

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'>
      <article>
        <name xmlns:ns2='http://predic8.com/material/1/'>foo2</name>
        <description xmlns:ns2='http://predic8.com/material/1/'>bar2</description>
        <price xmlns:ns2='http://predic8.com/material/1/'>
          <amount xmlns:ns3='http://predic8.com/common/1/'>10.00</amount>
          <currency xmlns:ns3='http://predic8.com/common/1/'>EUR</currency>
        </price>
        <id xmlns:ns2='http://predic8.com/material/1/'>2</id>
      </article>
      <article>
       <name xmlns:ns2='http://predic8.com/material/1/'>foo1</name>
        <description xmlns:ns2='http://predic8.com/material/1/'>bar1</description>
        <price xmlns:ns2='http://predic8.com/material/1/'>
          <amount xmlns:ns3='http://predic8.com/common/1/'>20.00</amount>
          <currency xmlns:ns3='http://predic8.com/common/1/'>USD</currency>
        </price>
        <id xmlns:ns2='http://predic8.com/material/1/'>1</id>
      </article>
    </ns1:create>
  </s11:Body>
</s11:Envelope>

I didn't change anything in source code.

psytester commented 8 years ago

I need to push that issue. We have tracked down the reason and can give an example WSDL with following ComplexType, where this Problem occurs for us

<xsd:simpleType name="mediumBlob">
    <xsd:restriction base="xsd:base64Binary">
        <xsd:maxLength value="16384" />
    </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Identity">
    <xsd:sequence>
        <xsd:element name="data_A" type="xsd:base64Binary" minOccurs="0" maxOccurs="10"/>
        <xsd:element name="data_B" type="tns:mediumBlob" minOccurs="0" maxOccurs="10"/>
        <xsd:element name="data_C" type="tns:mediumBlob" minOccurs="0" maxOccurs="10"/>
    </xsd:sequence>
</xsd:complexType>

In our code we set all elements and they data into a String HashMap to put them into the Operation later-on:

HashMap<String, String> data = new HashMap<>();
data.put("xpath:/MyOperation/id/data_A[1]", "###");
data.put("xpath:/MyOperation/id/data_A[2]", "XXX");
data.put("xpath:/MyOperation/id/data_B[1]", "###");
data.put("xpath:/MyOperation/id/data_B[2]", "XXX");
data.put("xpath:/MyOperation/id/data_C", "###");
msg_MyOperation.addData(data);

This generates following Request content:

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
    <s11:Body>
        <ns1:MyOperation xmlns:ns1='https://www.MyNameSpace.tld/abc'>
            <id>
                <data_A>###</data_A>
                <data_A>XXX</data_A>
                <data_B></data_B>
                <data_C>###</data_C>
            </id>
        </ns1:MyOperation>
    </s11:Body>
</s11:Envelope>

But expected was:

                <data_A>###</data_A>
                <data_A>XXX</data_A>
                <data_B>###</data_B>
                <data_B>XXX</data_B>
                <data_C>###</data_C>

While generating the request, during the creation of BuildInSchemaType-Objects, matching Xpath-Elements are identified by a Regular Expression. During that creation of SimpleType-Objekts only 1-to-1 matches are searched.

is no BuildInSchemaType SimpleType and finally it Fails Hopefully that's correct ;-)
keshavarzi commented 8 years ago

Hi,

thanks for your valueable description of the bug. It will take some time till we will fix that is SOA Model. Feel free to create a pull-request yourself if you want to. The code fort he RequestCreator is at the file:

https://github.com/membrane/soa-model/blob/master/core/src/main/groovy/com/predic8/wstool/creator/RequestCreator.groovy

Cheers,

Thomas

Am 04.08.16, 13:45 schrieb "psytester" notifications@github.com:

I need to push that issue. We have tracked down the reason and can give an example WSDL with following ComplexType, where this Problem occurs for us

                /xsd:restriction /xsd:simpleType     xsd:sequence                             /xsd:sequence /xsd:complexType In our code we set all elements and they data into a String HashMap to put them into the Operation later-on: HashMap data = new HashMap<>(); data.put("xpath:/MyOperation/id/data_A[1]", "###"); data.put("xpath:/MyOperation/id/data_A[2]", "XXX"); data.put("xpath:/MyOperation/id/data_B[1]", "###"); data.put("xpath:/MyOperation/id/data_B[2]", "XXX"); data.put("xpath:/MyOperation/id/data_C", "###"); msg_MyOperation.addData(data); This generates following Request content:     s11:Body                                     ###                 XXX                                 ###                     /ns1:MyOperation     /s11:Body /s11:Envelope But expected was:                 ###                 XXX                 ###                 XXX                 ### both are added because of type="xsd:base64Binary" is no direct type="xsd:base64Binary" and added, because only one Occurence is added is like but not added at all, only one empty because the fault is partly located in the Groovy-Scripts: While generating the request, during the creation of BuildInSchemaType-Objects, matching Xpath-Elements are identified by a Regular Expression. During that creation of SimpleType-Objekts only 1-to-1 matches are searched. is no BuildInSchemaType SimpleType and finally it Fails Hopefully that's correct ;-) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
carlvine500 commented 6 years ago

CreateSOAPRequest run result not correct (there are no data in element & ): soa-model version is

<dependency>
            <groupId>com.predic8</groupId>
            <artifactId>soa-model-core</artifactId>
            <version>1.6.0</version>
</dependency>

result is:

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'>
      <article>
        <ns2:name xmlns:ns2='http://predic8.com/material/1/'>foo2</ns2:name>
        <ns2:description xmlns:ns2='http://predic8.com/material/1/'>bar2</ns2:description>
        <ns2:price xmlns:ns2='http://predic8.com/material/1/'>
<!-- This element is required and should be filled. -->
          <ns3:amount xmlns:ns3='http://predic8.com/common/1/' />
          <ns3:currency xmlns:ns3='http://predic8.com/common/1/'></ns3:currency>
        </ns2:price>
        <ns2:id xmlns:ns2='http://predic8.com/material/1/'>2</ns2:id>
      </article>
      <article>
        <ns2:name xmlns:ns2='http://predic8.com/material/1/'>foo1</ns2:name>
        <ns2:description xmlns:ns2='http://predic8.com/material/1/'>bar1</ns2:description>
        <ns2:price xmlns:ns2='http://predic8.com/material/1/'>
<!-- This element is required and should be filled. -->
          <ns3:amount xmlns:ns3='http://predic8.com/common/1/' />
          <ns3:currency xmlns:ns3='http://predic8.com/common/1/'></ns3:currency>
        </ns2:price>
        <ns2:id xmlns:ns2='http://predic8.com/material/1/'>1</ns2:id>
      </article>
    </ns1:create>
  </s11:Body>
</s11:Envelope>