This document explains the provided examples, to help understand what they do and how they works.
The user have an installed and running SoaBox 1.1.x
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.
Those examples shows the flows you can build.
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.
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.
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.
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.
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.
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.
Those examples shows different templating techniques.
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
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>
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>
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>
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>
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.
This example uses the com.blacksoa.box.destinations.http.Put destination and the server answers with an HTTP 201 code with no content.
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.
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:
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>
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.
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.
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;
}
}
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).