Text Size
Tuesday, May 21, 2013
Product

Examples

Document goals

This document explains the provided examples, to help understand what they do and how they works.

Assumptions

 

Assumptions

The user have an installed and running SoaBox 1.1.x

Examples

 

The examples are provided as an exported box file.

You can download them from Sourceforge under the Examples folder at the address http://sourceforge.net/projects/soabox/files/Examples/

If you're running on http port 8080 download the file examples8080V1.2.x.box, if you're running on http port 8680 download examples8680V1.2.x.box

For JBoss 6.x the box to download is examplesAS68080V1.2.x.box, that is valid for http port 8080.

To install them go to the SoaBox console, http://localhost:XXXX/soaBox, choose the File > Import > Box menu and select the downloaded file.

For all the examples except for the load test one, the log is enabled so take a look on the console in the log viewer tab to see what's happening.

To see the files use the File Manager.

For every virtual client group there is a section and for every job a subsection.

If you want to use the jms example on jboss-6.x you'll have to restart the server.

 

Flows

Those examples shows the flows you can build.

Chain

With this example you can see how it's possible to chain multiple destinations.

When run the selected file will first be written to the filesystem and then sent to the Virtual Server.

If you check the job you will see that the selected destination is ChainWSDestination.

If you go to the ChainWSDestination configuration you'll see that the next attribute is set to OutDirDestination.

Jms

This example shows a complete jms queue flow.

The file is published on /queue/example via the Queue destination and then picked up by the ExampleQueueCleanerTask.

You can check the ExampleQueueCleanerTask under the task list menu Virtualization > Tasks.

Load test

This example shows how it's possible to run load tests.

When run it will send to the Virtual Server 1000 requests.

This is done via the LoadTestSelector, a SingleFileSelector, configured to pick 20 times the same file and then setting 50 as Thread value for the LoadTestJob (20*50=1000).

Setting the LoadTestSelector quantity to 1000 and the LoadTestJob thread value to 1 you'll have a single thread sending 1000 requests.

Matchers

This example shows the server side matchers chain.

When run 4 different files will be sent to the the same URL:

http://localhost:XXXX/virtual/examples/matchers.

Depending on the percentage of requests and their content a different response will be given.

To check how the server configuration works go to Virtualization > Server > Configuration and select as server Example.xml and look the URI /examples/matchers.

Server Side

This example shows how you can start a Virtual Client job from the server.

This is really useful if you want that after a call has been made to a WS, something will be published on a JMS queue or on a FTP server or something similar.

When run the Virtual Client will make a call to:

http://localhost:8080/virtual/examples/serverSideJob.

The server at this point will start the Virtual Client job Chain.

This is done setting the job on the sever configuration URI /examples/serverSideJob.

Triggered

This example shows the use of triggers.

When started the trigger will be delegated to start the job, if you open the TriggeredJob you will see that it has as trigger the EveryMinuteTrigger.

Now this job will run every minute until you stop it.

 

Templates

Those examples shows different templating techniques.

CSV

This example creates a csv file using Velocity and Value beans.

The template follows:

                
#foreach ($i in [0..5])
$i $replacer.replace("NameListValue") $replacer.replace("UIDValue") 
$replacer.replace("RandomNumberValue")
#end    
     

Because some fields are random it's not possible to predict exactly how the output will look but it should be similar to:

                 
0 Smith C0A80164_012B14839B5C_D34A_005CE38D 69
1 Johnson C0A80164_012B14839B61_1EC1_00766839 87
2 Williams C0A80164_012B14839B62_73C5_00B4AA39 1
3 Jones C0A80164_012B14839B62_55C1_0013A55F 199
4 Brown C0A80164_012B14839B63_CBEC_00CE0AC8 130
5 Davis C0A80164_012B14839B64_90E2_00D34B5C 113

Context

This example shows how you have access to context information both client side and server side.

This is done using Velocity and the provided context object.

The client side template follows:

                
<element>
$ctx.get("env_java.home")
</element>  
    

