package org.jboss.net.axis.transport.mailto;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.activation.DataSource;
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.soap.SOAPConstants;
import org.apache.log4j.Logger;
public class SOAPDataSource implements DataSource
{
private Logger log = Logger.getLogger(getClass());
private Message soapMessage = null;
public SOAPDataSource(Message msg)
{
this.soapMessage = msg;
}
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream(this.soapMessage.getSOAPPartAsBytes());
}
public OutputStream getOutputStream() throws IOException
{
throw new IOException("getOutputStream() is not implemented in SOAP12DataSource.");
}
public String getContentType()
{
SOAPEnvelope envelope = null;
try
{
envelope = soapMessage.getSOAPEnvelope();
} catch (AxisFault e)
{
log.warn("Unable to get SOAPEnvelope from the SOAPMessage.", e);
}
boolean soap12 = (envelope != null && envelope.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS);
MessageContext mctx = this.soapMessage.getMessageContext();
SOAPConstants sc = mctx.getSOAPConstants();
String ct = "text/xml";
try
{
ct = soapMessage.getContentType(sc);
} catch (AxisFault e)
{
log.warn("Failed to determine content type from the SOAPMessage.", e);
ct = sc.getContentType();
}
if (soap12)
{
if (mctx.useSOAPAction())
{
ct += ct +"; action=\""+mctx.getSOAPActionURI()+"\"";
}
}
return ct;
}
public String getName()
{
return "SOAP Message";
}
}