Access Keys:
Skip to content (Access Key - 0)

Contents

Guidelines to Posting on the Mule User List

 If you're reading this you must be wondering what you have to do to increase the probability that your problem is resolved. Following is a brief discussion of what your explanation of the problem should include:

  • Explain briefly what you problem is. Use point form or short paragraphs as it makes it easier to read and understand.
  • Specify the Mule version, Jdk version as well as the version numbers of other technologies you are using in your application
  • If the application involves any complicated routing, it will be useful to provide a diagram of your system (possibly generated using the visualizer tool available with Mule).
  • Provide the relevant exception stack listing
  • Provide your configuration file or at least the relevant parts of your configuration.
  • Whenever possible, also provide a test case package that would illustrate your problem. Actually, this is the ideal situation since this will save other people from having to replicate your error first. We will now take a look at a problem which was actually taken from the Mule User List and illustrate how a test case can be built to illustrate the scenario depicted here. 

Case Study:

 My server should be able to send a message with attachment (eg. image) to client over soap.  I expect that sending image as an attachment would be more efficient than sending it as for example a byte array. A client should be able to receive the attachment and for example display it to the user.
 
Service Component:

public DataHandler getMapImage() throws Exception {
               BufferedImage image = ImageIO.read(new FileInputStream("map_image.jpg"));
               UMOMessage result = new MuleMessage("image");

               DataSource ds = new ImageDataSource("image", image);
               DataHandler dataHandler = new DataHandler(ds);
               result.addAttachment("image attachement", dataHandler);

               return dataHandler;
}

Service config:

<endpoint-identifiers>
        <endpoint-identifier name="AxisWSEndpoint" value="axis:http://localhost:8080/services" />
</endpoint-identifiers>
<transformers>
        <transformer name="HttpRequestToSoapRequest"
               className="org.mule.providers.soap.transformers.HttpRequestToSoapRequest"/>
</transformers>
<model name="soapGisSample">
        <mule-descriptor name="gisService" implementation="sample.gis.Geo">
               <inbound-router>
                       <endpoint address="AxisWSEndpoint" transformers="HttpRequestToSoapRequest">
                               <security-filter className="org.mule.extras.acegi.filters.http.HttpBasicAuthenticationFilter">
                                      <properties>
                                              <property name="realm" value="mule-realm"/>
                                       </properties>
                               </security-filter>
                       </endpoint>
               </inbound-router>
        </mule-descriptor>
</model>

Client:

MuleClient client = new MuleClient();
String mapUrl = "axis:http://testuser:testpass@localhost:8080/services/gisService?method=getMapImage";
UMOMessage mapResult = client.receive(mapUrl, 100);

...
 
...and it fails when invokes receive method. 

Analyzing the problem

In the above scenario, the problem is evident; the Server can't send Attachments over Axis to client application. In other cases, there may be more than one problem. In such cases you should list the problems individually and test for each independently on any other errors.  Once the problem is identified you should build a test case in order to test for this problem and build a scenario where the problem is replicable. 

Creating a Test Case

The FunctionalTestCase available in Mule not only allows you to build JUnit tests but also to define a mule configuration file (which will be used to load Mule), so extending this class for your tests is encouraged. An important factor to keep in mind when creating a test case is the level of detail. It is better to cut down to the basic stuff by removing anything from the configuration that does not directly relate to the problem. For example, in the configuration that the client provided for us above, the security filter and the transformers can be removed. As a test component we can create a class called org.foo.FileOperationsComponent that will implement a method that is very similar to the one provided to us by the user. This method, once called, will create a file, create a datahandler with that file, and send it back to the client. We must also provide an interface for this class since we're using Axis.  

package org.foo;

import java.io.File;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import org.mule.impl.MuleMessage;
import org.mule.umo.UMOMessage;

public class FileOperationsComponent implements FileOperationsService
{

static File repo;

public FileOperationsComponent()
{
	// empty constructor
}

public DataHandler getFile(String fileName) throws Exception
{
	File file = new File("repo");
	FileOperationsComponent.repo = file;
	DataHandler fileData = new DataHandler(new FileDataSource(File.createTempFile(fileName,".txt", file)));
	UMOMessage message = new MuleMessage(fileData.getName());
	message.addAttachment(fileName, fileData);
	return fileData;
}

We build the mule configuration file for this test the same way we would build our mule configuration. Below we configure our OperationsComponent to accept an inbound message over the Axis transport: 

<?xml version= "1.0" encoding= "UTF-8" ?>
<\!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN" "http://mule.mulesource.org/dtds/mule-configuration.dtd">

<mule-configuration id= "axis-attachments-config" version= "1.0">
	<model name="Attachment_Test">
		<mule-descriptor name= "TestComponent" implementation="org.foo.FileOperationsComponent">
			<inbound-router>
				<endpoint address="axis:http://localhost:8999"/>
			</inbound-router>
		</mule-descriptor>
	</model>
</mule-configuration>

The test case would look something like the following. Please note that the mule-config.xml file as seen above is referenced in the getConfigResources() method in the test case. 

public class AxisAttachmentsTestCase extends FunctionalTestCase
{

	public void testAxisAttachments() throws Exception
	{
		MuleClient muleClient = new MuleClient();
		UMOMessage result= muleClient.send("axis:http://localhost:8999/TestComponent?method=getFile",new MuleMessage("TestFile");
		assertNotNull(result.getPayload());
		assertTrue(result.getAttachmentNames().size() > 0);
		assertNotNull(result.getAttachment(result.getPayloadAsString()));
	}

	String getConfigResources()
	{
		return "mule-config.xml"
	}
}

Note that there are three assertions that we are making above.

  1. We assert that the payload returned by the message is not null.
  2. We assert that attachments are being returned in the MuleMessage from the FileOperationsComponent
  3. We assert that the attachment returned is the correct one. 

In the case of this particular problem, the test case will not meet the second two conditions and will fail thus demonstrating that there is a problem with Attachments being received from the server over Axis in a more clear-cut and concise way.

Adaptavist Theme Builder Powered by Atlassian Confluence