KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > server > msgprocessors > FaultProcessor


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.sandesha.server.msgprocessors;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.Message;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.components.logger.LogFactory;
23 import org.apache.axis.message.SOAPEnvelope;
24 import org.apache.axis.message.SOAPFault;
25 import org.apache.axis.message.addressing.AddressingHeaders;
26 import org.apache.commons.logging.Log;
27 import org.apache.sandesha.Constants;
28 import org.apache.sandesha.IStorageManager;
29 import org.apache.sandesha.RMMessageContext;
30 import org.apache.sandesha.storage.dao.SandeshaQueueDAO;
31 import org.apache.sandesha.ws.rm.RMHeaders;
32
33 import javax.xml.namespace.QName JavaDoc;
34
35 /**
36  * This class is the message processor for the faults.
37  *
38  * @author Jaliy Ekanayake
39  */

40 public class FaultProcessor implements IRMMessageProcessor {
41     private IStorageManager storageManager;
42     private AxisFault axisFault;
43     private static final Log log = LogFactory.getLog(SandeshaQueueDAO.class.getName());
44
45     public FaultProcessor(IStorageManager storageManager) {
46         this.storageManager = storageManager;
47     }
48
49     public FaultProcessor(IStorageManager storageManager, AxisFault axisFault) {
50         this.storageManager = storageManager;
51         this.axisFault = axisFault;
52
53     }
54
55     public boolean processMessage(RMMessageContext rmMessageContext) throws AxisFault {
56         axisFault = new AxisFault(new QName JavaDoc(Constants.FaultCodes.IN_CORRECT_MESSAGE),
57                 Constants.FaultMessages.INVALID_MESSAGE, null, null);
58         try {
59             return sendFault(rmMessageContext);
60         } catch (Exception JavaDoc e) {
61             log.error(e);
62             return true;
63         }
64
65     }
66
67     public boolean sendFault(RMMessageContext rmMessageContext) throws Exception JavaDoc {
68
69         AddressingHeaders addrHeaders;
70         RMHeaders rmHeaders;
71         MessageContext msgContext = rmMessageContext.getMsgContext();
72
73         if (rmMessageContext.getRMHeaders() != null) {
74             rmHeaders = rmMessageContext.getRMHeaders();
75             String JavaDoc acksTo = getAcksTo(rmHeaders);
76             if (acksTo != null && acksTo.equals(Constants.WSA.NS_ADDRESSING_ANONYMOUS)) {
77                 return sendFaultSync(msgContext);
78             } else if (acksTo != null) {
79                 storageManager.insertFault(rmMessageContext);
80                 return false;
81             }
82         }
83
84         if (rmMessageContext.getAddressingHeaders() != null) {
85             addrHeaders = rmMessageContext.getAddressingHeaders();
86             if (addrHeaders.getFaultTo() != null) {
87                 if (addrHeaders.getFaultTo().getAddress().toString().equals(Constants.WSA.NS_ADDRESSING_ANONYMOUS)) {
88                     return sendFaultSync(msgContext);
89                 } else {
90                     storageManager.insertFault(rmMessageContext);
91                     return false;
92                 }
93             }
94         } else {
95             FaultProcessor.log.error(axisFault);
96             return sendFaultSync(msgContext);
97         }
98         return true;
99     }
100
101     private boolean sendFaultSync(MessageContext msgContext) throws Exception JavaDoc {
102         SOAPFault soapFault = new SOAPFault(axisFault);
103         SOAPEnvelope sEnv = new SOAPEnvelope();
104         sEnv.getBody().addChildElement(soapFault);
105         msgContext.setResponseMessage(new Message(sEnv));
106         return true;
107     }
108
109     private String JavaDoc getAcksTo(RMHeaders rmHeaders) {
110         if (rmHeaders.getSequence() != null)
111             return storageManager.getAcksTo(rmHeaders.getSequence().getIdentifier().getIdentifier());
112         else if (rmHeaders.getCreateSequence() != null)
113             return rmHeaders.getCreateSequence().getAcksTo().getAddress().toString();
114         else
115             return null;
116     }
117
118 }
Popular Tags