1 7 package org.jboss.net.axis.transport.mailto.server; 8 9 import javax.mail.Flags ; 10 import javax.mail.Message ; 11 import javax.mail.MessagingException ; 12 13 import org.apache.axis.AxisEngine; 14 import org.apache.axis.AxisFault; 15 import org.apache.axis.MessageContext; 16 import org.apache.axis.server.AxisServer; 17 import org.jboss.net.axis.server.JMXEngineConfigurationFactory; 18 import org.jboss.net.axis.transport.mailto.server.MailTransportServiceMBean; 19 import org.jboss.net.axis.transport.mailto.AbstractMailTransportService; 20 import org.jboss.net.axis.transport.mailto.MailConstants; 21 22 89 public class MailTransportService extends AbstractMailTransportService implements MailTransportServiceMBean, 90 MailConstants 91 { 92 93 95 private AxisServer server = null; 96 97 private String transportName = "mailto"; 98 99 106 public String getTransportName() 107 { 108 return this.transportName; 109 } 110 111 116 public void setTransportName(String name) 117 { 118 this.transportName = name; 119 } 120 121 126 public AxisServer getEngine() throws AxisFault 127 { 128 if (server == null) 129 { 130 try 131 { 132 server = JMXEngineConfigurationFactory.newJMXFactory(getEngineName()).getAxisServer(); 133 } 134 catch (NullPointerException e) 135 { 136 throw new AxisFault("Could not access JMX configuration factory.", e); 137 } 138 } 139 140 return server; 141 } 142 143 146 protected void processMessages(Message [] msgs) 147 { 148 for (int i = 0; i < msgs.length; i++) 150 { 151 processMessage(msgs[i]); 152 153 161 if (getDeleteMail()) 162 { 163 try 164 { 165 msgs[i].setFlag(Flags.Flag.DELETED, true); 166 } 167 catch (MessagingException e1) 168 { 169 log.warn("Unable to flag the message for deletion.", e1); 170 } 171 } 172 } 173 } 174 175 183 protected MessageContext createMessageContext(AxisEngine engine, Message msg) 184 throws AxisFault 185 { 186 MessageContext msgCtx = new MessageContext(engine); 187 188 msgCtx.setTransportName(transportName); 190 191 return msgCtx; 193 } 194 195 202 protected void processMessageBody(MessageContext mc, Message msg) throws AxisFault 203 { 204 String msgNS = null; 205 try 206 { 207 org.apache.axis.Message soapMsg = new org.apache.axis.Message(msg.getInputStream(), false, msg 208 .getContentType(), null); 209 210 mc.setRequestMessage(soapMsg); 211 } 212 catch (Exception e) 213 { 214 log.warn("This message doesn't appear to be a SOAP Message,", e); 215 } 216 } 217 218 223 protected String processHeaders(MessageContext ctx, Message msg) throws AxisFault 224 { 225 String msgID = null; 228 try 229 { 230 String [] msgIDs = msg.getHeader(HEADER_MESSAGE_ID); 231 if (msgIDs != null && msgIDs.length > 0) 232 { 233 msgID = msgIDs[0]; 234 } 235 } 236 catch (MessagingException e) 237 { 238 throw new AxisFault("Unable to process mail headers.", e); 239 } 240 return msgID; 241 } 242 243 248 private void processMessage(Message msg) 249 { 251 252 org.apache.axis.MessageContext sMsgCtx = null; 253 org.apache.axis.Message sResMsg = null; 254 255 try 256 { 257 sMsgCtx = createMessageContext(getEngine(), msg); 259 260 String msgID = processHeaders(sMsgCtx, msg); 262 263 processMessageBody(sMsgCtx, msg); 265 266 archiveMessage(msgID, sMsgCtx); 267 268 if (log.isDebugEnabled()) 270 log.debug("Invoking Axis Server."); 271 272 getEngine().invoke(sMsgCtx); 273 274 if (log.isDebugEnabled()) 275 log.debug("Return from Axis Server."); 276 277 } 278 catch (AxisFault e) 279 { 280 log.fatal("The email message number "+msg.getMessageNumber()+" caused an AxisFault:",e); 284 } 285 } 286 287 294 protected void archiveMessage(String msgID, MessageContext msgCtx) 295 { 296 } 297 298 } 299 | Popular Tags |