1 9 package org.jboss.net.axis.transport.mailto.client; 10 11 import org.apache.axis.AxisFault; 12 import org.apache.axis.MessageContext; 13 import org.apache.axis.message.addressing.AddressingHeaders; 14 import org.apache.axis.message.addressing.Constants; 15 import org.apache.axis.message.addressing.MessageID; 16 17 35 public class AsyncMailSender extends BaseMailSender 36 { 37 38 public static final String TIMEOUT = "Timeout"; 39 public static final long DEFAULT_TIMEOUT = 1800000; 41 protected long getTimeout() 42 { 43 long timeout = DEFAULT_TIMEOUT; 44 String to = (String ) getOption(TIMEOUT); 45 if (to != null) 46 { 47 try 48 { 49 timeout = Long.parseLong(to) * 60 * 1000; 50 } catch (NumberFormatException e) 51 { 52 log.warn(to + "is not a valid number we will use 30 minutes instead.", e); 54 } 55 } 56 return timeout; 57 } 58 59 private String getMessageID(MessageContext ctx) 60 { 61 String id = "no message-id"; 62 63 if (ctx.containsProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS)) 64 { 65 AddressingHeaders headers = (AddressingHeaders) ctx.getProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS); 66 MessageID msgid = headers.getMessageID(); 67 if (msgid != null) 68 { 69 id = msgid.toString(); 70 } 71 } 72 return id; 73 } 74 75 80 protected void checkResponse(MessageContext ctx) throws AxisFault 81 { 82 String id = getMessageID(ctx); 83 84 if (log.isDebugEnabled()) 85 log.debug("Entering: checkResponse [" + id + "]"); 86 87 try 88 { 89 Thread.sleep(getTimeout()); 91 92 if (log.isDebugEnabled()) 94 log.debug("This request " + id + " timed out."); 95 throw new AxisFault("Request Timed Out"); 96 } 97 catch (InterruptedException e) 98 { 99 if (log.isDebugEnabled()) 101 log.debug("The request " + id + " received a response."); 102 103 } 105 if (log.isDebugEnabled()) 106 log.debug("Leaving: checkResponse [" + id + "]"); 107 } 108 } 109 | Popular Tags |