KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > axis > transport > mailto > SOAPDataSource


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  *
7  * Created on Dec 29, 2003
8  */

9 package org.jboss.net.axis.transport.mailto;
10
11 import java.io.ByteArrayInputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.InputStream JavaDoc;
14 import java.io.OutputStream JavaDoc;
15
16 import javax.activation.DataSource JavaDoc;
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 /**
27  * <dl>
28  * <dt><b>Title: </b><dd>SOAP 1.2 DataSource</dd>
29  * <p>
30  * <dt><b>Description: </b><dd>Datasource capable of handling SOAP 1.2 messages with the application/soap+xml
31  * content type.</dd>
32  * <p>
33  * </dl>
34  * @author <a HREF="mailto:jasone@greenrivercomputing.com">Jason Essington</a>
35  * @version $Revision: 1.1 $
36  */

37 public class SOAPDataSource implements DataSource JavaDoc
38 {
39    private Logger log = Logger.getLogger(getClass());
40    private Message soapMessage = null;
41
42    /**
43     * constructor to create a response message (one with no action parameter)
44     * @param msg soapMessage
45     */

46    public SOAPDataSource(Message msg)
47    {
48       this.soapMessage = msg;
49    }
50
51    /* (non-Javadoc)
52     * @see javax.activation.DataSource#getInputStream()
53     */

54    public InputStream JavaDoc getInputStream() throws IOException JavaDoc
55    {
56       /*
57        * This method will get the whole soap message, but this datasource is really only set up to handle the
58        * soap envelope sans attachments.
59        * TODO handle attachments
60        */

61       return new ByteArrayInputStream JavaDoc(this.soapMessage.getSOAPPartAsBytes());
62    }
63
64    /**
65     * NOT IMPLEMENTED!
66     */

67    public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc
68    {
69       throw new IOException JavaDoc("getOutputStream() is not implemented in SOAP12DataSource.");
70    }
71
72    /* (non-Javadoc)
73     * @see javax.activation.DataSource#getContentType()
74     */

75    public String JavaDoc 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 JavaDoc 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          // we need to add the action parameter to the content type for SOAP 1.2 requests
104
if (mctx.useSOAPAction())
105          {
106             ct += ct +"; action=\""+mctx.getSOAPActionURI()+"\"";
107          }
108       }
109       
110       return ct;
111    }
112
113    /* (non-Javadoc)
114     * @see javax.activation.DataSource#getName()
115     */

116    public String JavaDoc getName()
117    {
118       // TODO return something more intelligent here
119
return "SOAP Message";
120    }
121
122 }
123
Popular Tags