Skip to Main Content U.S. Department of Energy

Synchronous MifWebServiceModule Sample

This sample demonstrates writing a module that uses JAX-WS to create a web service in MIF. In JAX-WS, this is done by placing annotations in the appropriate places in your implementation code, then adding cxf endpoints to the module.

This document covers:

  1. An overview of the EchoWebServiceSynchTest
  2. How to run the sample
  3. A walkthrough of the code used to construct this sample


In this sample, a MIF pipeline consists of a single MifWebServiceModule. This creates a synchronous web service which receives a string from the client, then simply echoes that string back to the client, as depicted in the following diagram:

Synchronous Web Service Module

Running the sample

To run the sample, you will need to send data from a client to the MIF pipeline which is hosting the web service. You can do this either by: using CXF's wsdl2java tool to generate client stubs or use a SOAP testing tool such as soapUI as the client.

We will explain running the sample with soapUI since that does not require generating stubs or writing any extra code. Please download soapUI which is available from the above link for free. If you prefer to use the wsdl2java tool to generate your stubs, the command will be smiilar to:

# wsdl2java -client http://localhost:9090/echoService?wsdl

First, start up the MIF pipeline from MIF_HOME by running the command

bin/ -c

Then, start soapUI and point it at your web service by creating a new soapUI project and give it the “initial WSDL”, which is the URL where the web service serving the wsdl file: http://localhost:9000/echoService?wsdl. The program then creates an “echoServiceSoapBinding”. Expand the “doEcho” method and you will see a sample xml message to be sent to the service. Enter a string to send to the service in the <echoArg> tag. For example, my request message looks like:

<soapenv:Envelope xmlns:soapenv=""xmlns:sync="">

This will send the string “hi” to MIF, which will be returned by the webservice back to the client. Once you send this message, you will get the following response message:

<soap:Envelope xmlns:soap="">
      <ns2:doEchoResponse xmlns:ns2="">

Note that the message contains the string you sent echo-ed back to you. You should also see the module print the string it has received to the MIF console, which will look like this:

2010-05-20 16:15:41,675 INFO  [MifManagerImpl]  -- MIF has started --
echo-ing: hi

Code Walkthrough

The code to create the pipeline looks very similar to code you have seen so far. We create a pipeline, add a module to it which is listening on an http endpoint, then start the pipeline:

public class EchoWebServiceSynchTest {
  public static void main(String[] args)  {
    MifPipeline pipeline = new MifPipeline();
    pipeline.addMifWsModule(EchoService.class, "http://localhost:9000/echoService", null);

The implementation class, however, is different than usual. Instead of implementing a MifProcessor interface, we implement EchoInterface. This is typically how Java web services are created: the interface represents the exposed methods of the web service. So, EchoInterface implements the web service by using the @WebService JAX-WS annotation:

public interface EchoInterface {
  public String doEcho(@WebParam(name = "echoArg") String echoArg);

The annotation @WebParam just specifies the name of the web service's argument.

The implementation class, EchoService, simply receives the string, prints it to the standard out, then returns it. Since this is a synchronous webservice, the return value is sent back to the client.

synchronous_webservicemodule.txt · Last modified: 2010/05/20 17:26 by adamw