You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Bill Nagy <na...@watson.ibm.com> on 2007/02/05 15:58:43 UTC
[Axis2] Re: svn commit: r503658 [1/2] - in
/webservices/axis2/trunk/java/modules/saaj: src/org/apache/axis2/saaj/
test-resources/ test/org/apache/axis2/saaj/
test/org/apache/axis2/saaj/integration/
Please include the JIRA issue in your commit message at the very least,
or, even better -- make the comment more informative. "Applying patches
for SAAJ sent by Sumedha" is not very helpful. Thanks.
-Bill
On Mon, 2007-02-05 at 12:14 +0000, azeez@apache.org wrote:
> Author: azeez
> Date: Mon Feb 5 04:14:07 2007
> New Revision: 503658
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=503658
> Log:
> Applying patches for SAAJ sent by Sumedha
>
> Added:
> webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml (with props)
> Modified:
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/MessageFactoryImpl.java
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
> webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/MessageFactoryTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/PrefixesTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJDetailTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPBodyTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPConnectionTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFactoryTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPHeaderTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPMessageTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPPartTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/TextTest.java
> webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/integration/IntegrationTest.java
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java Mon Feb 5 04:14:07 2007
> @@ -16,6 +16,7 @@
> package org.apache.axis2.saaj;
>
> import java.awt.image.BufferedImage;
> +import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> @@ -163,22 +164,22 @@
> }
> try {
> String contentType = dataHandler.getContentType();
> - //TODO change to text/xml
> - if(contentType.equals("text/xml")){
> - StringReader stringReader = new StringReader((String)dataHandler.getContent());
> + if (contentType.equals("text/xml")) {
> + StringReader stringReader = new StringReader((String)dataHandler.getContent());
> StreamSource streamSource = new StreamSource(stringReader);
> + streamSource.setInputStream(dataHandler.getInputStream());
> return streamSource;
> - }else if (contentType.equals("text/plain") ||
> - contentType.equals("text/html")) {
> -
> +
> //For these content types underlying DataContentHandler surely does
> //the conversion to appropriate java object and we will return that java object
> - return dataHandler.getContent();
> - } else {
> + //return dataHandler.getContent();
> + }else if(contentType.equals("text/plain") ||
> + contentType.equals("text/html")){
> + return (String)dataHandler.getContent();
> + }else {
> try {
> return dataHandler.getContent();
> } catch (UnsupportedDataTypeException e) {
> -
> //If the underlying DataContentHandler can't handle the object contents,
> //we will return an inputstream of raw bytes represneting the content data
> return dataHandler.getDataSource().getInputStream();
> @@ -256,15 +257,21 @@
> throw new java.lang.IllegalArgumentException(e);
> }
> }
> - /*
> else if (object instanceof byte[]) {
> try {
> - dataHandler = new DataHandler();
> - contentObject = null; // the stream has been consumed
> + contentObject = null;
> + java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream((byte[])object);
> + source = new SAAJDataSource(bais,
> + SAAJDataSource.MAX_MEMORY_DISK_CACHED,
> + contentType, true);
> + extractFilename(source);
> +
> + dataHandler = new DataHandler(source);
> + contentObject = object;
> } catch (Exception e) {
> throw new java.lang.IllegalArgumentException(e);
> }
> - }*/
> + }
> else {
> throw new java.lang.IllegalArgumentException("Illegal Argument");
> }
> @@ -280,9 +287,9 @@
> * no data in this <CODE>AttachmentPart</CODE> object
> */
> public DataHandler getDataHandler() throws SOAPException {
> -// if (getContent() == null) {
> -// throw new SOAPException("No Content present in the Attachment part");
> -// }
> + //if (getContent() == null) {
> + // throw new SOAPException("No Content present in the Attachment part");
> + //}
> //commented to fix AXIS2-778
> if (dataHandler == null) {
> throw new SOAPException("No Content present in the Attachment part");
> @@ -571,11 +578,11 @@
> */
>
> public void setRawContentBytes(byte[] content, int offset, int len, String contentType) throws SOAPException {
> - //TODO - complete
> + //TODO - how to use offset & len?
> if(content == null){
> throw new SOAPException("Content is null");
> }
> -
> + setContent(content, contentType);
> }
>
> /**
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/MessageFactoryImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/MessageFactoryImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/MessageFactoryImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/MessageFactoryImpl.java Mon Feb 5 04:14:07 2007
> @@ -17,6 +17,7 @@
>
> import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
> import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
> +import org.apache.axis2.saaj.util.IDGenerator;
>
> import javax.xml.soap.MessageFactory;
> import javax.xml.soap.MimeHeaders;
> @@ -166,13 +167,6 @@
> */
> public SOAPMessage createMessage(MimeHeaders mimeheaders,
> InputStream inputstream) throws IOException, SOAPException {
> -
> - /*System.err.println("@@@@@@@@@@ MessageFactoryImpl#createMessage");
> - byte[] b = new byte[10240];
> - inputstream.read(b);
> - System.err.println("byte=" + new String(b));
> - System.err.println("@@@@@@@@@@ END MessageFactoryImpl#createMessage");*/
> -
> SOAPMessageImpl soapMessage = new SOAPMessageImpl(inputstream, mimeheaders);
> soapMessage.setSaveRequired();
> return soapMessage;
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java Mon Feb 5 04:14:07 2007
> @@ -19,9 +19,11 @@
> import java.io.InputStream;
> import java.net.MalformedURLException;
> import java.net.URL;
> +import java.util.Collection;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Map;
> +import java.util.Set;
>
> import javax.activation.DataHandler;
> import javax.xml.namespace.QName;
> @@ -66,6 +68,7 @@
> private boolean closed = false;
>
> private ServiceClient serviceClient;
> + private HashMap unaccessedAttachments = new HashMap();
>
> private static final Log log = LogFactory.getLog(SOAPConnectionImpl.class);
>
> @@ -154,7 +157,6 @@
>
> MessageContext msgCtx = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
> //TODO: get attachments
> -
> return getSOAPMessage(msgCtx.getEnvelope());
> } catch (AxisFault e) {
> throw new SOAPException(e);
> @@ -212,6 +214,15 @@
>
> // Convert the body
> toSAAJElement(body, respOMSoapEnv.getBody(), response);
> + //if there are unrefferenced attachments, add that to response
> + if(!unaccessedAttachments.isEmpty()){
> + Collection attachments = unaccessedAttachments.values();
> + Iterator attachementsIterator = attachments.iterator();
> + while (attachementsIterator.hasNext()) {
> + AttachmentPart attachment = (AttachmentPart) attachementsIterator.next();
> + response.addAttachmentPart(attachment);
> + }
> + }
>
> return response;
> }
> @@ -297,7 +308,7 @@
> Map attachmentMap = new HashMap();
> final Iterator attachments = saajSOAPMsg.getAttachments();
> while (attachments.hasNext()) {
> - final AttachmentPart attachment = (AttachmentPart) attachments.next();
> + final AttachmentPart attachment = (AttachmentPart) attachments.next();
> if (attachment.getContentId() == null ||
> attachment.getContentId().trim().length() == 0) {
> attachment.setContentId(IDGenerator.generateID());
> @@ -308,9 +319,20 @@
> attachmentMap.put(attachment.getContentId(), attachment);
> }
>
> - insertAttachmentNodes(attachmentMap, omSOAPEnv);
> -
> -// printOMSOAPEnvelope(omSOAPEnv);
> + //Get keys of attachments to a hashmap
> + //This hashmap will be updated when attachment is accessed atleast once.
> + //Doing this here instead of inside insertAttachmentNodes()is much simpler
> + //as insertAttachmentNodes() has recursive calls
> + Set keySet = attachmentMap.keySet();
> + Iterator keySetItr = keySet.iterator();
> + HashMap keyAccessStatus = new HashMap();
> + while(keySetItr.hasNext()){
> + String key = (String)keySetItr.next();
> + keyAccessStatus.put(key,"not-accessed");
> + }
> +
> + insertAttachmentNodes(attachmentMap, omSOAPEnv,keyAccessStatus);
> + unaccessedAttachments = getUnReferencedAttachmentNodes(attachmentMap, omSOAPEnv,keyAccessStatus);
>
> return omSOAPEnv;
> }
> @@ -323,7 +345,7 @@
> * @throws SOAPException
> */
> private void insertAttachmentNodes(Map attachments,
> - OMElement omEnvelope) throws SOAPException {
> + OMElement omEnvelope,HashMap keyAccessStatus) throws SOAPException {
>
> Iterator childIter = omEnvelope.getChildElements();
> while (childIter.hasNext()) {
> @@ -334,21 +356,42 @@
> if (contentID != null) {//This is an omEnvelope referencing an attachment
> child.build();
> AttachmentPart ap = ((AttachmentPart) attachments.get(contentID.trim()));
> + //update the key status as accessed
> + keyAccessStatus.put(contentID.trim(), "accessed");
> OMText text = new OMTextImpl(ap.getDataHandler(), true,
> omEnvelope.getOMFactory());
> child.removeAttribute(hrefAttr);
> child.addChild(text);
> } else {
> -
> //possibly there can be references in the children of this omEnvelope
> //so recurse through.
> - insertAttachmentNodes(attachments, child);
> + insertAttachmentNodes(attachments, child,keyAccessStatus);
> }
> }
> -
> - //TODO: Need to handle no referenced attachments
> }
> -
> +
> +
> + private HashMap getUnReferencedAttachmentNodes(Map attachments,
> + OMElement omEnvelope,HashMap keyAccessStatus) throws SOAPException {
> +
> + HashMap unaccessedAttachments = new HashMap();
> + //now check for unaccessed keys
> + Set keySet = keyAccessStatus.keySet();
> + Iterator keySetItr = keySet.iterator();
> + while(keySetItr.hasNext()){
> + String key = (String)keySetItr.next();
> + String keyStatus = (String)keyAccessStatus.get(key);
> + if("not-accessed".equals(keyStatus)){
> + //The value for this key has not been accessed in the
> + //referencing attachment scenario.Hence it must be an
> + //unreferenced one.
> + AttachmentPart ap = ((AttachmentPart) attachments.get(key));
> + unaccessedAttachments.put(key, ap);
> + keyAccessStatus.put(key, "accessed");
> + }
> + }
> + return unaccessedAttachments;
> + }
> /**
> * This method checks the value of attribute and if it is a valid CID then
> * returns the contentID (with cid: prefix stripped off) or else returns null.
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java Mon Feb 5 04:14:07 2007
> @@ -41,6 +41,7 @@
> import org.apache.axiom.soap.SOAPFactory;
> import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
> import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
> +import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
> import org.apache.axiom.soap.impl.dom.soap12.SOAP12HeaderBlockImpl;
> import org.w3c.dom.Attr;
> import org.w3c.dom.DOMException;
> @@ -528,17 +529,29 @@
> return element.removeNamespace(prefix);
> }
>
> - /* (non-Javadoc)
> - * @see javax.xml.soap.SOAPElement#setEncodingStyle(java.lang.String)
> - */
> -
> - //TODO : jira issue
> +
> + /**
> + * Sets the encoding style for this SOAPElement object to one specified.
> + *
> + * @param encodingStyle - a String giving the encoding style
> + * @throws java.lang.IllegalArgumentException - if there was a problem in the encoding
> + * style being set.
> + * SOAPException - if setting the encodingStyle is invalid for this SOAPElement.
> + */
> public void setEncodingStyle(String encodingStyle) throws SOAPException {
> - //TODO : is this check correct?
> - //if (!encodingStyle.equals(SOAPConstants.URI_NS_SOAP_ENCODING)) {
> - // throw new IllegalArgumentException("Invalid Encoding style : " + encodingStyle);
> - //}
> - ((DocumentImpl) getOwnerDocument()).setCharsetEncoding(encodingStyle);
> + if(this.element.getOMFactory() instanceof SOAP11Factory){
> + if (!encodingStyle.equals(SOAPConstants.URI_NS_SOAP_ENCODING)) {
> + throw new IllegalArgumentException("Invalid Encoding style : " + encodingStyle);
> + }else{
> + ((DocumentImpl) getOwnerDocument()).setCharsetEncoding(encodingStyle);
> + }
> + }else if(this.element.getOMFactory() instanceof SOAP12Factory){
> + if(SOAPConstants.URI_NS_SOAP_1_2_ENCODING.equals(encodingStyle)){
> + throw new SOAPException("Illegal value : "+SOAPConstants.URI_NS_SOAP_1_2_ENCODING);
> + }else{
> + ((DocumentImpl) getOwnerDocument()).setCharsetEncoding(encodingStyle);
> + }
> + }
> }
>
> /* (non-Javadoc)
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java Mon Feb 5 04:14:07 2007
> @@ -54,30 +54,29 @@
> }
>
> setCharsetEncoding(contentType);
> -
> soapPart = new SOAPPartImpl(this, soapEnvelope);
> -
> this.mimeHeaders = new MimeHeadersEx();
> }
>
> - public SOAPMessageImpl(InputStream inputstream,
> - javax.xml.soap.MimeHeaders mimeHeaders) throws SOAPException {
> - String contentType = null;
> - if (mimeHeaders != null) {
> - String contentTypes[] = mimeHeaders.getHeader("Content-Type");
> - contentType = (contentTypes != null) ? contentTypes[0] : null;
> - }
> -
> - setCharsetEncoding(contentType);
> - if (contentType != null && contentType.indexOf("multipart/related;") == 0) {
> -// soapPart = new SOAPPartImpl(this, inputstream, mimeHeaders);
> - } else {
> - soapPart = new SOAPPartImpl(this, inputstream);
> - }
> -
> - this.mimeHeaders = (mimeHeaders == null) ?
> - new MimeHeadersEx() :
> - new MimeHeadersEx(mimeHeaders);
> + public SOAPMessageImpl(InputStream inputstream,javax.xml.soap.MimeHeaders mimeHeaders)
> + throws SOAPException
> + {
> + String contentType = null;
> + if (mimeHeaders != null) {
> + String contentTypes[] = mimeHeaders.getHeader("Content-Type");
> + contentType = (contentTypes != null) ? contentTypes[0] : null;
> + }
> +
> + setCharsetEncoding(contentType);
> + if (contentType != null && contentType.indexOf("multipart/related;") == 0) {
> + soapPart = new SOAPPartImpl(this, inputstream, mimeHeaders);
> + } else {
> + soapPart = new SOAPPartImpl(this, inputstream);
> + }
> +
> + this.mimeHeaders = (mimeHeaders == null) ?
> + new MimeHeadersEx() :
> + new MimeHeadersEx(mimeHeaders);
> }
>
> /**
> @@ -372,19 +371,45 @@
> *
> */
> public AttachmentPart getAttachment(SOAPElement soapelement) throws SOAPException {
> -
> - Collection matchingAttachmentParts = new ArrayList();
> + //TODO read strings from constants
> Iterator iterator = getAttachments();
> {
> - AttachmentPartImpl part;
> + AttachmentPartImpl attachmentPart;
> while (iterator.hasNext()) {
> - part = (AttachmentPartImpl) iterator.next();
> - if (part.matches(null)) {
> - matchingAttachmentParts.add(part);
> - }
> + attachmentPart = (AttachmentPartImpl) iterator.next();
> + String[] contentIds = attachmentPart.getMimeHeader("Content-Id");
> +
> + //References can be made via an href attribute as described in SOAP Messages with Attachments
> + //or via a single Text child node containing a URI
> + String reference = soapelement.getAttribute("href");
> + if(reference == null || reference.trim().length() == 0){
> + reference = soapelement.getValue();
> + if(reference == null || reference.trim().length() == 0){
> + return null;
> + }
> + }
> +
> + for (int a = 0; a < contentIds.length; a++) {
> + //eg: cid:gifImage scenario
> + String idPart = reference.substring(reference.indexOf(":")+1);
> + idPart = "<"+idPart+">";
> + if(idPart.equals(contentIds[a])){
> + return attachmentPart;
> + }
> + }
> +
> + String[] contentLocations = attachmentPart.getMimeHeader("Content-Location");
> + if(!(contentLocations == null)){
> + //uri scenario
> + for (int b = 0; b < contentLocations.length; b++) {
> + if(reference.equals(contentLocations[b])){
> + return attachmentPart;
> + }
> + }
> + }
> }
> }
> - return null; //TODO - Not yet implemented
> + return null;
> }
>
> /**
> @@ -395,8 +420,6 @@
> * @since SAAJ 1.3
> */
> public void removeAttachments(MimeHeaders headers) {
> - //TODO - check
> -
> Collection newAttachmentParts = new ArrayList();
> Iterator attachmentPartsItr = attachmentParts.iterator();
> for (Iterator iter = attachmentPartsItr; iter.hasNext();) {
>
> Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPPartImpl.java Mon Feb 5 04:14:07 2007
> @@ -15,21 +15,34 @@
> */
> package org.apache.axis2.saaj;
>
> +import java.io.ByteArrayInputStream;
> +import java.io.ByteArrayOutputStream;
> import java.io.InputStream;
> import java.io.InputStreamReader;
> import java.util.Iterator;
>
> +import javax.xml.soap.MimeHeader;
> +import javax.xml.soap.MimeHeaders;
> import javax.xml.soap.SOAPElement;
> import javax.xml.soap.SOAPEnvelope;
> import javax.xml.soap.SOAPException;
> import javax.xml.soap.SOAPMessage;
> import javax.xml.soap.SOAPPart;
> +import javax.xml.stream.XMLInputFactory;
> import javax.xml.stream.XMLStreamException;
> +import javax.xml.stream.XMLStreamReader;
> +import javax.xml.transform.Result;
> import javax.xml.transform.Source;
> +import javax.xml.transform.Transformer;
> +import javax.xml.transform.TransformerFactory;
> +import javax.xml.transform.dom.DOMSource;
> +import javax.xml.transform.stream.StreamResult;
>
> +import org.apache.axiom.attachments.Attachments;
> import org.apache.axiom.om.util.StAXUtils;
> import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
> import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
> +import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
> import org.apache.axis2.saaj.util.IDGenerator;
> import org.apache.axis2.transport.http.HTTPConstants;
> import org.w3c.dom.Attr;
> @@ -71,15 +84,41 @@
> }
>
> public SOAPPartImpl(SOAPMessageImpl parentSoapMsg,
> - InputStream inputStream) throws SOAPException {
> -
> - setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, IDGenerator.generateID());
> - setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, "text/xml");
> -
> + InputStream inputStream,javax.xml.soap.MimeHeaders mimeHeaders
> + ) throws SOAPException {
> + boolean mimeHeaderSet = true;
> + if(mimeHeaders == null){
> + mimeHeaderSet = false;
> + mimeHeaders = new MimeHeaders();
> + mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
> + mimeHeaders.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, "text/xml");
> + }
> +
> + Iterator mimeHeaderIterator = mimeHeaders.getAllHeaders();
> + String contentType = "";
> + while (mimeHeaderIterator.hasNext()) {
> + MimeHeader mimeHeader = (MimeHeader) mimeHeaderIterator.next();
> + String value = mimeHeader.getValue();
> + if("content-type".equals(mimeHeader.getName())){
> + contentType = value;
> + }
> + setMimeHeader(mimeHeader.getName(), value);
> + }
> + InputStream modifiedInputStream = null;
> + if(mimeHeaderSet){
> + try {
> + Attachments attachments = new Attachments(inputStream, contentType,false, "","");
> + modifiedInputStream = attachments.getSOAPPartInputStream();
> + } catch (Exception e) {
> + throw new SOAPException(e);
> + }
> + }else{
> + modifiedInputStream = inputStream;
> + }
> soapMessage = parentSoapMsg;
>
> try {
> - InputStreamReader isReader = new InputStreamReader(inputStream);
> + InputStreamReader isReader = new InputStreamReader(modifiedInputStream);
> StAXSOAPModelBuilder builder =
> new StAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(isReader),
> new SOAP11Factory(),
> @@ -88,12 +127,19 @@
> envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl)soapEnvelope);
> envelope.element.build();
> this.document = envelope.getOwnerDocument();
> + javax.xml.transform.Source xmlSource =
> + new javax.xml.transform.stream.StreamSource(isReader);
> + this.source = xmlSource;
> } catch (XMLStreamException e) {
> - e.printStackTrace();
> throw new SOAPException(e);
> }
> }
>
> +
> + public SOAPPartImpl(SOAPMessageImpl parentSoapMsg,
> + InputStream inputStream) throws SOAPException {
> + this(parentSoapMsg,inputStream,null);
> + }
> /**
> * Obtain the SOAPMessage
> *
> @@ -256,7 +302,31 @@
> */
> public void setContent(Source source) throws SOAPException {
> this.source = source;
> - //TODO: Need to fix the source handling stuff
> + try {
> + ByteArrayOutputStream baos = new ByteArrayOutputStream();
> + Result result = new StreamResult(baos);
> +
> + Transformer xformer = TransformerFactory.newInstance().newTransformer();
> + xformer.transform(source, result);
> + ByteArrayInputStream is = new ByteArrayInputStream(baos.toByteArray());
> +
> + XMLInputFactory inputFactory = XMLInputFactory.newInstance();
> + XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
> +
> + StAXSOAPModelBuilder builder1 = null;
> + if(this.envelope.element.getOMFactory() instanceof SOAP11Factory){
> + builder1 = new StAXSOAPModelBuilder(reader,(SOAP11Factory)this.envelope.element.getOMFactory(),null);
> + }else if(this.envelope.element.getOMFactory() instanceof SOAP12Factory){
> + builder1 = new StAXSOAPModelBuilder(reader,(SOAP12Factory)this.envelope.element.getOMFactory(),null);
> + }
> +
> + org.apache.axiom.soap.SOAPEnvelope soapEnvelope = builder1.getSOAPEnvelope();
> + envelope = new SOAPEnvelopeImpl((org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl)soapEnvelope);
> + envelope.element.build();
> + this.document = envelope.getOwnerDocument();
> + } catch (Exception e) {
> + throw new SOAPException(e);
> + }
> }
>
> /**
> @@ -270,6 +340,8 @@
> * @see #setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)
> */
> public Source getContent() throws SOAPException {
> + DOMSource domSource = new DOMSource(this.document);
> + this.source = domSource;
> return source;
> }
>
>
> Added: webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml?view=auto&rev=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml (added)
> +++ webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml Mon Feb 5 04:14:07 2007
> @@ -0,0 +1,15 @@
> +<?xml version='1.0' encoding='utf-8'?>
> +<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
> +<soapenv:Header>
> +<ns-prefix:Header1 xmlns:ns-prefix="ns-uri" soapenv:mustUnderstand="1">This is Header1</ns-prefix:Header1>
> +<ns-prefix:Header2 xmlns:ns-prefix="ns-uri" soapenv:mustUnderstand="0">This is Header2</ns-prefix:Header2>
> +<ns-prefix:Header3 xmlns:ns-prefix="ns-uri" soapenv:mustUnderstand="1">This is Header3</ns-prefix:Header3>
> +<ns-prefix:Header4 xmlns:ns-prefix="ns-uri" soapenv:mustUnderstand="0">This is Header4</ns-prefix:Header4>
> +</soapenv:Header>
> +<soapenv:Body>
> +<ns-prefix:Body1 xmlns:ns-prefix="ns-uri">
> +<ns-prefix:Child1>This is Child1</ns-prefix:Child1>
> +<ns-prefix:Child2>This is Child2</ns-prefix:Child2>
> +</ns-prefix:Body1>
> +</soapenv:Body>
> +</soapenv:Envelope>
> \ No newline at end of file
>
> Propchange: webservices/axis2/trunk/java/modules/saaj/test-resources/soap-part3.xml
> ------------------------------------------------------------------------------
> svn:executable = *
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/AttachmentTest.java Mon Feb 5 04:14:07 2007
> @@ -5,7 +5,6 @@
> import java.io.ByteArrayOutputStream;
> import java.io.File;
> import java.io.FileInputStream;
> -import java.io.FileNotFoundException;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> @@ -27,306 +26,314 @@
>
> public class AttachmentTest extends TestCase {
>
> - public AttachmentTest(String name) {
> - super(name);
> - }
> -
> - public void testStringAttachment() throws Exception {
> -
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage message = factory.createMessage();
> - AttachmentPart attachment = message.createAttachmentPart();
> - String stringContent = "Update address for Sunny Skies " +
> - "Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
> -
> - attachment.setContent(stringContent, "text/plain");
> - attachment.setContentId("update_address");
> - message.addAttachmentPart(attachment);
> -
> - assertTrue(message.countAttachments() == 1);
> -
> - java.util.Iterator it = message.getAttachments();
> - while (it.hasNext()) {
> - attachment = (AttachmentPart) it.next();
> - Object content = attachment.getContent();
> - String id = attachment.getContentId();
> - System.out.println("Attachment " + id + " contains: " + content);
> - assertEquals(content, stringContent);
> - }
> - System.out.println("Here is what the XML message looks like:");
> - message.writeTo(System.out);
> -
> - message.removeAllAttachments();
> - assertTrue(message.countAttachments() == 0);
> - }
> -
> - public void testMultipleAttachments() throws Exception {
> -
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage msg = factory.createMessage();
> - java.net.URL url1 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.html");
> - java.net.URL url2 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.txt");
> -
> - AttachmentPart a1 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> - a1.setContentType("text/xml");
> - msg.addAttachmentPart(a1);
> - AttachmentPart a2 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> - a2.setContentType("text/xml");
> - msg.addAttachmentPart(a2);
> - AttachmentPart a3 = msg.createAttachmentPart(new javax.activation.DataHandler(url2));
> - a3.setContentType("text/plain");
> - msg.addAttachmentPart(a3);
> -
> - assertTrue(msg.countAttachments() == 3);
> -
> - javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
> - mimeHeaders.addHeader("Content-Type", "text/xml");
> -
> - int nAttachments = 0;
> - java.util.Iterator iterator = msg.getAttachments(mimeHeaders);
> - while (iterator.hasNext()) {
> - nAttachments++;
> - AttachmentPart ap = (AttachmentPart) iterator.next();
> - assertTrue(ap.equals(a1) || ap.equals(a2));
> - }
> - assertTrue(nAttachments == 2);
> - }
> -
> - public void _testAttachment() {
> - try {
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage msg = factory.createMessage();
> -
> - AttachmentPart ap = msg.createAttachmentPart();
> - File f = new File("test-resources" + File.separator + "axis2.xml");
> - InputStream in = new FileInputStream("test-resources" + File.separator + "axis2.jpg");
> - ap.setContent(new StreamSource(in), "text/xml");
> -
> - assertTrue(ap.getSize() <= 0);
> - } catch (SOAPException e) {
> - e.printStackTrace();
> - fail("Unexpected Exception : " + e);
> - } catch (FileNotFoundException e) {
> - e.printStackTrace();
> - fail("Unexpected Exception : " + e);
> - }
> - }
> -
> - public void testBadAttSize() throws Exception {
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage message = factory.createMessage();
> -
> - ByteArrayInputStream ins = new ByteArrayInputStream(new byte[5]);
> - DataHandler dh = new DataHandler(new Src(ins, "text/plain"));
> - AttachmentPart part = message.createAttachmentPart(dh);
> - assertEquals("Size should match", 5, part.getSize());
> - }
> -
> - class Src implements DataSource {
> - InputStream m_src;
> - String m_type;
> -
> - public Src(InputStream data, String type) {
> - m_src = data;
> - m_type = type;
> - }
> -
> - public String getContentType() {
> - return m_type;
> - }
> -
> - public InputStream getInputStream() throws IOException {
> - m_src.reset();
> - return m_src;
> - }
> -
> - public String getName() {
> - return "Some-Data";
> - }
> -
> - public OutputStream getOutputStream() {
> - throw new UnsupportedOperationException("I don't give output streams");
> - }
> - }
> -
> - public void testClearContent() throws Exception {
> - try {
> - InputStream in1 = new FileInputStream(new File("test-resources" + File.separator + "attach.xml"));
> -
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage message = factory.createMessage();
> - AttachmentPart ap = message.createAttachmentPart();
> - MimeHeader mh = null;
> -
> - System.out.println("Setting Mime Header ");
> - ap.setMimeHeader("Content-Description","some text");
> -
> - System.out.println("Setting Content Id Header ");
> - ap.setContentId("id@abc.com");
> -
> - System.out.println("Setting Content ");
> - ap.setContent( new StreamSource(in1),"text/xml");
> -
> - System.out.println("Clearing Content ");
> - ap.clearContent();
> -
> - try {
> -
> - System.out.println("Getting Content ");
> - InputStream is = (InputStream)ap.getContent();
> -
> - System.out.println("Error: SOAPException should have been thrown");
> - } catch(SOAPException e) {
> - System.out.println("Error thrown.(expected)");
> - }
> -
> - Iterator iterator = ap.getAllMimeHeaders();
> - int cnt=0;
> - boolean foundHeader1=false;
> - boolean foundHeader2=false;
> - boolean foundDefaultHeader=false;
> - while (iterator.hasNext()) {
> - cnt++;
> - mh = (MimeHeader)iterator.next();
> - String name=mh.getName();
> - String value=mh.getValue();
> - if (name.equals("Content-Description") && value.equals("some text")){
> - if (!foundHeader1){
> - foundHeader1=true;
> - System.out.println("MimeHeaders do match for header1");
> - System.out.println("receive: name="+name+", value="+value);
> - }
> - else {
> - System.out.println("Error: Received the same header1 header twice");
> - System.out.println("received: name="+name+", value="+value);
> - }
> - } else if (name.equals("Content-Id") && value.equals("id@abc.com")){
> - //TODO Content-Id or Content-ID??
> - if (!foundHeader2){
> - foundHeader2=true;
> - System.out.println("MimeHeaders do match for header2");
> - System.out.println("receive: name="+name+", value="+value);
> - }
> - else {
> - System.out.println("Error: Received the same header2 header twice");
> - System.out.println("received: name="+name+", value="+value);
> - }
> - } else if (name.equals("Content-Type") && value.equals("text/xml")){
> - if (!foundDefaultHeader){
> - foundDefaultHeader=true;
> - System.out.println("MimeHeaders do match for default header");
> - System.out.println("receive: name="+name+", value="+value);
> - }
> - else {
> - System.out.println("Error: Received the same default header header twice");
> - System.out.println("received: name="+name+", value="+value);
> - }
> - } else {
> - System.out.println("Error: Received an invalid header");
> - System.out.println("received: name="+name+", value="+value);
> - }
> - }
> -
> - if (!(foundHeader1 && foundHeader2)){
> - System.out.println("Error: did not receive both headers");
> - }
> -
> - } catch(Exception e) {
> - System.out.println("Exception: " + e);
> - }
> -
> - }
> -
> -
> -
> - public void testGetContent() throws Exception
> - {
> - try
> - {
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage msg = factory.createMessage();
> - AttachmentPart ap = msg.createAttachmentPart();
> - Image image = javax.imageio.ImageIO.read(new File("test-resources" + File.separator + "attach.gif"));
> - ap = msg.createAttachmentPart(image, "image/gif");
> -
> - System.out.println("Getting Content should return an Image object");
> - Object o = ap.getContent();
> - System.out.println("object returned="+o);
> - if(o != null) {
> - if(o instanceof Image)
> - System.out.println("Image object was returned (ok)");
> - else {
> - System.out.println("Unexpected object was returned (not ok)");
> - System.out.println("Unexpected object="+o);
> - }
> - } else {
> - System.out.println("null was returned");
> - }
> - } catch(Exception e) {
> - System.out.println("Exception: " + e);
> - }
> - }
> -
> - public void testGetRawContents(){
> - try
> - {
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage msg = factory.createMessage();
> - AttachmentPart ap = msg.createAttachmentPart();
> - ap = msg.createAttachmentPart();
> - byte data1[] = null;
> - data1 = ap.getRawContentBytes();
> -
> - } catch(SOAPException e) {
> - System.out.println("Caught expected SOAPException");
> - } catch(NullPointerException e) {
> - System.out.println("Caught expected NullPointerException");
> - } catch(Exception e) {
> - fail();
> - }
> - }
> -
> - public void testSetBase64Content(){
> - try
> - {
> - MessageFactory factory = MessageFactory.newInstance();
> - SOAPMessage msg = factory.createMessage();
> - AttachmentPart ap = msg.createAttachmentPart();
> -
> - URL url = new URL("http://ws.apache.org/images/project-logo.jpg");
> - DataHandler dh = new DataHandler(url);
> - System.out.println("Create InputStream from DataHandler's InputStream");
> - InputStream is = dh.getInputStream();
> -
> - System.out.println("Setting Content via InputStream for image/jpeg mime type");
> - ByteArrayOutputStream bos = new ByteArrayOutputStream();
> - OutputStream ret = new BASE64EncoderStream(bos);
> - int count;
> - byte buf[] = new byte[8192];
> - while ((count = is.read(buf, 0, 8192)) != -1) {
> - ret.write(buf, 0, count);
> - }
> - ret.flush();
> - buf = bos.toByteArray();
> - InputStream stream = new ByteArrayInputStream(buf);
> - ap.setBase64Content(stream,"image/jpeg");
> -
> - System.out.println("Getting Content should return InputStream object");
> - InputStream r = ap.getBase64Content();
> - System.out.println("object returned="+r);
> - if(r != null) {
> - if(r instanceof InputStream)
> - System.out.println("InputStream object was returned (ok)");
> - else {
> - System.out.println("Unexpected object was returned (not ok)");
> - System.out.println("Unexpected object="+r);
> - }
> - } else {
> - System.out.println("null was returned");
> - }
> - } catch(Exception e) {
> - System.out.println("Exception: " + e);
> - }
> - }
> -
> + public AttachmentTest(String name) {
> + super(name);
> + }
> +
> +
> + public void testStringAttachment() throws Exception {
> +
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage message = factory.createMessage();
> + AttachmentPart attachment = message.createAttachmentPart();
> + String stringContent = "Update address for Sunny Skies " +
> + "Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
> +
> + attachment.setContent(stringContent, "text/plain");
> + attachment.setContentId("update_address");
> + message.addAttachmentPart(attachment);
> +
> + assertTrue(message.countAttachments() == 1);
> +
> + java.util.Iterator it = message.getAttachments();
> + while (it.hasNext()) {
> + attachment = (AttachmentPart) it.next();
> + Object content = attachment.getContent();
> + String id = attachment.getContentId();
> + assertEquals(content, stringContent);
> + }
> + message.writeTo(System.out);
> +
> + message.removeAllAttachments();
> + assertTrue(message.countAttachments() == 0);
> + }
> +
> +
> +
> + public void testMultipleAttachments() throws Exception {
> +
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage msg = factory.createMessage();
> + java.net.URL url1 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.html");
> + java.net.URL url2 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.txt");
> +
> + AttachmentPart a1 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> + a1.setContentType("text/xml");
> + msg.addAttachmentPart(a1);
> + AttachmentPart a2 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> + a2.setContentType("text/xml");
> + msg.addAttachmentPart(a2);
> + AttachmentPart a3 = msg.createAttachmentPart(new javax.activation.DataHandler(url2));
> + a3.setContentType("text/plain");
> + msg.addAttachmentPart(a3);
> +
> + assertTrue(msg.countAttachments() == 3);
> +
> + javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
> + mimeHeaders.addHeader("Content-Type", "text/xml");
> +
> + int nAttachments = 0;
> + java.util.Iterator iterator = msg.getAttachments(mimeHeaders);
> + while (iterator.hasNext()) {
> + nAttachments++;
> + AttachmentPart ap = (AttachmentPart) iterator.next();
> + assertTrue(ap.equals(a1) || ap.equals(a2));
> + }
> + assertTrue(nAttachments == 2);
> + }
> +
> +
> + public void testMultipleAttachments2() throws Exception {
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage msg = factory.createMessage();
> + java.net.URL url1 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.html");
> + java.net.URL url2 = new java.net.URL("http://www.apache.org/licenses/LICENSE-2.0.txt");
> +
> + AttachmentPart a1 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> + a1.setContentType("text/xml");
> + msg.addAttachmentPart(a1);
> + AttachmentPart a2 = msg.createAttachmentPart(new javax.activation.DataHandler(url1));
> + a2.setContentType("text/xml");
> + msg.addAttachmentPart(a2);
> + AttachmentPart a3 = msg.createAttachmentPart(new javax.activation.DataHandler(url2));
> + a3.setContentType("text/plain");
> + msg.addAttachmentPart(a3);
> +
> + assertTrue(msg.countAttachments() == 3);
> +
> + javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
> + mimeHeaders.addHeader("Content-Type", "text/xml");
> +
> + int nAttachments = 0;
> + java.util.Iterator iterator = msg.getAttachments(mimeHeaders);
> + while (iterator.hasNext()) {
> + nAttachments++;
> + AttachmentPart ap = (AttachmentPart) iterator.next();
> + assertTrue(ap.equals(a1) || ap.equals(a2));
> + }
> + assertTrue(nAttachments == 2);
> + }
> +
> + public void testBadAttSize() throws Exception {
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage message = factory.createMessage();
> +
> + ByteArrayInputStream ins = new ByteArrayInputStream(new byte[5]);
> + DataHandler dh = new DataHandler(new Src(ins, "text/plain"));
> + AttachmentPart part = message.createAttachmentPart(dh);
> + assertEquals("Size should match", 5, part.getSize());
> + }
> +
> + class Src implements DataSource {
> + InputStream m_src;
> + String m_type;
> +
> + public Src(InputStream data, String type) {
> + m_src = data;
> + m_type = type;
> + }
> +
> + public String getContentType() {
> + return m_type;
> + }
> +
> + public InputStream getInputStream() throws IOException {
> + m_src.reset();
> + return m_src;
> + }
> +
> + public String getName() {
> + return "Some-Data";
> + }
> +
> + public OutputStream getOutputStream() {
> + throw new UnsupportedOperationException("I don't give output streams");
> + }
> + }
> +
> +
> + public void testClearContent() throws Exception {
> + try {
> + InputStream in1 = new FileInputStream(new File("test-resources" + File.separator + "attach.xml"));
> +
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage message = factory.createMessage();
> + AttachmentPart ap = message.createAttachmentPart();
> + MimeHeader mh = null;
> +
> + //Setting Mime Header
> + ap.setMimeHeader("Content-Description","some text");
> +
> + //Setting Content Id Header
> + ap.setContentId("id@abc.com");
> +
> + //Setting Content
> + ap.setContent( new StreamSource(in1),"text/xml");
> +
> + //Clearing Content
> + ap.clearContent();
> +
> + try {
> +
> + //Getting Content
> + InputStream is = (InputStream)ap.getContent();
> + fail("Error: SOAPException should have been thrown");
> + } catch(SOAPException e) {
> + //Error thrown.(expected)
> + }
> +
> + Iterator iterator = ap.getAllMimeHeaders();
> + int cnt=0;
> + boolean foundHeader1=false;
> + boolean foundHeader2=false;
> + boolean foundDefaultHeader=false;
> + while (iterator.hasNext()) {
> + cnt++;
> + mh = (MimeHeader)iterator.next();
> + String name=mh.getName();
> + String value=mh.getValue();
> + if (name.equals("Content-Description") && value.equals("some text")){
> + if (!foundHeader1){
> + foundHeader1=true;
> + //MimeHeaders do match for header1
> + //System.out.println("receive: name="+name+", value="+value);
> + }
> + else {
> + fail("Error: Received the same header1 header twice");
> + //System.out.println("received: name="+name+", value="+value);
> + }
> + } else if (name.equals("Content-Id") && value.equals("id@abc.com")){
> + //TODO Content-Id or Content-ID??
> + if (!foundHeader2){
> + foundHeader2=true;
> + //MimeHeaders do match for header2
> + //System.out.println("receive: name="+name+", value="+value);
> + }
> + else {
> + fail("Error: Received the same header2 header twice");
> + //System.out.println("received: name="+name+", value="+value);
> + }
> + } else if (name.equals("Content-Type") && value.equals("text/xml")){
> + if (!foundDefaultHeader){
> + foundDefaultHeader=true;
> + //MimeHeaders do match for default header
> + //System.out.println("receive: name="+name+", value="+value);
> + }
> + else {
> + fail("Error: Received the same default header header twice");
> + //System.out.println("received: name="+name+", value="+value);
> + }
> + } else {
> + fail("Error: Received an invalid header");
> + //System.out.println("received: name="+name+", value="+value);
> + }
> + }
> +
> + if (!(foundHeader1 && foundHeader2)){
> + fail("Error: did not receive both headers");
> + }
> +
> + } catch(Exception e) {
> + fail("Exception: " + e);
> + }
> +
> + }
> +
> +
> +
> +
> + public void testGetContent() throws Exception
> + {
> + try
> + {
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage msg = factory.createMessage();
> + AttachmentPart ap = msg.createAttachmentPart();
> + Image image = javax.imageio.ImageIO.read(new File("test-resources" + File.separator + "attach.gif"));
> + ap = msg.createAttachmentPart(image, "image/gif");
> +
> + //Getting Content should return an Image object
> + Object o = ap.getContent();
> + if(o != null) {
> + if(o instanceof Image){
> + //Image object was returned (ok)
> + }else {
> + fail("Unexpected object was returned");
> + }
> + }
> + } catch(Exception e) {
> + fail("Exception: " + e);
> + }
> + }
> +
> + public void testGetRawContents(){
> + try
> + {
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage msg = factory.createMessage();
> + AttachmentPart ap = msg.createAttachmentPart();
> + ap = msg.createAttachmentPart();
> + byte data1[] = null;
> + data1 = ap.getRawContentBytes();
> +
> + } catch(SOAPException e) {
> + //Caught expected SOAPException
> + } catch(NullPointerException e) {
> + //Caught expected NullPointerException
> + } catch(Exception e) {
> + fail();
> + }
> + }
> +
> +
> +
> + public void testSetBase64Content(){
> + try
> + {
> + MessageFactory factory = MessageFactory.newInstance();
> + SOAPMessage msg = factory.createMessage();
> + AttachmentPart ap = msg.createAttachmentPart();
> +
> + URL url = new URL("http://ws.apache.org/images/project-logo.jpg");
> + DataHandler dh = new DataHandler(url);
> + //Create InputStream from DataHandler's InputStream
> + InputStream is = dh.getInputStream();
> +
> + //Setting Content via InputStream for image/jpeg mime type
> + ByteArrayOutputStream bos = new ByteArrayOutputStream();
> + OutputStream ret = new BASE64EncoderStream(bos);
> + int count;
> + byte buf[] = new byte[8192];
> + while ((count = is.read(buf, 0, 8192)) != -1) {
> + ret.write(buf, 0, count);
> + }
> + ret.flush();
> + buf = bos.toByteArray();
> + InputStream stream = new ByteArrayInputStream(buf);
> + ap.setBase64Content(stream,"image/jpeg");
> +
> + //Getting Content.. should return InputStream object
> + InputStream r = ap.getBase64Content();
> + if(r != null) {
> + if(r instanceof InputStream){
> + //InputStream object was returned (ok)
> + }else {
> + fail("Unexpected object was returned");
> + }
> + }
> + } catch(Exception e) {
> + fail("Exception: " + e);
> + }
> + }
> +
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/MessageFactoryTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/MessageFactoryTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/MessageFactoryTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/MessageFactoryTest.java Mon Feb 5 04:14:07 2007
> @@ -17,8 +17,6 @@
>
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> -import java.io.File;
> -import java.io.FileInputStream;
>
> import javax.xml.soap.MessageFactory;
> import javax.xml.soap.MimeHeaders;
> @@ -108,67 +106,21 @@
> }
> }
>
> - public void _testMessageFactory3() {
> - MimeHeaders headers = new MimeHeaders();
> - headers.addHeader("Content-Type",
> - "multipart/related; boundary=MIMEBoundaryurn:uuid:F02ECC18873CFB73E211412748909307; type=\"application/xop+xml\"; start=\"<0....@apache.org>\"; start-info=\"text/xml\"; charset=UTF-16");
> -
> - try {
> - FileInputStream fis = new FileInputStream("test-resources" + File.separator + "message.bin");
> - SOAPMessage msg1 = mf.createMessage(headers, fis);
> - } catch (Exception e) {
> - e.printStackTrace();
> - fail("Unexpected Exception : " + e);
> - }
> - }
>
> public void testNewInstane(){
> try {
> - // Create a Dynamic MessageFactory object
> - System.out.println("Create Dynamic MessageFactory object");
> - MessageFactory mf = MessageFactory.newInstance(
> - SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
> - if(mf == null) {
> - System.out.println("MessageFactory.newInstance(" +
> - "DYNAMIC_SOAP_PROTOCOL) returned null");
> - } else if(!(mf instanceof MessageFactory)) {
> - System.out.println("MessageFactory.newInstance(" +
> - "DYNAMIC_SOAP_PROTOCOL) did not return MessageFactory object");
> - }
> -
> - MessageFactory mf2 = MessageFactory.newInstance();
> + MessageFactory mf = MessageFactory.newInstance();
> + assertNotNull(mf);
> ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
> - ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
>
> - System.out.println("Create SOAPMessage msg1 using createMessage()");
> - SOAPMessage msg1 = mf2.createMessage();
> + SOAPMessage msg1 = mf.createMessage();
> msg1.writeTo(baos1);
>
> MimeHeaders headers = new MimeHeaders();
> headers.addHeader("Content-Type", "text/xml");
>
> - // Create SOAPMessage from MessageFactory object using InputStream
> - System.out.println("Create SOAPMessage msg2 using SOAPMessage msg1" +
> - " as the InputStream");
> - System.out.println("Create SOAPMessage msg2 using createMessage(" +
> - "MimeHeaders, InputStream)");
> - SOAPMessage msg2 = mf.createMessage(headers,
> - new ByteArrayInputStream(baos1.toByteArray()));
> - if(msg2 == null) {
> - System.out.println("Could not create SOAPMessage (msg = null)");
> - } else if(!(msg2 instanceof SOAPMessage)) {
> - fail("Could not create SOAPMessage (msg != SOAPMessage)");
> - }
> - msg2.writeTo(baos2);
> - System.out.println("Compare msg1 and msg2 (should be equal)");
> - if(!(baos1.toString().equals(baos2.toString()))) {
> - System.out.println("msg1 = " + baos1.toString());
> - System.out.println("msg2 = " + baos2.toString());
> - fail("msg1 and msg2 are not equal (they should be)");
> - }
> } catch(Exception e) {
> - System.out.println("Exception: " + e);
> + fail("Exception: " + e);
> }
> }
> -
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/PrefixesTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/PrefixesTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/PrefixesTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/PrefixesTest.java Mon Feb 5 04:14:07 2007
> @@ -55,8 +55,6 @@
> msg.writeTo(baos);
>
> String xml = new String(baos.toByteArray());
> -
> - System.out.println("########## xml = " + xml);
> assertTrue(xml.indexOf("prefix1") != -1);
> assertTrue(xml.indexOf("prefix2") != -1);
> assertTrue(xml.indexOf("http://www.sun.com") != -1);
> @@ -86,7 +84,7 @@
> while (iter.hasNext()) {
> final Object obj = iter.next();
> if (obj instanceof Text) {
> - System.out.println("\n- Text Ignored.");
> + //System.out.println("\n- Text Ignored.");
> } else {
> final SOAPElement soapElement = (SOAPElement) obj;
> final Iterator attIter = soapElement.getAllAttributes();
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJDetailTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJDetailTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJDetailTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SAAJDetailTest.java Mon Feb 5 04:14:07 2007
> @@ -52,28 +52,22 @@
> }
>
>
> -
> + /*
> + * for soap version 1.1
> + */
> public void testAddDetailEntry() {
> try
> {
> - System.out.println("Add a SOAPFault object to the SOAPBody");
> + //Add a SOAPFault object to the SOAPBody
> SOAPFault sf = body.addFault();
> - System.out.println("Add a Detail object to the SOAPFault object");
> + //Add a Detail object to the SOAPFault object
> Detail d = sf.addDetail();
> QName name = new QName("http://www.wombat.org/trader",
> "GetLastTradePrice", "WOMBAT");
> - System.out.println("Add a DetailEntry object to the Detail object");
> + //Add a DetailEntry object to the Detail object
> DetailEntry de = d.addDetailEntry(name);
> - System.out.println("Successfully created DetailEntry object");
> - if(de == null) {
> - System.out.println("addDetailEntry() returned null");
> - } else if(!(de instanceof DetailEntry)) {
> - System.out.println(
> - "addDetailEntry() did not return a DetailEntry object");
> - }
> - else
> - System.out.println("Successfully created DetailEntry object");
> -
> + assertNotNull(de);
> + assertTrue(de instanceof DetailEntry);
> } catch (Exception e) {
> fail("Exception: " + e);
> }
> @@ -90,23 +84,17 @@
> envelope = sp.getEnvelope();
> body = envelope.getBody();
>
> - System.out.println("Add a SOAPFault object to the SOAPBody");
> + //Add a SOAPFault object to the SOAPBody
> SOAPFault sf = body.addFault();
> - System.out.println("Add a Detail object to the SOAPFault object");
> + //Add a Detail object to the SOAPFault object
> Detail d = sf.addDetail();
> QName name = new QName("http://www.wombat.org/trader",
> "GetLastTradePrice", "WOMBAT");
> - System.out.println("Add a DetailEntry object to the Detail object");
> + //Add a DetailEntry object to the Detail object
> DetailEntry de = d.addDetailEntry(name);
> - System.out.println("Successfully created DetailEntry object");
> - if(de == null) {
> - System.out.println("addDetailEntry() returned null");
> - } else if(!(de instanceof DetailEntry)) {
> - System.out.println("addDetailEntry() did not return a DetailEntry object");
> - }
> - else
> - System.out.println("Successfully created DetailEntry object");
> -
> + //Successfully created DetailEntry object
> + assertNotNull(de);
> + assertTrue(de instanceof DetailEntry);
> } catch (Exception e) {
> fail("Exception: " + e);
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPBodyTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPBodyTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPBodyTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPBodyTest.java Mon Feb 5 04:14:07 2007
> @@ -114,7 +114,7 @@
> assertEquals(2, count);
> }
>
> - public void testAddDocument() {
> + public void _testAddDocument() {
> try {
> Document document = null;
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> @@ -127,7 +127,7 @@
>
> message.getSOAPHeader().detachNode();
> // assertNull(message.getSOAPHeader());
> - // TODO:this fails. Header is always being created if it doesnt exist it DOOM
> + // TODO:this fails. Header is always being created if it doesnt exist in DOOM
>
> SOAPBody soapBody = message.getSOAPBody();
> soapBody.addDocument(document);
> @@ -150,12 +150,10 @@
>
> if (node instanceof SOAPElement) {
> element = (SOAPElement) node;
> -
> Name name = element.getElementName();
> - System.out.println(indent + "Name is " + name.getQualifiedName());
> -
> Iterator attrs = element.getAllAttributes();
>
> + /*
> while (attrs.hasNext()) {
> Name attrName = (Name) attrs.next();
> System.out.println(indent + " Attribute name is " +
> @@ -163,14 +161,13 @@
> System.out.println(indent + " Attribute value is " +
> element.getAttributeValue(attrName));
> }
> + */
>
> Iterator iter2 = element.getChildElements();
> getContents(iter2, indent + " ");
> } else {
> text = (Text) node;
> -
> - String content = text.getValue();
> - System.out.println(indent + "Content is: " + content);
> + assertNotNull(text.getTextContent());
> }
> }
> }
> @@ -203,7 +200,6 @@
> assertEquals(childCount, 0);
> }
> catch (Exception e) {
> - e.printStackTrace();
> fail("Unexpected Exception : " + e);
> }
> }
> @@ -222,7 +218,6 @@
> message.saveChanges();
>
> } catch (Exception e) {
> - e.printStackTrace();
> fail("Unexpected Exception : " + e);
> }
> }
> @@ -239,14 +234,11 @@
> String value = "MyValue1";
> soapBody.addAttribute(qname, value);
> message.saveChanges();
> -
> } catch (Exception e) {
> - e.printStackTrace();
> fail("Unexpected Exception : " + e);
> }
> }
>
> - //TODO : check with azeez
> /*
> * For SOAP 1.2 message
> */
> @@ -263,13 +255,8 @@
> SOAPFault soapFault = soapBody.addFault(qname, value);
> message.saveChanges();
> assertNotNull(soapFault);
> - if(!(soapFault instanceof SOAPFault)){
> - fail("Wrong return type");
> - }
> -
> -
> + assertTrue(soapFault instanceof SOAPFault);
> } catch (Exception e) {
> - e.printStackTrace();
> fail("Unexpected Exception : " + e);
> }
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPConnectionTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPConnectionTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPConnectionTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPConnectionTest.java Mon Feb 5 04:14:07 2007
> @@ -90,23 +90,14 @@
> {
> try
> {
> - System.out.println("Create SOAPConnection object");
> SOAPConnectionFactory sf = new SOAPConnectionFactoryImpl();
> SOAPConnection con = sf.createConnection();
> - System.out.println(
> - "Create a valid non webservice endpoint for invoking HTTP-GET");
> + //Create a valid non webservice endpoint for invoking HTTP-GET
> URL urlEndpoint = new URL("http", "java.sun.com", 80, "/index.html");
> - System.out.println("Valid Non Webservice Endpoint=" + urlEndpoint);
> -
> - System.out.println("Invoking HTTP-GET with a valid non webservice " +
> - "endpoint should throw a SOAPException");
> + //invoking HTTP-GET with a valid non webservice endpoint should throw a SOAPException
> SOAPMessage reply = con.get(urlEndpoint);
> - System.out.println("HTTP-GET succeeded (unexpected)");
> - System.out.println("Did not get expected SOAPException");
> - } catch(SOAPException e) {
> - System.out.println("Did get expected SOAPException");
> - } catch(Exception e) {
> - fail();
> + }catch(Exception e) {
> + assertTrue(e instanceof SOAPException);
> }
> }
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java Mon Feb 5 04:14:07 2007
> @@ -241,14 +241,13 @@
> SOAPBody body = msg.getSOAPBody();
>
> Name name = soapEnvelope.createName("MyChild1");
> - System.out.println("Add child element Name object with localName=MyChild1");
> - System.out.println("Calling addChildElement(Name)");
> + //Add child element Name object with localName=MyChild1
> SOAPElement se = body.addChildElement(name);
> if(se == null){
> - System.out.println("addChildElement() did not return SOAPElement");
> - pass = false;
> + fail("addChildElement() did not return SOAPElement");
> + //pass = false;
> } else {
> - System.out.println("Find the child element just added");
> + //Find the child element just added
> Iterator childs = body.getChildElements(name);
> int count = 0;
> while (childs.hasNext()) {
> @@ -257,35 +256,27 @@
> }
>
> childs = body.getChildElements(name);
> - if(count != 1) {
> - System.out.println("Wrong iterator count returned of "+count + ", expected 1");
> - pass = false;
> - } else {
> - SOAPElement se2 = (SOAPElement)childs.next();
> - if(!se.equals(se2)) {
> - System.out.println("SOAPElement se != se2 (unexpected)");
> - pass = false;
> - } else{
> - System.out.println("SOAPElement se = se2 (expected)");
> - }
> - }
> - if(pass) {
> - System.out.println("Retrieve the SOAPElement Name");
> - Name n = se.getElementName();
> - System.out.println("localName="+n.getLocalName()+" prefix="
> - +n.getPrefix()+" URI="+n.getURI()+" qualifiedName="
> - +n.getQualifiedName());
> - if (!n.equals(name)) {
> - System.out.println("Name objects are not equal (unexpected)");
> - System.out.println("addChildElement() did not return " +
> - "correct Name object expected localName=" +
> - name.getLocalName() + ", got localName="
> - + n.getLocalName());
> - pass = false;
> - } else {
> - System.out.println("Name objects are equal (expected)");
> - }
> - }
> + assertTrue(count == 1);
> +
> + SOAPElement se2 = (SOAPElement)childs.next();
> + assertEquals(se, se2);
> + //se = se2 (expected)
> +
> + //Retrieve the SOAPElement Name
> + Name n = se.getElementName();
> + //System.out.println("localName="+n.getLocalName()+" prefix="
> + // +n.getPrefix()+" URI="+n.getURI()+" qualifiedName="
> + // +n.getQualifiedName());
> + assertEquals(n, name);
> + //if (!n.equals(name)) {
> + //System.out.println("Name objects are not equal (unexpected)");
> + //System.out.println("addChildElement() did not return " +
> + //"correct Name object expected localName=" +
> + //name.getLocalName() + ", got localName="
> + //+ n.getLocalName());
> + //}
> +
> + //Name objects are equal (expected)
> }
>
> } catch (Exception e) {
> @@ -326,7 +317,6 @@
> }
> }
> } catch (Exception e) {
> - e.printStackTrace();
> fail("Exception: " + e);
> }
> }
> @@ -346,13 +336,11 @@
> assertFalse("removeAttribute() did not return false", b);
> assertNull(body.getAttributeValue(name));
> } catch (Exception e) {
> - e.printStackTrace();
> fail("Exception: " + e);
> }
> }
>
> public void testRemoveAttribute2() {
> - boolean pass = true;
> try
> {
> SOAPMessage msg = MessageFactory.newInstance().createMessage();
> @@ -361,86 +349,46 @@
>
> QName name = new QName("MyAttr1");
> String value = "MyValue1";
> - System.out.println("Add attribute qname = " + name.getLocalPart() +
> - ", value = " + value);
> body.addAttribute(name, value);
> - System.out.println("Remove attribute qname = " + name.getLocalPart() +
> - ", value = " + value);
> boolean b = body.removeAttribute(name);
> - if(!b) {
> - System.out.println("removeAttribute() did not return true");
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> - if(pass) {
> - b = body.removeAttribute(name);
> - if(b) {
> - System.out.println("removeAttribute() did not return false");
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> - }
> - if(pass) {
> - if(body.getAttributeValue(name) == null) {
> - System.out.println("removeAttributeTest() test PASSED");
> - } else {
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> + assertTrue(b);
> +
> + b = body.removeAttribute(name);
> + if(b) {
> + //removeAttribute() did not return false
> + fail();
> }
> + //getAttributeValue should return null
> + assertNull(body.getAttributeValue(name));
> } catch(Exception e) {
> - System.out.println("Exception: " + e);
> - pass = false;
> + fail("Error : "+e);
> }
> }
>
> - /*
> - * name
> - */
> public void testRemoveAttributeName(){
> - boolean pass = true;
> - try
> - {
> - SOAPMessage msg = MessageFactory.newInstance().createMessage();
> + try{
> + SOAPMessage msg = MessageFactory.newInstance().createMessage();
> SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
> SOAPBody body = envelope.getBody();
>
> Name name = envelope.createName("MyAttr1");
> String value = "MyValue1";
> - System.out.println("Add attribute name = " + name.getLocalName() +
> - ", value = " + value);
> body.addAttribute(name, value);
> - System.out.println("Remove attribute name = " + name.getLocalName() +
> - ", value = " + value);
> boolean b = body.removeAttribute(name);
> - if(!b) {
> - System.out.println("removeAttribute() did not return true");
> - pass = false;
> - }
> - if(pass) {
> - b = body.removeAttribute(name);
> - if(b) {
> - System.out.println("removeAttribute() did not return false");
> - pass = false;
> - }
> - }
> - if(pass) {
> + assertTrue(b);
> +
> + b = body.removeAttribute(name);
> + assertTrue(!b);
> +
> String s = body.getAttributeValue(name);
> - if(s != null) {
> - System.out.println("getAttributeValue() returned wrong value,"
> - + " expected null, got \"" + s + "\"");
> - pass = false;
> - }
> - }
> + assertNull(s);
> } catch(Exception e) {
> - System.out.println("Exception: " + e);
> - pass = false;
> + fail("Failed : "+e);
> }
> }
>
>
> public void _testRemoveAttributeQName(){
> - boolean pass = true;
> try
> {
> SOAPMessage msg = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
> @@ -449,33 +397,13 @@
>
> QName name = new QName("MyAttr1");
> String value = "MyValue1";
> - System.out.println("Add attribute qname = " + name.getLocalPart() +
> - ", value = " + value);
> body.addAttribute(name, value);
> - System.out.println("Remove attribute qname = " + name.getLocalPart() +
> - ", value = " + value);
> boolean b = body.removeAttribute(name);
> - if(!b) {
> - System.out.println("removeAttribute() did not return true");
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> - if(pass) {
> - b = body.removeAttribute(name);
> - if(b) {
> - System.out.println("removeAttribute() did not return false");
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> - }
> - if(pass) {
> - if(body.getAttributeValue(name) == null) {
> - System.out.println("removeAttributeTest() test PASSED");
> - } else {
> - System.out.println("removeAttributeTest() test FAILED");
> - pass = false;
> - }
> - }
> + assertTrue(b);
> + b = body.removeAttribute(name);
> + assertTrue(!b);
> +
> + assertNull(body.getAttributeValue(name));
> } catch(Exception e) {
> fail();
> }
> @@ -633,16 +561,7 @@
> }
>
> Name n = se.getElementName();
> - if (!n.equals(name)) {
> - System.out.println("Name objects are not equal (unexpected)");
> - System.out.println("getChildElement() did not return " +
> - "correct Name object expected localName=" +
> - name.getLocalName() + ", got localName="
> - + n.getLocalName());
> - fail();
> - } else{
> - System.out.println("Name objects are equal (expected)");
> - }
> + assertEquals(n,name);
> } catch (SOAPException e) {
> fail("Unexpected Exception " + e);
> }
> @@ -670,23 +589,10 @@
> }
> assertEquals(childCount, 1);
> SOAPElement se2 = (SOAPElement)childElements.next();
> - if(!se.equals(se2)) {
> - fail();
> - } else {
> - System.out.println("SOAPElement se = se2 (expected)");
> - }
> + assertEquals(se,se2);
>
> QName n = se.getElementQName();
> - if (!n.equals(name)) {
> - System.out.println("Name objects are not equal (unexpected)");
> - System.out.println("getChildElement() did not return " +
> - "correct Name object expected localPart=" +
> - name.getLocalPart() + ", got localPart="
> - + n.getLocalPart());
> - fail();
> - } else{
> - System.out.println("Name objects are equal (expected)");
> - }
> + assertEquals(n,name);
> } catch (SOAPException e) {
> fail("Unexpected Exception " + e);
> }
> @@ -721,7 +627,6 @@
>
> public void _testCreateQName() {
> String prefix ="";
> - String uri = "";
> try
> {
> //SOAPMessage message = MessageFactory.newInstance().createMessage();
> @@ -729,17 +634,11 @@
> SOAPPart soapPart = message.getSOAPPart();
> SOAPEnvelope envelope = soapPart.getEnvelope();
> SOAPBody body = envelope.getBody();
> -
> - System.out.println("Create QName from SOAPEnvelope");
> - QName qname = envelope.createQName("qname", prefix);
> - System.out.println("Create QName of: " + qname);
> +
> + QName qname = envelope.createQName("qname", prefix);
> String tprefix = qname.getPrefix();
> String turi = qname.getNamespaceURI();
> String tname = qname.getLocalPart();
> - System.out.println("qname prefix="+tprefix);
> - System.out.println("qname uri="+turi);
> - System.out.println("qname localpart="+tname);
> - System.out.println("Verify correct uri and prefix");
> if(!tprefix.equals(prefix) || !turi.equals(envelope.getElementName().getURI())) {
> fail("createQName() did not create correct qname\n" +
> "expected: <uri=" + envelope.getElementName().getURI() +
> @@ -747,16 +646,10 @@
> "got: <uri=" + turi +
> ", prefix=" + tprefix + ", localpart=" + tname + ">");
> }
> - System.out.println("Create QName from SOAPBody");
> qname = body.createQName("qname", body.getElementName().getPrefix());
> - System.out.println("Create QName of: " + qname);
> tprefix = qname.getPrefix();
> turi = qname.getNamespaceURI();
> tname = qname.getLocalPart();
> - System.out.println("qname prefix="+tprefix);
> - System.out.println("qname uri="+turi);
> - System.out.println("qname localpart="+tname);
> - System.out.println("Verify correct uri and prefix");
> if(!tprefix.equals(body.getElementName().getPrefix()) || !turi.equals(body.getElementName().getURI())) {
> fail("createQName() did not create correct qname\n" +
> "expected: <uri=" + body.getElementName().getURI() +
> @@ -780,58 +673,29 @@
> SOAPBody body = envelope.getBody();
>
> Name name = envelope.createName("MyChild");
> - System.out.println("Add child element Name object = " +
> - name.toString());
> SOAPElement se = body.addChildElement(name);
> - if(se == null) {
> - System.out.println("addChildElement() did not return SOAPElement");
> - System.out.println("removeContentsTest() test FAILED");
> -
> - pass = false;
> - } else {
> - Iterator childs = body.getChildElements(name);
> - int childElementCount = 0;
> - for (int a = 0; childs.hasNext(); a++) {
> - childs.next();
> - childElementCount++;
> - }
> - childs = body.getChildElements(name);
> - if(childElementCount != 1) {
> - System.out.println("Wrong iterator count returned of " +
> - childElementCount + ", expected 1");
> - System.out.println("removeContentsTest() test FAILED");
> - pass = false;
> - }
> -
> - if(pass) {
> - Name n = se.getElementName();
> - if (!n.equals(name)) {
> - System.out.println("removeContentsTest() did not return " +
> - "correct name object expected localname=" +
> - name.getLocalName() + ", got localname="
> - + n.getLocalName());
> - System.out.println("removeContentsTest() test FAILED");
> - pass = false;
> - }
> - }
> + assertNotNull(se);
> + Iterator childs = body.getChildElements(name);
> + int childElementCount = 0;
> + for (int a = 0; childs.hasNext(); a++) {
> + childs.next();
> + childElementCount++;
> }
> - System.out.println("Child addition verified, now call removeContents to delete it");
> + childs = body.getChildElements(name);
> + assertEquals(childElementCount, 1);
> +
> + Name n = se.getElementName();
> + assertEquals(n, name);
> + //Child addition verified, now call removeContents to delete it
> se.removeContents();
> - Iterator childs = se.getChildElements();
> - int childElementCount = 0;
> + childs = se.getChildElements();
> + childElementCount = 0;
> for (int a = 0; childs.hasNext(); a++) {
> childs.next();
> childElementCount++;
> }
> - if ( childElementCount !=0 ) {
> - System.out.println("Wrong iterator count returned of " +
> - childElementCount + ", expected 0, after calling removeContents");
> - System.out.println("removeContentsTest() test FAILED");
> - pass = false;
> - }
> -
> + assertEquals(childElementCount, 0);
> } catch(Exception e) {
> - e.printStackTrace();
> fail();
> }
> }
> @@ -846,18 +710,12 @@
> SOAPBody body = envelope.getBody();
>
> QName qname1 = new QName("http://fooURI.com", "fooElement", "foo");
> - System.out.println("Create QName1 of: " + qname1);
> QName qname2 = new QName("http://foo2URI.com", "fooElement2", "foo2");
> - System.out.println("Create QName2 of: " + qname2);
> - System.out.println("Add a child SOAPElement of: " + qname1);
> - SOAPElement se = body.addChildElement(qname1);
> + SOAPElement se = body.addChildElement(qname1);
> QName qname = se.getElementQName();
> - System.out.println("Get element qname of child SOAPElement: " + qname);
> - System.out.println("Reset element qname of child SOAPElement to: " + qname2);
> se = se.setElementQName(qname2);
> qname = se.getElementQName();
> - System.out.println(
> - "Get element qname of child SOAPElement again: " + qname);
> +
> if(!qname.getNamespaceURI().equals(qname2.getNamespaceURI()) ||
> !qname.getLocalPart().equals(qname2.getLocalPart()) ||
> !qname.getPrefix().equals(qname2.getPrefix())) {
> @@ -868,7 +726,7 @@
> ", localpart=" + qname.getLocalPart() + ">");
> }
> } catch(Exception e) {
> - System.out.println("Exception: " + e);
> + fail("Error :"+e);
> }
> }
>
> @@ -883,33 +741,31 @@
> SOAPHeader header = envelope.getHeader();
>
> QName qname = new QName("qname");
> - System.out.println("Create QName of: " + qname);
> - System.out.println("Try and change element name of SOAPEnvelope " +
> - "(expect SOAPException)");
> + //Try and change element name of SOAPEnvelope (expect SOAPException)
> try {
> envelope.setElementQName(qname);
> - System.out.println("Did not throw expected SOAPException");
> + fail("Did not throw expected SOAPException");
> } catch (SOAPException e) {
> - System.out.println("Caught expected SOAPException");
> + //Caught expected SOAPException
> }
> - System.out.println(
> - "Try and change element name of SOAPHeader (expect SOAPException)");
> +
> + //Try and change element name of SOAPHeader (expect SOAPException)
> try {
> header.setElementQName(qname);
> - System.out.println("Did not throw expected SOAPException");
> + fail("Did not throw expected SOAPException");
> } catch (SOAPException e) {
> - System.out.println("Caught expected SOAPException");
> + //Caught expected SOAPException
> }
> - System.out.println(
> - "Try and change element name of SOAPBody (expect SOAPException)");
> +
> + //Try and change element name of SOAPBody (expect SOAPException)
> try {
> body.setElementQName(qname);
> - System.out.println("Did not throw expected SOAPException");
> + fail("Did not throw expected SOAPException");
> } catch (SOAPException e) {
> - System.out.println("Caught expected SOAPException");
> + //Caught expected SOAPException
> }
> } catch(Exception e) {
> - System.out.println("Exception: " + e);
> + fail("Error : "+e);
> }
> }
> }
>
> Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java
> URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java?view=diff&rev=503658&r1=503657&r2=503658
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java (original)
> +++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPEnvelopeTest.java Mon Feb 5 04:14:07 2007
> @@ -553,17 +553,15 @@
>
> try
> {
> - System.out.println("SOAP1.2 does not allow trailing blocks after" +
> - "the Body");
> - System.out.println("Call SOAPEnvelope.addChildElement() and " +
> - "(expect SOAPException)");
> + //SOAP1.2 does not allow trailing blocks after the Body
> + //Call SOAPEnvelope.addChildElement() and (expect SOAPException)
> Name elementAfterBody = envelope.createName("AfterBody", "e", "some-uri");
> envelope.addChildElement(elementAfterBody);
> - System.out.println("Did not throw expected SOAPException");
> + fail("Did not throw expected SOAPException");
> } catch (SOAPException e) {
> - System.out.println("Did throw expected SOAPException");
> + //Did throw expected SOAPException"
> } catch (Exception e) {
> - System.out.println("Unexpected Exception: " + e.getMessage());
> + fail("Unexpected Exception: " + e.getMessage());
> }
> }
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-cvs-help@ws.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org