Customizing a Service Control: Defining Java to XML Translation with XML Maps

This topic describes customizations you can make to a Service control's CTRL file to modify the control's default behavior.

To learn more about controls, see Controls: Using Resources from a Web Service.

To learn more about Service controls, see Service Control: Using Another Web Service.

To learn more about customizing Service controls, see Customizing a Service Control: Overview.

# Adding XML Maps to the Methods of a Service Control

You can modify the relationship between the Java interface exposed to clients of a Service control and the XML messages sent to the target web service. The following example is taken from the QuoteServiceControl.ctrl sample Service control used by the QuoteClient.jws Sample.

QuoteServiceControl.ctrl was originally generated from QuoteService.jws. It was then modified: the first parameter of getQuote was removed from the Java signature, meaning callers (web services that use this 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, which the Service control combines with the hard-coded parameter to produce the two-parameter message the target service expects.

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

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

Below is the code after the CTRL 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. The XML map must comply with the contract of the target web service.

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

Note that the modifications to the method signature and XML map could also be accomplished in the Edit Maps and Interface Dialog. Access the dialog by double-clicking on the map icon (the fat arrow) for the getQuote method when QuoteClient.jws is being edited in Design View.

Related Topics

Handling and Shaping XML Messages with XML Maps

QuoteClient.jws Sample