1 16 package org.apache.axis2.saaj; 17 18 import org.apache.axis2.om.OMOutput; 19 import org.apache.axis2.transport.http.HTTPConstants; 20 21 import javax.xml.soap.*; 22 import javax.xml.stream.XMLOutputFactory; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.util.Iterator ; 26 27 33 public class SOAPMessageImpl extends SOAPMessage { 34 35 private SOAPPartImpl mSOAPPart; 36 private java.util.Hashtable mProps = new java.util.Hashtable (); 37 private MimeHeaders headers; 38 39 public SOAPMessageImpl(Object initialContents){ 40 try{ 41 setup(initialContents, false, null, null, null); 42 } catch(SOAPException e){ 43 e.printStackTrace(); 44 } 45 } 46 47 public SOAPMessageImpl(Object initialContents, boolean bodyInStream, javax.xml.soap.MimeHeaders headers) { 48 try{ 49 setup(initialContents, bodyInStream, null, null, (MimeHeaders)headers); 50 } catch(SOAPException e){ 51 e.printStackTrace(); 52 } 53 } 54 55 private void setup(Object initialContents, boolean bodyInStream, 56 String contentType, String contentLocation, 57 MimeHeaders mimeHeaders)throws SOAPException{ 58 if(null == mSOAPPart) 59 mSOAPPart = new SOAPPartImpl(this, initialContents, bodyInStream); 60 else 61 mSOAPPart.setMessage(this); 62 63 headers = (mimeHeaders == null) ? new MimeHeaders() : new MimeHeaders(mimeHeaders); 64 } 65 66 74 public String getContentDescription() { 75 String values[] = headers.getHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION); 76 if(values != null && values.length > 0) 77 return values[0]; 78 return null; 79 } 80 81 88 public void setContentDescription(String description) { 89 headers.setHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION, description); 90 } 91 92 95 public SOAPPart getSOAPPart() { 96 return mSOAPPart; 97 } 98 99 public SOAPBody getSOAPBody() throws SOAPException { 100 return mSOAPPart.getEnvelope().getBody(); 101 } 102 103 public SOAPHeader getSOAPHeader() throws SOAPException { 104 return mSOAPPart.getEnvelope().getHeader(); 105 } 106 107 public void setProperty(String property, Object value) throws SOAPException { 108 mProps.put(property, value); 109 } 110 111 public Object getProperty(String property) throws SOAPException { 112 return mProps.get(property); 113 } 114 115 118 public void removeAllAttachments() { 119 121 } 122 123 126 public int countAttachments() { 127 return 0; 129 } 130 131 134 public Iterator getAttachments() { 135 return null; 137 } 138 139 142 public Iterator getAttachments(javax.xml.soap.MimeHeaders headers) { 143 return null; 145 } 146 147 150 public void addAttachmentPart(AttachmentPart attachmentpart) { 151 153 } 154 155 158 public AttachmentPart createAttachmentPart() { 159 return null; 161 } 162 163 166 public javax.xml.soap.MimeHeaders getMimeHeaders() { 167 168 return headers; 169 } 170 171 174 public void saveChanges() throws SOAPException { 175 177 } 178 179 182 public boolean saveRequired() { 183 return false; 185 } 186 187 190 public void writeTo(OutputStream out) throws SOAPException, IOException { 191 try{ 192 OMOutput omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(out)); 193 ((SOAPEnvelopeImpl)mSOAPPart.getEnvelope()).getOMEnvelope().serialize(omOutput); 194 omOutput.flush(); 195 } catch(Exception e){ 196 throw new SOAPException(e); 197 } 198 } 199 200 } 201 | Popular Tags |