1 package org.codehaus.xfire.xmpp;
2
3 import org.codehaus.xfire.MessageContext;
4 import org.codehaus.xfire.fault.XFireFault;
5 import org.codehaus.xfire.handler.AbstractHandler;
6 import org.jivesoftware.smack.packet.XMPPError;
7
8 /***
9 * Creates fault information for the response packet.
10 *
11 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
12 */
13 public class XMPPFaultHandler
14 extends AbstractHandler
15 {
16 public static final String XMPP_ERROR = "xfire.xmppError";
17
18 /***
19 * @param e
20 * @param context
21 * @throws Exception
22 */
23 public void invoke(MessageContext context)
24 {
25 /***
26 * From the JEP-0076 spec:
27 * _SOAP Error_ _HTTP Code_ _IQ Error Description_
28 * env:VersionMismatch 500 <internal-server-error/>
29 * env:MustUnderstand 500 <internal-server-error/>
30 * env:Sender 400 <bad-request/>
31 * env:Receiver 500 <internal-server-error/>
32 * env:DataEncodingUnknown 500 <internal-server-error/>
33 */
34
35 XFireFault fault = (XFireFault) context.getExchange().getFaultMessage().getBody();
36 XMPPError error = null;
37 if (fault.getFaultCode().equals(XFireFault.SENDER))
38 {
39 error = new XMPPError(400);
40 }
41 else
42 {
43 error = new XMPPError(500);
44 }
45
46 context.setProperty(XMPP_ERROR, error);
47 }
48 }