Java MTOM and MIME: Enhancing Efficiency - Quiz

Total: 61 questions

1. Can SOAP-based web services consume or return binary data?
Yes.
2. General approaches to handling arbitrary binary data in SOAP-based web services.
- To encode data as base64 and transmit as the payload of the SOAP body. - To transmit as one or more attachments of a SOAP message.
3. Describe approach of handling binary data in SOAP-based web services using encoding.
For instance, a service operation that returns an image to a requester simply could return a java.awt.Image, which is a Java wrapper for image bytes. The image's bytes then would be encoded and transmitted as the body of a SOAP message.
4. Options of SOAP attachments.
- SwA; - DIME; - MTOM.
5. The downside of sending byte data as attachment.
The receiver must deal with the raw bytes, for example, by converting them back into multimedia types such as images and sounds.
6. Main purpose of a DIME extension.
To work with Microsoft clients.
7. Drawbacks of SwA approach.
- It is hard to use with a document-style service. - Frameworks such as .Net don't support SwA.
8. What does acronym MTOM mean?
Message Transmission Optimization Mechanism
9. What MTOM is used for?
The binary data can be sent and received without data encoding.
10. Which type of binary data JAX-WS can send within the XML document?
Base64 or hexBinary.
11. Which type of data does MTOM use?
Binary base64 data.
12. Is MTOM optimization enabled by default?
No.
13. Does MTOM send binary data as part of XML document?
No, as attachments outside of the XML document.
14. Should JAX-WS applications configurate the client or the server artifacts to enable MTOM support?
Both.
15. Can MTOM be enabled on the endpoints that implement Provider interface?
No.
16. How to enable MTOM for the server?
1. Java artifacts for the JAX-WS application should be developed which includes an XML schema or WSDL file that represents the web services application data that has a binary attachment. 2. Use the @MTOM annotation on the endpoint.
17. Which element is used in the XML schema for the binary data?
A xsd:base64Binary or xsd:hexBinary.
18. What xmime:expectedContentTypes attribute is used for?
To affect the mapping by JAXB.
19. Parameters of the @MTOM annotation?
Enabled and threshold.
20. What @MTOM.enabled is used for?
It specifies if MTOM is enabled for the JAX-WS endpoint.
21. What @MTOM.threshold parameter is used for?
It defines the minimum size for messages which are sent using MTOM.
22. 

Write example where MTOM is enabled on the web service.

@MTOM
@WebService(name = "ExamPortType",
            serviceName = "ExamService",
            targetNamespace="http://www.examclouds.com")
public class ExamImpl {
  @WebMethod
  public String exam(byte[] bytes) {
    return new String(bytes);
  }
}
23. What @BindingType annotation is used for?
@BindingType annotation on a SEI specifies that the endpoint supports one of the MTOM binding types so that the response messages are MTOM-enabled.
24. 

Which constants does SOAPBinding class define for the value of the @BindingType annotation?

SOAP11HTTP_MTOM_BINDING and SOAP12HTTP_MTOM_BINDING for SOAP version 1.1 and SOAP version 1.2 correspondingly.
25. 

Example of using the Optimized Mime Serialization policy assertion.

<wsdl:definitions
           targetNamespace="examclouds.com"
           xmlns:tns="examclouds.com"
  ... >
       <wsp:Policy wsu:Id="ExamPolicy" >
           <wsoma:OptimizedMimeSerialization />
      </wsp:Policy>
      <wsdl:binding name="ExamBinding" type="tns:ExamPortType" >
          <wsp:PolicyReference
              URI="#ExamPolicy"
              wsdl:required="true" />
      </wsdl:binding>
  </wsdl:definitions>
26. For which elements an optimization is available?
For the xs:base64Binary data type only.
27. 

Example of how binding uses the MTOM policy.

<binding name="examBinding" type="tns:examPortType">
    <wsp:PolicyReference URI="#examBindingPolicy"/>
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="examOperation">
        <soap:operation/>
        <input name="input1">
            <soap:body use="literal" namespace="http://j2ee.netbeans.org/wsdl/mtomBP/mtom"/>
        </input>
        ...
</binding>
28. 

Example of the SOAP envelope with binary data transmitted as MTOM.

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:mtomOperation xmlns:ns2="http://j2ee.netbeans.org/wsdl/mtomBP/mtom">
            <part1>English</part1>
            <part2>
                <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include"
                    href="cid:[email protected]" />
            </part2>
        </ns2:mtomOperation>
    </S:Body>
</S:Envelope>
29. 

Which element in wsdl is used to specify where the binary data is?

A <xop:Include> element.
30. Is MTOM suitable for a large number of tiny attachments?
No.
31. How to enable MTOM on server?
The enable-mtom attribute can be used in the sun-jaxws.xml configuration file.
32. 

What MTOMFeature is used for?

To specify if MTOM should be used with a web service. The feature is used instead of the SOAPBinding.SOAP11HTTP_MTOM_BINDING, 
SOAPBinding.SOAP12HTTP_MTOM_BINDING and 
the SOAPBinding.setMTOMEnabled().
33. Properties of the MTOMFeature.
The threshold.
34. What swaRef is used in WSDL for?
In this mechanism the content of XML element of type wsi:swaRef is sent as MIME attachment and the element inside SOAP Body holds the reference to this attachment in the CID URI scheme.
35. How to enable MTOM on the client side?
The MTOMFeature should be passed to the proxy constructor.
36. 

