1 9 package org.jboss.net.axis.transport.mailto; 10 11 import java.io.ByteArrayInputStream ; 12 import java.io.IOException ; 13 import java.io.InputStream ; 14 import java.io.OutputStream ; 15 16 import javax.activation.DataSource ; 17 18 import org.apache.axis.AxisFault; 19 import org.apache.axis.Message; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.message.SOAPEnvelope; 22 import org.apache.axis.soap.SOAPConstants; 23 import org.apache.log4j.Logger; 24 25 26 37 public class SOAPDataSource implements DataSource 38 { 39 private Logger log = Logger.getLogger(getClass()); 40 private Message soapMessage = null; 41 42 46 public SOAPDataSource(Message msg) 47 { 48 this.soapMessage = msg; 49 } 50 51 54 public InputStream getInputStream() throws IOException 55 { 56 61 return new ByteArrayInputStream (this.soapMessage.getSOAPPartAsBytes()); 62 } 63 64 67 public OutputStream getOutputStream() throws IOException 68 { 69 throw new IOException ("getOutputStream() is not implemented in SOAP12DataSource."); 70 } 71 72 75 public String getContentType() 76 { 77 SOAPEnvelope envelope = null; 78 try 79 { 80 envelope = soapMessage.getSOAPEnvelope(); 81 } catch (AxisFault e) 82 { 83 log.warn("Unable to get SOAPEnvelope from the SOAPMessage.", e); 84 } 85 86 boolean soap12 = (envelope != null && envelope.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS); 87 88 MessageContext mctx = this.soapMessage.getMessageContext(); 89 SOAPConstants sc = mctx.getSOAPConstants(); 90 91 String ct = "text/xml"; 92 try 93 { 94 ct = soapMessage.getContentType(sc); 95 } catch (AxisFault e) 96 { 97 log.warn("Failed to determine content type from the SOAPMessage.", e); 98 ct = sc.getContentType(); 99 } 100 101 if (soap12) 102 { 103 if (mctx.useSOAPAction()) 105 { 106 ct += ct +"; action=\""+mctx.getSOAPActionURI()+"\""; 107 } 108 } 109 110 return ct; 111 } 112 113 116 public String getName() 117 { 118 return "SOAP Message"; 120 } 121 122 } 123 | Popular Tags |