The server side template follows:

                
<element>
$ctx.get("env.java.home") $ctx.get("http.param.param1").get(0) $ctx.print()
</element>    

Include

This example shows how to use the velocity include directive.

This is very useful if you want to reuse the files you use in the development process in the box.

The template of the including one follows:

                
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
#include("/examples/include/contained.vm")
 </soap:Body>
</soap:Envelope>  

XML

This example shows the use of the built-in xml template engine.

It shows how you can get access to a Value bean simply defining it's name in gullwings.

The template follows:

                
<customer>
<id>{IdValue}</id>
</customer>

 

XPath

This group contains only one job that shows the use of XPaths.

It illustrates both how to select the answer to give server side, depending on the xpath, and how do include in the answer part of the request always using xpaths.

The template of the server side answer follows:

                
<updated>
<customer>
$ctx.get("req.body").xpath("{soap=http://www.w3.org/2001/12/soap-envelope,
c=http://example.com/example}//c:customer/c:name")
</customer>
</updated>

 

Rest

This group shows how to implement REST calls and answers.

On the client side it uses the various HTTP destinations (POST, CREATE, GET, PUT, DELETE) using for the GET method URL virtualization.

On the server side it shows how using regular expression it's possible to give the proper HTTP response, answering with just a HTTP code, or with xml content.

Create

This example uses the com.blacksoa.box.destinations.http.Put destination and the server answers with an HTTP 201 code with no content.

Delete

This example uses the com.blacksoa.box.destinations.http.Delete destination and on the server configuration the request has a RegEx (/rest/delete/)(.*).

This way the any /rest/delete/x will be caught, like /rest/delete/1 or /rest/delete/8.

The server answers with an HTTP 204 code with no content.

Get

This example uses the com.blacksoa.box.destinations.http.Get destination with URL virtualization.

The URL set on the destination is the following:

http://localhost:xxxx/virtual/rest/get/{IdValue}

The {IdValue} will be replaced by the IdValue bean. Generating for every request a new URL like:

  • http://localhost:xxxx/virtual/rest/get/1
  • http://localhost:xxxx/virtual/rest/get/2
  • http://localhost:xxxx/virtual/rest/get/3

On the server configuration, similar to the Delete example, the request has a RegEx (/rest/get/)(.*).

This way the any /rest/get/x will be caught, like /rest/get/1 or /rest/get/8.

The answers is a HTTP 200 code with virtualized content.

The response file is an xml, that contains the Id of the get URL, using the context information.

                
<book>
<id>{ctx(http.uri.4)}</id>
<author>An author</author>
<title>A title</title>
<description>A description</description>
</book>

As you can see the id element is filled with {ctx(http.uri.4)}, the forth token of the URI, the id.

The generated response content will look like

                
<book>
<id>22</id>
<author>An author</author>
<title>A title</title>
<description>A description</description>
</book>

 

Update

This example uses the com.blacksoa.box.destinations.http.Post destination

On the server the request has a RegEx (/rest/update/)(.*)

The answer is an HTTP 200 code with no content.

Custom

This group contains two examples of integrating custom code in SoaBox.

SoaBox can run code written by you integrating it in the WebApp, working as framework for your needs.

To integrate your code refer to the Developer Guide.

Destination

In this example SoaBox will run a Custom Destination, called com.blacksoa.box.custom.CustomFileLayout, the code of the Class follows:

                
public class CustomFileLayout extends AbstractDestination {

	/** Logger */
	private final static Logger log = Logger.getLogger(CustomFileLayout.class);
	
	/** Where to publish */
	private String outputFolder = "";
	
	/** The extension to use for the generated files */
	private String extension = ".xml";
	
	private static int counter = 0;
	
	/**
	 * 
	 * @param destination next destination to call
	 */
	public CustomFileLayout(Destination destination){
		super(destination);
	}
	
	/**
	 * Constructor
	 */
	public CustomFileLayout(){
		
	}
	
	/*
	 * (non-Javadoc)
	 * @see Destination#publish(java.lang.String)
	 */
	public void publish(String xml){
		super.publish(xml);
		String outFile = convert(getOutputFolder()) + counter++ + getExtension();
        
		
		File fileOut = new File(outFile);

		for (int i = 0; fileOut.exists(); i++) {
			fileOut = new File(outFile + i);
		}

		if(doLog)log.info("Going to write to file:" + outFile);
		
		try {
			FileWriter writer = new FileWriter(fileOut);
			writer.write(xml);
			writer.flush();
			writer.close();

		} catch (IOException e) {
			log.error("Error while writing file: " + outFile + ", error:" + e.getMessage(), e);
		}
	}

	public String getOutputFolder() {
		return outputFolder;
	}

	public void setOutputFolder(String outputFolder) {
		
		this.outputFolder = outputFolder;
		if(!this.outputFolder.endsWith(File.separator))this.outputFolder+=File.separator;
		
	}

	public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}
}

