+49 228 5552576-0


info@predic8.com

Create SOAP Request Template with Java

The Membrane SOA Model can create SOAP request Templates out of a WSDL document, filled with sample data in respect to their type definition.

package sample.wsdl;

import groovy.xml.MarkupBuilder;
import java.io.StringWriter;
import com.predic8.wsdl.Definitions;
import com.predic8.wsdl.WSDLParser;
import com.predic8.wstool.creator.RequestTemplateCreator;
import com.predic8.wstool.creator.SOARequestCreator;

public class CreateSOAPRequestTemplate {

  public static void main(String[] args) {

    WSDLParser parser = new WSDLParser();
    
    Definitions wsdl = parser.parse("resources/article/article.wsdl");
    
    StringWriter writer = new StringWriter();
    
    //SOAPRequestCreator constructor: SOARequestCreator(Definitions, Creator, MarkupBuilder)
    SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer));
    
    //creator.createRequest(PortType name, Operation name, Binding name);
    creator.createRequest("ArticleServicePT", "create", "ArticleServicePTBinding");

    System.out.println(writer);
  }
}
      
Listing 1: CreateSOAPRequestTemplate

Using the code above you get the following soap request message.

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/' id='?999?'>
      <article xmlns:ns1='http://predic8.com/material/1/'>
        <name>?XXX?</name>
        <description>?XXX?</description>
        <price xmlns:ns1='http://predic8.com/common/1/'>
          <amount>?999.99?</amount>
<!-- possible value: EUR, possible value: USD -->
          <currency xmlns:ns1='http://predic8.com/common/1/'>???</currency>
        </price>
<!-- Pattern: [A-Z]{2}-\d{5} -->
        <id xmlns:ns1='http://predic8.com/material/1/'>???</id>
      </article>
    </ns1:create>
  </s11:Body>
</s11:Envelope>

      
Listing 2: Created soap request template

Copyright © 2008-2017 predic8 GmbH
Koblenzerstr. 65, 53173 Bonn, Tel. +49 (228) 555 25 76-0