Apache Axis2 – JAX-WS Guide
Apache Axis2 – JAX-WS Guide
Introduction to JAXWS
JAXWS 2.0 is a new programming model that simplifies application development through
support of a standard, annotationbased model to develop Web Service applications and
clients. The JAXWS 2.0 specification strategically aligns itself with the current industry
trend towards a more documentcentric messaging model and replaces the remote
procedure call programming model as defined by JAXRPC. JAXWS is the strategic
programming model for developing Web services and is a required part of the Java
Platform, Enterprise Edition 5 (Java EE 5). The implementation of the JAXWS
programming standard provides the following enhancements for developing Web services
and clients:
Better platform independence for Java applications.
Using JAXWS APIs, development of Web services and clients is simplified with better
platform independence for Java applications. JAXWS takes advantage of the dynamic
proxy mechanism to provide a formal delegation model with a pluggable provider. This
is an enhancement over JAXRPC, which relies on the generation of vendorspecific
stubs for invocation.
Annotations
JAXWS introduces support for annotating Java classes with metadata to indicate that
the Java class is a Web service. JAXWS supports the use of annotations based on
the Metadata Facility for the Java Programming Language (JSR 175) specification, the
Web Services Metadata for the Java Platform (JSR 181) specification and annotations
defined by the JAXWS 2.0 specification. Using annotations within the Java source and
within the Java class simplifies development of Web services by defining some of the
additional information that is typically obtained from deployment descriptor files, WSDL
files, or mapping metadata from XML and WSDL files into the source artifacts.
For example, you can embed a simple @WebService tag in the Java source to expose
the bean as a Web service.
@WebService
The @WebService annotation tells the server runtime to expose all public methods on
that bean as a Web service. Additional levels of granularity can be controlled by adding
additional annotations on individual methods or parameters. Using annotations makes
it much easier to expose Java artifacts as Web services. In addition, as artifacts are
created from using some of the topdown mapping tools starting from a WSDL file,
annotations are included within the source and Java classes as a way of capturing the
metadata along with the source files.
Using annotations also improves the development of Web services within a team
structure because you do not need to define every Web service in a single or common
deployment descriptor as required with JAXRPC Web services. Taking advantage of
annotations with JAXWS Web services allows parallel development of the service and
the required metadata.
With JAXWS, Web services are called both synchronously and asynchronously. JAX
WS adds support for both a polling and callback mechanism when calling Web
services asynchronously. Using a polling model, a client can issue a request, get a
response object back, which is polled to determine if the server has responded. When
the server responds, the actual response is retrieved. Using the callback model, the
client provides a callback handler to accept and process the inbound response object.
Both the polling and callback models enable the client to focus on continuing to
process work without waiting for a response to return, while providing for a more
dynamic and efficient model to invoke Web services.
For example, a Web service interface might have methods for both synchronous and
asynchronous requests. Asynchronous requests are identified in bold below:
@WebService
public interface CreditRatingService {
// sync operation
Score getCreditScore(Customer customer);
// async operation with polling
Response<Score> getCreditScoreAsync(Customer customer);
// async operation with callback
Future<?> getCreditScoreAsync(Customer customer,
AsyncHandler<Score> handler);
}
The asynchronous invocation that uses the callback mechanism requires an additional
input by the client programmer. The callback is an object that contains the application
code that will be executed when an asynchronous response is received. The following
is a code example for an asynchronous callback handler:
while (!response.isDone()) {
// do something while we wait
}
The following example illustrates using the @Resource annotation for resource
injection:
@WebService
public class MyService {
@Resource
private WebServiceContext ctx;
Refer to sections 5.2.1 and 5.3 of the JAXWS 2.0 specification for more information
on resource injection.
Data binding with Java Architecture for XML Binding (JAXB) 2.0
JAXWS leverages the JAXB 2.0 API and tools as the binding technology for mappings
between Java objects and XML documents. JAXWS tooling relies on JAXB tooling for
default data binding for twoway mappings between Java objects and XML documents.
The dynamic client API for JAXWS is called the dispatch client
( javax.xml.ws.Dispatch ). The dispatch client is an XML messaging oriented client.
The data is sent in either PAYLOAD or MESSAGE mode. When using the PAYLOAD
mode, the dispatch client is only responsible for providing the contents of the
<soap:Body> and JAXWS adds the <soap:Envelope> and <soap:Header> elements.
When using the MESSAGE mode, the dispatch client is responsible for providing the
entire SOAP envelope including the <soap:Envelope>, <soap:Header>, and
<soap:Body> elements and JAXWS does not add anything additional to the message.
The dispatch client supports asynchronous invocations using a callback or polling
mechanism.
The static client programming model for JAXWS is the called the proxy client. The
proxy client invokes a Web service based on a Service Endpoint interface (SEI) which
must be provided.
Using JAXWS, you can send binary attachments such as images or files along with
Web services requests. JAXWS adds support for optimized transmission of binary
data as specified by Message Transmission Optimization Mechanism (MTOM).
JAXWS exposes the following binding technologies to the end user: XML Source,
SOAP Attachments API for Java (SAAJ) 1.3, and Java Architecture for XML Binding
(JAXB) 2.0. XML Source enables a user to pass a javax.xml.transform.Source into the
runtime which represents the data in a Source object to be processed. SAAJ 1.3 now
has the ability to pass an entire SOAP document across the interface rather than just
the payload itself. This is done by the client passing the SAAJ SOAPMessage object
across the interface. JAXWS leverages the JAXB 2.0 support as the data binding
technology of choice between Java and XML.
Support for SOAP 1.2 has been added to JAXWS 2.0. JAXWS supports both SOAP
1.1 and SOAP 1.2 so that you can send binary attachments such as images or files
along with Web services requests. JAXWS adds support for optimized transmission of
binary data as specified by MTOM.
JAXWS provides the wsgen and wsimport commandline tools for generating
portable artifacts for JAXWS Web services. When creating JAXWS Web services, you
can start with either a WSDL file or an implementation bean class. If you start with an
implementation bean class, use the wsgen commandline tool to generate all the Web
services server artifacts, including a WSDL file if requested. If you start with a WSDL
file, use the wsimport commandline tool to generate all the Web services artifacts for
either the server or the client. The wsimport command line tool processes the WSDL
file with schema definitions to generate the portable artifacts, which include the service
class, the service endpoint interface class, and the JAXB 2.0 classes for the
corresponding XML schema.
Introduction to JAXB
Java Architecture for XML Binding (JAXB) is a Java technology that provides an easy
and convenient way to map Java classes and XML schema for simplified development
of Web services. JAXB leverages the flexibility of platformneutral XML data in Java
applications to bind XML schema to Java applications without requiring extensive
knowledge of XML programming.
JAXB provides the xjc schema compiler tool, the schemagen schema generator tool,
and a runtime framework. You can use the xjc schema compiler tool to start with an
XML schema definition (XSD) to create a set of JavaBeans that map to the elements
and types defined in the XSD schema. You can also start with a set of JavaBeans and
use the schemagen schema generator tool to create the XML schema. Once the
mapping between XML schema and Java classes exists, XML instance documents can
be converted to and from Java objects through the use of the JAXB binding runtime
API. Data stored in XML documents can be accessed without the need to understand
the data structure. You can then use the resulting Java classes to assemble a Web
services application.
JAXB annotated classes and artifacts contain all the information needed by the JAXB
runtime API to process XML instance documents. The JAXB runtime API supports
marshaling of JAXB objects to XML and unmarshaling the XML document back to
JAXB class instances. Optionally, you can use JAXB to provide XML validation to
enforce both incoming and outgoing XML documents to conform to the XML
constraints defined within the XML schema.
JAXB is the default data binding technology used by the Java API for XML Web
Services (JAXWS) 2.0 tooling and implementation within this product. You can
develop JAXB objects for use within JAXWS applications.
You can also use JAXB independently of JAXWS when you want to leverage the XML
data binding technology to manipulate XML within your Java applications.
Java API for XMLBased Web Services (JAXWS) supports two different service
endpoint implementations types, the standard JavaBeans service endpoint
interface and a new Provider interface to enable services to work at the XML
message level. By using annotations on the service endpoint or client, you can
define the service endpoint as a Web service.
The JAXWS programming model also leverages support for annotating Java
classes with metadata to define a service endpoint application as a Web service
and define how a client can access the Web service. JAXWS supports
annotations based on the Metadata Facility for the Java Programming Language
(JSR 175) specification, the Web Services Metadata for the Java Platform (JSR
181) specification and annotations defined by the JAXWS 2.0 (JSR 224)
specification, which includes Java Architecture for XML Binding (JAXB)
annotations. Using annotations, the service endpoint implementation can
independently describe the Web service without requiring a WSDL file. Annotations
can provide all of the WSDL information necessary to configure your service
endpoint implementation or Web services client. You can specify annotations on
the service endpoint interface used by the client and the server, or on the server
side service implementation class.
To develop a JAXWS Web service, you must annotate your Java class with the
javax.jws.WebService annotation for JavaBeans endpoints or the
javax.jws.WebServiceProvider annotation for a Provider endpoint. These
annotations define the Java class as a Web service endpoint. For a JavaBeans
endpoint, the service endpoint interface or service endpoint implementation is a
Java interface or class, respectively, that declares the business methods provided
by a particular Web service. The only methods on a JavaBeans endpoint that can
be invoked by a Web services client are the business methods that are defined in
the explicit or implicit service endpoint interface.
When using a bottomup approach to develop JAXWS Web services, use the
wsgen commandline tool when starting from a service endpoint implementation.
The wsgen tool processes a compiled service endpoint implementation class as
input and generates the following portable artifacts:
any additional Java Architecture for XML Binding (JAXB) classes that are
required to marshal and unmarshal the message contents. The additional
classes include classes that are represented by the @RequestWrapper
annotation and the @ResponseWrapper annotation for a wrapped method.
a WSDL file if the optional wsdl argument is specified. The wsgen command
does not automatically generate the WSDL file. The WSDL file is automatically
generated when you deploy the service endpoint.
You are not required to develop a WSDL file when developing JAXWS Web
services using the bottomup approach of starting with JavaBeans. The use of
annotations provides all of the WSDL information necessary to configure the
service endpoint or the client. Axis2 supports WSDL 1.1 documents that comply
with Web ServicesInteroperability (WSI) Basic Profile 1.1 specifications and are
either Document/Literal style documents or RPC/Literal style documents.
Additionally, WSDL documents with bindings that declare a USE attribute of value
LITERAL are supported while the value, ENCODED , is not supported. For WSDL
documents that implement a Document/Literal wrapped pattern, a root element is
declared in the XML schema and is used as an operation wrapper for a message
flow. Separate wrapper element definitions exist for both the request and the
response.
To ensure the wsgen command does not miss inherited methods on a service
endpoint implementation bean, you must either add the @WebService annotation
to the desired superclass or you can override the inherited method in the
implementation class with a call to the superclass method. Implementation classes
only expose methods from superclasses that are annotated with the
@WebService annotation.
Note: The wsgen command does not differentiate the XML namespace between
multiple XMLType annotations that have the same @XMLType name defined
within different Java packages. When this scenario occurs, the following error is
produced:
Error: Two classes have the same XML type name ....
Use @XmlType.name and @XmlType.namespace to assign different names
to them...
This error indicates you have class names or @XMLType.name values that have
the same name, but exist within different Java packages. To prevent this error, add
the @XML.Type.namespace class to the existing @XMLType annotation to
differentiate between the XML types.
3. Develop the Java artifacts.
4. Package and deploy your service.
You can use the JAXWS tool, wsimport, to process a WSDL file and generate
portable Java artifacts that are used to create a Web service. The portable Java
artifacts created using the wsimport tool are:
Service endpoint interface (SEI)
Service class
Exception class that is mapped from the wsdl:fault class (if any)
Java Architecture for XML Binding (JAXB) generated type values which are Java
classes mapped from XML schema types
Run the
command to generate the portable artifacts. The keep option tells the tool not to
delete the generated files, and the verbose option tells it to list the files that were
created. The ObjectFactory.java file that is created contains factory methods for each
Java content interface and Java element interface generated in the associated
package. The packageinfo.java file takes the targetNamespace value and creates
the directory structure.
You must now provide an implementation for the SEI created by the tool.
Dispatch client: Use this client when you want to work at the XML message level or
when you want to work without any generated artifacts at the JAXWS level.
Dynamic Proxy client: Use this client when you want to invoke a Web service
based on a service endpoint interface.
Dispatch client
XMLbased Web services use XML messages for communications between Web
services and Web services clients. The JAXWS APIs provide highlevel methods to
simplify and hide the details of converting between Java method invocations and their
associated XML messages. However, in some cases, you might desire to work at the
XML message level. Support for invoking services at the XML message level is
provided by the Dispatch client API. The Dispatch client API,
javax.xml.ws.Dispatch , is a dynamic JAXWS client programming interface. To
write a Dispatch client, you must have expertise with the Dispatch client APIs, the
supported object types, and knowledge of the message representations for the
associated WSDL file. The Dispatch client can send data in either MESSAGE or
PAYLOAD mode. When using the javax.xml.ws.Service.Mode.MESSAGE mode,
the Dispatch client is responsible for providing the entire SOAP envelope including the
<soap:Envelope> , <soap:Header> , and <soap:Body> elements. When using the
javax.xml.ws.Service.Mode.PAYLOAD mode, the Dispatch client is only
responsible for providing the contents of the <soap:Body> and JAXWS includes the
payload in a <soap:Envelope> element.
The Dispatch client API requires application clients to construct messages or payloads
as XML which requires a detailed knowledge of the message or message payload.
The Dispatch client supports the following types of objects:
javax.xml.transform.Source : Use Source objects to enable clients to use
XML APIs directly. You can use Source objects with SOAP or HTTP bindings.
JAXB objects: Use JAXB objects so that clients can use JAXB objects that are
generated from an XML schema to create and manipulate XML with JAXWS
applications. JAXB objects can only be used with SOAP or HTTP bindings.
javax.xml.soap.SOAPMessage : Use SOAPMessage objects so that clients can
work with SOAP messages. You can only use SOAPMessage objects with SOAP
bindings.
javax.activation.DataSource : Use DataSource objects so that clients can
work with Multipurpose Internet Mail Extension (MIME) messages. Use
DataSource only with HTTP bindings.
For example, if the input parameter type is javax.xml.transform.Source, the call to the
Dispatch client API is similar to the following code example:
The Dispatch parameter value determines the return type of the invoke() method.
Refer to Chapter 4 of the JAXWS 2.0 specification for more information on using
Dynamic Proxy clients.
The static client programming model for JAXWS is the called the dynamic proxy client.
The dynamic proxy client invokes a Web service based on a service endpoint interface
that is provided. After you create the proxy, the client application can invoke methods
on the proxy just like a standard implementation of those interfaces. For JAXWS Web
service clients using the dynamic proxy programming model, use the JAXWS tool,
wsimport, to process a WSDL file and generate portable Java artifacts that are used
to create a Web service client.
Create the following portable Java artifacts using the wsimport tool:
Service endpoint interface (SEI)
Service class
Exception class that is mapped from the wsdl:fault class (if any)
Java Architecture for XML Binding (JAXB) generated type values which are Java
classes mapped from XML schema types
You can customize the bindings in your WSDL file to enable asynchronous
mappings or attachments. To generate asynchronous interfaces, add the client
side only customization enableAsyncMapping binding declaration to the
wsdl:definitions element or in an external binding file that is defined in the
WSDL file. Use the enableMIMEContent binding declaration in your custom client
or server binding file to enable or disable the default mime:content mapping
rules. For additional information on custom binding declarations, see chapter 8 the
JAXWS specification.
3. Run the wsimport keep wsdl_URL command to generate the portable client
artifacts. Use the verbose option to see a list of generated files when you run the
command.
Best practice: When you run the wsimport tool, the location of your WSDL file
must either be omitted or point to a valid WSDL document. A best practice for
ensuring that you produce a JAXWS Web services client that is portable to other
systems is to package the WSDL document within the application module such as
a Web services client Java archive (JAR) file or a Web archive (WAR) file. You can
specify a relative URI for the location of your WSDL file by using the
wsdllocation annotation attribute. For example, if your MyService.wsdl file is
located in the METAINF/wsdl/ directory, then run the wsimport tool and use the
wsdllocation option to specify the value to be used for the location of the WSDL
file.
The Dispatch API can send data in either PAYLOAD or MESSAGE mode. When using
the PAYLOAD mode, the Dispatch client is only responsible for providing the contents
of the <soap:Body> and JAXWS includes the input payload in a <soap:Envelope>
element. When using the MESSAGE mode, the Dispatch client is responsible for
providing the entire SOAP envelope.
The Dispatch client API requires application clients to construct messages or payloads
as XML and requires a detailed knowledge of the message or message payload. The
Dispatch client can use HTTP bindings when using Source objects, Java Architecture
for XML Binding (JAXB) objects, or data source objects. The Dispatch client supports
the following types of objects:
The Dispatch API uses the concept of generics that are introduced in Java Runtime
Environment Version 5. For each of the invoke() methods on the Dispatch interface,
generics are used to determine the return type.
The following example illustrates the steps to create a Dispatch client and invoke a
sample EchoService service endpoint.
String endpointUrl = ...;
/** Create a service and add at least one port to it. **/
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUr
l);
org.apache.axis2.jaxws.use.async.mep
property to the request context to enable asynchronous messaging for the Web
services client. Using this property requires that the service endpoint supports WS
Addressing which is supported by default for the application server. The following
example demonstrates how to set this property:
Map<String, Object> rc = ((BindingProvider) port).getReques
tContext();
rc.put("org.apache.axis2.jaxws.use.async.mep", Boolean.TRU
E);
When developing Dynamic Proxy clients, after you generate the portable client
artifacts from a WSDL file using the wsimport command, the generated service
endpoint interface (SEI) does not have asynchronous methods included in the
interface. Use JAXWS bindings to add the asynchronous callback or polling methods
on the interface for the Dynamic Proxy client. To enable asynchronous mappings, you
can add the jaxws:enableAsyncMapping binding declaration to the WSDL file. For
more information on adding binding customizations to generate an asynchronous
interface, see chapter 8 of the JAXWS specification.
Note: When you run the wsimport tool and enable asynchronous invocation through
the use of the JAXWS enableAsyncMapping binding declaration, ensure that the
corresponding response message your WSDL file does not contain parts. When a
response message does not contain parts, the request acts as a twoway request, but
the actual response that is sent back is empty. The wsimport tool does not correctly
handle a void response. To avoid this scenario, you can remove the output message
from the operation which makes your operation a oneway operation or you can add a
<wsdl:part> to your message. For more information on the usage, syntax and
parameters for the wsimport tool, see the wsimport command for JAXWS
applications documentation.
The following example illustrates a Web service interface with methods for
asynchronous requests from the client.
@WebService
Using the callback method The callback method requires a callback handler that is
shown in the following example. When using the callback procedure, after a request is
made, the callback handler is responsible for handling the response. The response
value is a response or possibly an exception. The Future<?> method represents the
result of an asynchronous computation and is checked to see if the computation is
complete. When you want the application to find out if the request is completed, invoke
the Future.isDone() method. Note that the Future.get() method does not
provide a meaningful response and is not similar to the Response.get() method.
CreditRatingService svc = ...;
Using the polling method The following example illustrates an asynchronous polling
client:
while (!response.isDone()) {
// Do something while we wait.
}
score = response.get();
The second type of handler is a protocol handler. The protocol handlers operate on
message context properties and protocolspecific messages. Protocol handlers are
limited to SOAPbased configurations and must implement the
javax.xml.ws.handler.soap.SOAPHandler interface. Protocol handlers receive
the message as a javax.xml.soap.SOAPMessage to read the message data.
The JAXWS runtime makes no distinction between serverside and clientside handler
classes. The runtime does not distinguish between inbound or outbound flow when a
handleMessage(MessageContext) method or handleFault(MessageContext)
method for a specific handler is invoked. You must configure the handlers for the
server or client, and implement sufficient logic within these methods to detect the
inbound or outbound direction of the current message.
To use handlers with Web services client applications, you must add the
@HandlerChain annotation to the service endpoint interface or the generated service
class and provide the handler chain configuration file. The @HandlerChain
annotation contains a file attribute that points to a handler chain configuration file that
you create. For Web services client applications, you can also configure the handler
chain programmatically using the Binding API. To modify the handlerchain class
programmatically, use either the default implementation or a custom implementation of
the HandlerResolver method.
To use handlers with your server application, you must set the @HandlerChain
annotation on either the service endpoint interface or the endpoint implementation
class, and provide the associated handler chain configuration file. Handlers for the
server are only configured by setting the @HandlerChain annotation on the service
endpoint implementation or the implementation class. The handler classes must be
included in the deployed artifact.
For both server and client implementations of handlers using the @HandlerChain
annotation, you must specify the location of the handler configuration as either a
relative path from the annotated file or as an absolute URL. For example:
@HandlerChain(file="../../common/handlers/myhandlers.xml")
or
@HandlerChain(file="http://foo.com/myhandlers.xml")
For more information on the schema of the handler configuration file, see the JSR 181
specification.
For more information regarding JAXWS handlers, see chapter 9 of the JAXWS
specification.
The following example illustrates the steps necessary to configure JAXWS handlers
on a service endpoint interface using the @HandlerChain annotation.
The @HandlerChain annotation has a file attribute that points to a handler chain
configuration XML file that you create. The following file illustrates a typical handler
configuration file. The protocolbindings , portnamepattern , and service
namepattern elements are all filters that are used to restrict which services can
apply the handlers.
<?xml version="1.0" encoding="UTF‐8"?>
<jws:handler‐chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
<!‐‐ Note: The '*" denotes a wildcard. ‐‐>
<jws:handler‐chain name="MyHandlerChain">
<jws:protocol‐bindings>##SOAP11_HTTP ##ANOTHER_BINDING</j
ws:protocol‐bindings>
<jws:port‐name‐pattern
xmlns:ns1="http://handlersample.samples.apache.org/">ns
1:MySampl*</jws:port‐name‐pattern>
<jws:service‐name‐pattern
xmlns:ns1="http://handlersample.samples.apache.org/">ns
1:*</jws:service‐name‐pattern>
<jws:handler>
<jws:handler‐class>org.apache.samples.handlersamp
le.SampleLogicalHandler</jws:handler‐class>
</jws:handler>
<jws:handler>
<jws:handler‐class>org.apache.samples.handlersamp
le.SampleProtocolHandler2</jws:handler‐class>
</jws:handler>
<jws:handler>
<jws:handler‐class>org.apache.samples.handlersamp
le.SampleLogicalHandler</jws:handler‐class>
</jws:handler>
<jws:handler>
<jws:handler‐class>org.apache.samples.handlersamp
le.SampleProtocolHandler2</jws:handler‐class>
</jws:handler>
</jws:handler‐chain>
</jws:handler‐chains>
Make sure that you add the handler.xml file and the handler classes contained in the
handler.xml file in your class path.
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
The interaction between the browser, application server, and application is transparent
to the user and the application program. The application and the user are typically not
aware of the session identifier provided by the server.
Session cookies
The HTTP maintain session feature uses a single cookie, JSESSIONID , and this
cookie contains the session identifier. This cookie is used to associate the request with
information stored on the server for that session. On subsequent requests from the
JAXWS application, the session ID is transmitted as part of the request header, which
enables the application to associate each request for a given session ID with prior
requests from that user. The JAXWS client applications retrieve the session ID from
the HTTP response headers and then use those IDs in subsequent requests by setting
the session ID in the HTTP request headers.
URL rewriting
URL rewriting works like a redirected URL as it stores the session identifier in the URL.
The session identifier is encoded as a parameter on any link or form that is submitted
from a Web page. This encoded URL is used for subsequent requests to the same
server.
Enabling MTOM
JAXWS supports the use of SOAP Message Transmission Optimized Mechanism
(MTOM) for sending binary attachment data. By enabling MTOM, you can send and
receive binary data optimally without incurring the cost of data encoding to ensure the
data is included in the XML document.
JAXWS applications can send binary data as base64 or hexBinary encoded data
contained within the XML document. However, to take advantage of the optimizations
provided by MTOM, enable MTOM to send binary base64 data as attachments
contained outside the XML document. MTOM optimization is only available for the
xs:base64Binary data type. The MTOM option is not enabled by default. JAXWS
applications require separate configuration of both the client and the server artifacts to
enable MTOM support. For the server, MTOM can be enabled on a JAXWS
JavaBeans endpoint only and not on a providerbased endpoint.
//Enable MTOM
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);