JAX-WS and XML

JAX-WS is mainly used for working with SOAP based web services and SOAP based web services are primarily based on XML: SOAP message (which is the format for message exchange in SOAP web services ) itself is XML and WSDL (which is the description of a SOAP web service) is also XML based. So we will discuss few important points about JAX-WS and XML.

It is always preferred to use JAXB and JAX-WS specific newer APIs than other technologies mentioned here, like JAXP, SAAJ, MTOM etc. if possible. Older technologies are given here as it may be required for exams such as Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam (IZ0-897).

 

Important points about JAX-WS and XML

  1. To provide interoperability between web services written in different programming languages, web services uses XML Schema (XSD) which is a shared types system.

    • Typed web service messages require requires binding of XML Schema types and the programming language types (e.g. java data types).

    • The types section of a WSDL holds, points to, or imports an XSD. 

      • Although the WSDL 2.0 specification allows for alternatives to XML schema, XML schema is the default and the dominant type system used in WSDL.

      • The types section is optional.

        • If the types section is empty, then the service uses only simple data types such as xsd:string and xsd:long.

  2. Under the hood, pacakges in JAX-WS uses JAXB for the bindings between XSD types and Java types.

    • JAXB stands for Java Architecture for XML Binding and provides a Java API that can map Java objects to XML content and XML content to Java objects. Read more @ http://javajee.com/introduction-to-jaxb-2.

    • JAXB is the most preferred way of binding in JAX-WS.

  3. The SOAP with Attachments API for Java or SAAJ provides a standard way to send XML documents over the Internet from the Java platform.

    • SOAP mechanism for carrying large payloads and binary data as an attachment rather than inside the SOAP message envelope.

    • Developers can also use it to write SOAP messaging applications directly instead of using JAX-RPC or JAX-WS.

    • SAAJ 1.3 is the supported version for data binding with SOAP.

  4. Older versions of JAX-WS (JAX-RPC) used JAXP API for processing XML

    • The Java API for XML Processing, or JAXP, is a Java XML Application programming interfaces (API) that provides the capability of validating and parsing XML documents.

    • JAXP provide developers with a vendor and parser-implementation independent API to process XML.

    • The three basic parsing interfaces for JAXP are:

      • The Document Object Model parsing interface or DOM interface

      • The Simple API for XML parsing interface or SAX interface

      • The Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)

    • You can still work with JAXP APIs with JAX-WS, but JAXB is the preferred way. 

  5. MTOM a method of efficiently sending binary data to and from Web services.

    • MTOM is the W3C Message Transmission Optimization Mechanism.

    • MTOM (Message Transmission and Optimization Mechanism) together with XOP (XML Binary Optimized Packaging) defines how an XML binary data such as xs:base64Binary or xs:hexBinary can be optimally transmitted over the wire.

    • MTOM is specialized way of sending attachments. It can be used by JAX-WS or even SAAJ APIs.

    • MTOM feature is disabled in JAX-WS by default.

      • It can be enabled on the client and server. 

      • You can enable MTOM on a web service endpoint deployed in an EE container by specifying:

        • @MTOM annotation on the endpoint's class

        • <enable-mtom> in webservices.xml deployment descriptor

        • a wsoma:MTOM policy in WSDL

      • You can enable MTOM at client by calling setMTOMEnabled(true); on the SOAPBining object.

    • ​An MTOM optimized infoset+attachment for a large binary data saves around 30% in size when compared to original infoset.

    • The HTTP content-type header when a message is optimized using MTOM will be multipart/related.

 

Important Note

It is always preferred to use JAXB and JAX-WS specific newer APIs than other technologies mentioned here, like JAXP, SAAJ, MTOM etc. if possible. Older technologies are given here as it may be required for exams such as Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam (IZ0-897).

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!