Pojo

This example demostrate how to use a Pojo as destination.

The code needed follows:

                
public class PojoDestination extends AbstractDestination{
	
	/** Counter */
	private int counter = 0;
	
	/**
	 * 
	 */
	public void call() {
		System.out.println("Pojo destination, call number:" + counter++);
	}

}


The line of code neede are really few.

Being a Pojo there is no content to be send, for this reason as selector a QuantitySelector is used.

Using as selector QuantitySelector will make SoaBox use the call() method of the Destination instead of publish(java.lang.String).

 

Newsletter

Let us inform you on the evolution of the project!
Receive

SoaBox Twits

15 Sep 2012 SoaBox 1 1 6 GA has been released! Enjoy!
16 Jul 2012 "SoaBox-1.1.5.CR" has been released! It introduces a lot of new feature and enhancements! Enjoy!
14 Mar 2011 The development of version 1.1 has started. Stay tuned!
8 Feb 2011 SoaBox-1.0.5.GA has been released! It includes the last bug fixes! Enjoy!
7 Feb 2011 The following bugs have been fixed 3166986, 3166984. They will be available in the next release.
31 Jan 2011 SoaBox has been registered on freshmeat.net http://freshmeat.net/projects/soabox http://fb.me/QIEruBF7
26 Jan 2011 SoaBox is production ready! SoaBox-1.0.4.GA has been released! Enjoy!
20 Jan 2011 The box has been tested on jboss-6.0.0.final. It worked after very few changes!
18 Jan 2011 SoaBox is going through the last testes. Soon the GA version will be available.
17 Jan 2011 The following bugs have been fixed 3132370, 3132372, 3132381, 3132391, 3132396, 3150221. They will be available in the next release.
11 Jan 2011 The refactoring has ended. The repository head is again stable.
3 Jan 2011 A strong refactoring of the source base will occurr in the next days. The repository head are going to be very unstable.
13 Dec 2010 SoaBox joins the Black SOA namespace http://www.blacksoa.org/ http://fb.me/KvNFM7CL
9 Dec 2010 The project will continue to be on sourceforge but the website has moved to a better hosting.
3 Dec 2010 The ownership of the SoaBox project moves from Redpill Linpro to Rune Piselli. Redpill Linpro will continue to be... http://fb.me/Nl5Dzczi
8 Oct 2010 SoaBox-1.0.3.CR2 has been released. It moves the project from alpha to beta. All the known bugs have been fixed. So start using it!
6 Oct 2010 The following bugs have been fixed 3065280, 3065287, 3065896, 3066772, 3067659, 3069094. They will be avaible in the next release.
17 Sep 2010 The user guide has been updated, including many errata corrige and a better explaination of the context use in Velocity templates.
Project

Sourceforge

Access the sources, ask for features, look for bugs, comunity support on sourceforge.

License

SoaBox is free as freedom and released with the GPL v3 license.

Support

We provide both comunity and professional support.

Social