Defining Java to XML Translation with XML Maps

You can use an XML map to modify the relationship between the Java interface exposed to clients of a Web Service control and the XML messages sent to the target web service. You may want to do this if, for example, you want to simplify the methods that the Web Service control exposes, or perform some additional processing before the request is sent to the web service represented by the Web Service control. In all cases, the request that you send to the target web service must always adhere to the public contract outlined in the service’s WSDL file.

The following example, which demonstrates that kind of modification, is taken from the QuoteServiceControl.jcx sample Web Service control used by the QuoteClient.jws sample. QuoteServiceControl.jcx was originally generated from QuoteService.jws and then modified. The first parameter of getQuote was removed from the Java signature, meaning callers (that is, web services that use this Web Service control) are no longer expected to pass it. An XML map was then added to getQuote, with the value of the <customerID> element hard-coded. This leaves the message shape as QuoteService expects it, with two parameters. The calling service passes one parameter that the Web Service control combines with the hard-coded parameter to produce the two-parameter message the target service expects.

The following is the code as it was originally generated from QuoteService.jws. Notice that getQuote takes two parameters.

import com.bea.control.ServiceControl;
/**
 * @jc:location http-url="QuoteService.jws" jms-url="QuoteService.jws"
 * @jc:wsdl file="#QuoteServiceWsdl"
 */
public interface QuoteServiceControl extends ServiceControl
{
    public interface Callback
    {
        /**
         * @jc:conversation phase="finish"
         */
        public void onQuoteReady (java.lang.String tickerSymbol, double dQuote);
    }
    /**
     * @jc:conversation phase="start"
     */
    public void getQuote (int customerID String tickerSymbol);
}

Below is the code after the JCX file has been modified manually. The customerID parameter has been removed from the method signature and hard-coded into the XML map, which was also manually added. Note that the XML map must comply with the contract of the target web service.

import com.bea.control.ServiceControl;
/**
 * @jc:location http-url="QuoteService.jws" jms-url="QuoteService.jws"
 * @jc:wsdl file="#QuoteServiceWsdl"
 */
public interface QuoteServiceControl extends ServiceControl
{
    public interface Callback
    {
        /**
         * @jc:conversation phase="finish"
         */
        public void onQuoteReady (java.lang.String tickerSymbol, double dQuote);
    }
    /**
     * @jc:conversation phase="start"
     * @jc:parameter-xml xml-map::
     *  <getQuote xmlns="http://www.openuri.org/">
     *      <customerID>1234567890</customerID>
     *      <tickerSymbol>{tickerSymbol}</tickerSymbol>
     *  </getQuote>::
     */
    public void getQuote (String tickerSymbol);
}

Note that you can also make the modifications to the method signature and XML map in the Edit Maps and Interface dialog. Open the dialog by double-clicking on the map icon (the fat arrow) for the getQuote method when you are editing QuoteClient.jws in Design View.

Related Topics

Handling and Shaping XML Messages with XML Maps

QuoteClient.jws Sample