1 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 ; 34 35 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 (Constants.FaultCodes.IN_CORRECT_MESSAGE), 57 Constants.FaultMessages.INVALID_MESSAGE, null, null); 58 try { 59 return sendFault(rmMessageContext); 60 } catch (Exception e) { 61 log.error(e); 62 return true; 63 } 64 65 } 66 67 public boolean sendFault(RMMessageContext rmMessageContext) throws Exception { 68 69 AddressingHeaders addrHeaders; 70 RMHeaders rmHeaders; 71 MessageContext msgContext = rmMessageContext.getMsgContext(); 72 73 if (rmMessageContext.getRMHeaders() != null) { 74 rmHeaders = rmMessageContext.getRMHeaders(); 75 String 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 { 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 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 |