aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Order of Handlers on Server Side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Order of Handlers on Server Side" Watch "Order of Handlers on Server Side" New topic
Author

Order of Handlers on Server Side

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
Hi All,

I have configured my handlers.xml like this :


<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>fromjava.server.MyHandler1</handler-class>
</handler>
<handler>
<handler-class>fromjava.server.MyHandler2</handler-class>
</handler>
<handler>
<handler-class>fromjava.server.MyHandler3</handler-class>
</handler>
</handler-chain>
</handler-chains>


I sent a request from Client side and in each of the handler's handleMessage(SOAPMessageContext smc) , I am printing the output to a file like :


//MyHandler1.java
try {
FileWriter fw = new FileWriter(f,true);
if((Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) == true)
fw.write("MyHandler1 Outgoing *********");
else
fw.write("MyHandler1 Incoming *********");
fw.close();
} catch (IOException e) {
e.printStackTrace();
}


//MyHandler2.java
try {
FileWriter fw = new FileWriter(f,true);
if((Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) == true)
fw.write("MyHandler2 Outgoing *********");
else
fw.write("MyHandler2 Incoming *********");
fw.close();
} catch (IOException e) {
e.printStackTrace();
}


//MyHandler3.java
try {
FileWriter fw = new FileWriter(f,true);
if((Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) == true)
fw.write("MyHandler3 Outgoing *********");
else
fw.write("MyHandler3 Incoming *********");
fw.close();
} catch (IOException e) {
e.printStackTrace();
}


I sent a request from Client side and the file produces this output.

MyHandler3 Incoming *********
MyHandler2 Incoming *********
MyHandler1 Incoming *********
MyHandler1 Outgoing *********
MyHandler2 Outgoing *********
MyHandler3 Outgoing *********

Is this order right , I thought MyHandler1 will get the input request first !
Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
All of the handlers are protocol handlers (implement implements SOAPHandler<SOAPMessageContext>
Anila Mathew
Ranch Hand

Joined: Jun 16, 2004
Posts: 69

This is what I think about your question.

jaxws-2_0 spec says:

"For outbound messages handler processing starts with the first handler in the chain and proceeds in the same order as the handler chain. For inbound messages the order of processing is reversed: processing starts with
the last handler in the chain and proceeds in the reverse order of the handler chain."

Which means outbound messages are the ones that comes back from the webservice to the client, and inbound messages are the ones which are given to the webservice; which explains why MyHandler3 Incoming ********* as the first print in your application.

Let me know what you think.
Faraz Ali
Ranch Hand

Joined: May 15, 2008
Posts: 108
Hi Sim Kim,

Can you please please share us all of your findings about SOAP, UDDI, WSDL, JAX-WS, in the form of hints and tricks.

Since i am a beginner in web services, thats why i m just trying to understand the basic concepts. And i know the SCDJWS will be very tough, so my preparation might not help a lot. If you share your knowledge with us, that it will be very advantegous for all of us.

And i request all of you guys to post your notes/hints/tricks here. I will also do so.

Thank you very much,
Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
Anila,

I guess your are right . But when I read the RMH book it said otherwise (or may be that is what I understood)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Order of Handlers on Server Side