Describe how to map wsi:swaRef to DataHandler by JAXB 2.0.

An application constructs the DataHandler with the data and the appropriate MIME type and JAX-WS coordinates with JAXB and SAAJ to send it as attachment MIME part.

37. Which class does MTOMFeature extend?
The WebServiceFeature.
38. Example of enabling MTOM on the client.
Exam examPort = service.getExamPort(new MTOMFeature());
39. Which parameters does the MTOMFeature constructor accept?
An optional integer argument indicating the threshold, or the number of bytes that the binary data should be before being sent as an attachment.
40. Methods of enabling MTOM on a Dispatch client.
- using SOAPBinding.setMTOMEnabled(); - using Service.addPort; - using MTOMFeature;
41. 

Example of enabling MTOM on a Dispatch client by using SOAPBinding. setMTOMEnabled().

SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
binding.setMTOMEnabled(true);
42. 

Example of enabling MTOM on a Dispatch client by using Service.addPort.

Service svc = Service.create(serviceName);
svc.addPort(portName,SOAPBinding.SOAP11HTTP_MTOM_BINDING,endpointUrl);
43. 

Example of enabling MTOM on a Dispatch client by using MTOMFeature.

MTOMFeature mtomFeature = new MTOMFeature(true, 1024);
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11_HTTP_BINDING, endpointUrl);
Dispatch<Source> dsp = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD, mtomFeature);
44. Example of enabling MTOM on a Dynamic Proxy client.
Service service = Service.create(serviceName); MtomSample proxy = service.getPort(portName, MtomSample.class); BindingProvider bp = (BindingProvider) proxy; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true); MTOMFeature mtom = new MTOMFeature(); MtomSample proxy = service.getPort(portName, MtomSample.class, mtom);
45. 

Example of enabling MTOM on the client using the @MTOM annotation.

public class ClientApplication {
	    @MTOM(enabled = true, threshold = 1024)
	    @WebServiceRef(ExamService.class)
	    private ExamPortType examPort;
    ...
}
46. 

Example of enabling MTOM on the client using deployment descriptor elements within a port-component-ref element.

<service-ref>
    <service-ref-name>service/ExamPortComponentRef</service-ref-name>
    <service-interface>com.examclouds.ExamService</service-ref-interface>
    <port-component-ref>
        <service-endpoint-interface>com.examclouds.ExamPortType</service-endpoint-interface>
        <enable-mtom>true</enable-mtom>
        <mtom-threshold>1024</mtom-threshold>
    </port-component-ref>
</service-ref>
47. Scopes of properties for MessageContext.
APPLICATION or HANDLER.
48. Are all properties available to all handlers for an instance of a MEP on a particular endpoint?
Yes.
49. If a logical handler sets a property in the message context, where that property will be available?
To any protocol handlers in the chain during the execution of a MEP instance.
50. Where APPLICATION scoped properties are available?
To service endpoint implementations and client applications.
51. The default property's scope?
HANDLER.
52. 

Example of standard message context properties.

- javax.xml.ws.binding.attachments.inbound
- javax.xml.ws.binding.attachments.outbound
53. 

Type of javax.xml.ws.binding. attachments.inbound and javax.xml.ws.binding. attachments.outbound.

Map<String, DataHandler>

54. 

What are the key and the value of javax.xml.ws. binding.attachments.inbound and javax.xml.ws. binding.attachments.outbound properties?

The key is an unique identifier for the attachment. The value is a DataHandler for the attachment data.

55. 

Specified constants for javax.xml.ws.binding. attachments.inbound and javax.xml.ws.binding. attachments.outbound properties of MessageContext.

OUTBOUND_MESSAGE_ATTACHMENTS, 
INBOUND_MESSAGE_ATTACHMENTS.
56. 

Where Mime attachments, specified by the javax.xml.ws.binding. attachments.inbound and javax.xml.ws.binding. attachments.outbound properties can be changed?

In logical handlers.

57. 

Does any changes to the javax.xml.ws.binding. attachments.inbound and javax.xml.ws.binding. attachments.outbound properties applicable after calling the first SOAPHandler?

No, they are ignored.

58. Can the SOAPHandler modify the properties in the MessageContext?
Yes.
59. 

Will attachments, specified by the javax.xml.ws.binding. attachments.outbound property, be included as mime attachments in the message, when using Dispatch in SOAP / HTTP binding in payload mode?

Yes.

60. 

Will the javax.xml.ws.binding. attachments.outbound property be applied when using Dispatch in SOAP / HTTP binding in message mode?

No.

61. 

Example of setting properties to Dispatch client.

Dispatch<String> d = s.createDispatch(portName, String.class, Service.Mode.PAYLOAD);
Map<String, Object> requestContext = d.getRequestContext();
Map<String, DataHandler> attachments = new HashMap();
attachments.put("examCID", examDataHandler);
requestContext.put("javax.xml.ws.binding.attachments.outbound", attachments);
Page 1 of 1