Java SOAP Handler in Web Services - Quiz

Total: 43 questions

1. How does application code inspect and manipulate outgoing and incoming SOAP messages?
JWS provides a handler framework which help to do it.
2. How to inject a handler into the framework?
1. Create a handler class. 2. Place a handler within a handler chain.
3. Which interface handler class should implement?
The javax.xml.ws.handler.Handler class.
4. 

Subinterfaces of Handler interface.

LogicalHandler and SOAPHandler.

5. Is LogicalHandler protocol-neutral or SOAP-specific?
Protocol-neutral.
6. Is SOAPHandler protocol-neutral or SOAP-specific?
SOAP-specific.
7. Difference between LogicalHandler and SOAPHandler?
A LogicalHandler has access only to the message payload in the SOAP body, and a SOAPHandler has access to the entire SOAP message, including any optional headers and attachments.
8. Methods of Handler interface.
- handleMessage; - handleFault; - close;
9. What handleMessage method is used for?
It gives the access to the underlying message.
10. How to put a handler within a handler chain?
- by a configuration file; - managed through code.
11. Which method does SOAPHandler interface add?
getHeaders
12. Two ways to throw SOAP faults in JWS.
1. The Exception class is extended and a new exception is thrown in a @WebMethod. Then thrown Java exception is mapped to a SOAP fault by JWS. 2.A SOAPFaultException is created and thrown from a handler.
13. 

Example of handler deployment file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<javaee:handler-chains
    xmlns:javaee="http://java.sun.com/xml/ns/javaee"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <javaee:handler-chain>
   <javaee:handler>
    <javaee:handler-class>com.examclouds.QuestionHandler</javaee:handler-class>
   </javaee:handler>
 </javaee:handler-chain>
</javaee:handler-chains>
14. What does it mean if handleMessage returns true/false?
A returned true means continue message processing by executing the next handler in the chain, whereas a returned false means stop message processing.
15. Will the message be sent if a handler stops processing on an outgoing message?
No.
16. Can the order of executing handlers be different from what it is in configuration file?
Yes.
17. Methods of which handlers types are executed first for an outbound message - LogicalHandler or SOAPHandler?
Of a LogicalHandler.
18. Methods of which handlers types are executed first for an inbound message - LogicalHandler or SOAPHandler?
Of a SOAPHandler.
19. If a handler configuration file lists SOAP handlers (SH) and logical handlers (LH) in this order, top to bottom: SH1 LH1 SH2 SH3 LH2 In which order will the handlers be executed on an outgoing message?
LH1 LH2 SH1 SH2 SH3
20. If a handler configuration file lists SOAP handlers (SH) and logical handlers (LH) in this order, top to bottom: SH1 LH1 SH2 SH3 LH2 In which order will the handlers be executed on an incoming message?
SH1 SH2 SH3 LH1 LH2
21. Why the order of executing handlers is changing?
The runtime ordering makes sense because the LogicalHandler has access only to the body of the SOAP message, whereas the SOAPHandler has access to the entire SOAP message. For an outgoing message, then, the logical handlers should be able to process the payload, the SOAP body, before the SOAP handlers process the entire SOAP message.
22. When LogicalHandler should be used instead of SOAPHandler?
If the application does not need to process SOAP headers or SOAP attachments.
23. The subtypes of MessageContext.
SOAPMessageContext and LogicalMessageContext.
24. The types of parameters to handleMessage() in Handler.
SOAPMessageContext and LogicalMessageContext.
25. What is context from architectural point of view?
A context is what gives an object (a servlet, an EJB, a web service) access to its underlying container (servlet container, EJB container, web service container).
26. 

What is a context from programmatical point of view?

It is a key/value collection - Map<String, Object>.

27. How does Java provide access to HTTP messages in a handler or SIB?
Through a MessageContext.
28. How does Java provide access to HTTP messages in a Java-based client?
Through the BindingProvider and the request/response contexts, which are exposed as BindingProvider properties.
29. How to receive MessageContext in webservice?
@Resource WebServiceContext ws_ctx; @WebMethod public String echo(String str) { MessageContext ctx = ws_ctx.getMessageContext(); ... }
30. Which goals logical handlers are used for?
For building non-functional behavior, for example logging and caching.
31. 

What MessageContext. MESSAGE_OUTBOUND _PROPERTY property is used for?

It gives the direction of the message:

MessageContext ctx=.. 
Boolean outbound = ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
32. Example of receiving message.
LogicalMessage message = ctx.getMessage();
33. Example of receiving payload.
LogicalMessage message = ctx.getMessage(); Source payload = message.getPayload();
34. The main reason for using a SOAP handler.
To manipulate SOAP headers.
35. 

Example of a SOAP handler.

public class MyHandler implements SOAPHandler <SOAPMessageContext> {
    public Set<QName> getHeaders() {
        return null;
    }

    public void close(MessageContext ctx) {
    }

    public boolean handleFault(SOAPMessageContext ctx) {
        return false;
    }

    public boolean handleMessage(SOAPMessageContext ctx) {
        return false;
    }
}
36. Example of applying a handler chain to the web service with @HandlerChain.
@WebService @HandlerChain(file = "myChain.xml") public class MyMessenger { public String printName(String name) { return String.format("Hi %s", name); } }
37. Which annotation does port-component-name relate to?
To @WebService.name.
38. Which annotation does wsdl-service relate to?
To @WebService.serviceName.
39. Which annotation does wsdl-port relate to?
To @WebService.portName.
40. Which annotation does service-endpoint-interface relate to?
To @WebService.endpointInterface.
41. Does declarative configuration work for all clients?
No, only for proxy clients.
42. 

Which method is used to programmatically add Handler to the client?

Service.setHandlerResolver(HandlerResolver handlerResolver);
43. Example that programmatically adds the Handler to the client-side SEI.
public class ExamClientWithHandler { public static void main(String... args) throws Exception { ExamMessengerService service = new ExamMessengerService(); service.setHandlerResolver( new HandlerResolver() { public List getHandlerChain( PortInfo inf) { return Collections.singletonList(new ExamMessengerProtocolHandler()); } }); ExamMessenger port = service.getExamMessengerPort(); String message = port.printExamName("E1"); System.out.println(message); } }
Page 1 of 1