axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/test/saaj TestAttachment.java
Date Tue, 02 Jul 2002 11:31:47 GMT
dims        2002/07/02 04:31:47

  Modified:    java/src/org/apache/axis/attachments AttachmentPart.java
                        AttachmentsImpl.java MimeUtils.java
                        MultiPartDimeInputStream.java
                        MultiPartRelatedInputStream.java
               java/src/org/apache/axis/encoding/ser
                        JAFDataHandlerSerializer.java
               java/test/md5attach MD5AttachTest.java
               java/src/org/apache/axis SOAPPart.java
               java/test/saaj TestAttachment.java
  Log:
  Rolling back my changes.
  
  Revision  Changes    Path
  1.19      +24 -5     xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
  
  Index: AttachmentPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AttachmentPart.java	1 Jul 2002 20:01:39 -0000	1.18
  +++ AttachmentPart.java	2 Jul 2002 11:31:46 -0000	1.19
  @@ -96,6 +96,7 @@
        * Constructor AttachmentPart
        */
       public AttachmentPart() {
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, SOAPUtils.getNewContentIdValue());
       }
   
       /**
  @@ -104,9 +105,11 @@
        * @param dh
        */
       public AttachmentPart(javax.activation.DataHandler dh) {
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                SOAPUtils.getNewContentIdValue());
           datahandler = dh;
           if(dh != null)
  -            setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType());
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType());
       }
   
       /**
  @@ -134,7 +137,7 @@
        * @param value
        */
       public void addMimeHeader(String header, String value) {
  -        mimeHeaders.addHeader(header, value);
  +        mimeHeaders.setHeader(header, value);
       }
   
       /**
  @@ -188,7 +191,7 @@
        * @param loc
        */
       public void setContentLocation(String loc) {
  -        setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
       }
   
       /**
  @@ -198,7 +201,10 @@
        *     @returns void
        */
       public void setContentId(String newCid) {
  -        setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid);
  +        if (newCid!=null && !newCid.toLowerCase().startsWith("cid:")) {
  +            newCid = "cid:" + newCid;
  +        }
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid);
       }
   
       /**
  @@ -207,7 +213,20 @@
        * @return
        */
       public String getContentId() {
  -        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        String ret = getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        // Do not let the contentID ever be empty.
  +        if (ret == null) {
  +            ret = SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, ret);
  +        }
  +
  +        ret = ret.trim();
  +        if (ret.length() == 0) {
  +            ret = SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, ret);
  +        }
  +
  +        return ret;
       }
   
       /**
  
  
  
  1.23      +11 -11    xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java
  
  Index: AttachmentsImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- AttachmentsImpl.java	1 Jul 2002 20:01:39 -0000	1.22
  +++ AttachmentsImpl.java	2 Jul 2002 11:31:46 -0000	1.23
  @@ -223,8 +223,7 @@
           Part removedPart = getAttachmentByReference(reference);
   
           if (removedPart != null) {
  -            if(removedPart.getContentId()!=null)
  -                attachments.remove(removedPart.getContentId());
  +            attachments.remove(removedPart.getContentId());
               attachments.remove(removedPart.getContentLocation());
               orderedAttachments.remove(removedPart);
           }
  @@ -251,9 +250,7 @@
   
           mergeinAttachments();
   
  -        Part oldPart = null;
  -        if(newPart.getContentId()!=null)
  -            oldPart = (Part) attachments.put(newPart.getContentId(), newPart);
  +        Part oldPart = (Part) attachments.put(newPart.getContentId(), newPart);
   
           if (oldPart != null) {
               orderedAttachments.remove(oldPart);
  @@ -478,8 +475,6 @@
                   AttachmentPart part= (AttachmentPart)i.next();
                       DataHandler dh= AttachmentUtils.
                         getActivationDataHandler(part);
  -                    if(part.getContentId() == null)
  -                        part.setContentId(org.apache.axis.utils.SOAPUtils.getNewContentIdValue());
                       dimemultipart.addBodyPart(new 
                         DimeBodyPart(dh,part.getContentId()));
                 }
  @@ -591,10 +586,15 @@
               log.warn(JavaUtils.getMessage("exception00"));
           }
   
  -        multipart = null;
  -        dimemultipart = null;
  -        attachments.clear();
  -        orderedAttachments.clear();
  +        java.util.Iterator iterator = attachments.values().iterator();
  +        while(iterator.hasNext()){
  +            Part removedPart = (Part) iterator.next();
  +            if (removedPart != null) {
  +                attachments.remove(removedPart.getContentId());
  +                attachments.remove(removedPart.getContentLocation());
  +                orderedAttachments.remove(removedPart);
  +            }
  +        }
       }
   
       /**
  
  
  
  1.20      +48 -4     xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java
  
  Index: MimeUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- MimeUtils.java	1 Jul 2002 20:01:39 -0000	1.19
  +++ MimeUtils.java	2 Jul 2002 11:31:46 -0000	1.20
  @@ -267,7 +267,12 @@
           javax.mail.internet.MimeMultipart multipart = null;
   
           try {
  -            String rootCID = org.apache.axis.utils.SOAPUtils.getNewContentIdValue();
  +            String rootCID = getNewContentIdValue();
  +
  +            if (rootCID.startsWith("cid:")) {
  +                rootCID = rootCID.substring(4);
  +            }
  +
               multipart = new javax.mail.internet.MimeMultipart(
                       "related; type=\"text/xml\"; start=\"<" + rootCID + ">\"");
   
  @@ -288,11 +293,11 @@
                   javax.activation.DataHandler dh =
                           org.apache.axis.attachments.AttachmentUtils.getActivationDataHandler(
                                   part);
  -                if(part.getContentId()==null){
  -                    part.setContentId(org.apache.axis.utils.SOAPUtils.getNewContentIdValue());
  -                }
                   String contentID = part.getContentId();
   
  +                if (contentID.startsWith("cid:")) {
  +                    contentID = contentID.substring(4);
  +                }
   
                   messageBodyPart = new javax.mail.internet.MimeBodyPart();
   
  @@ -332,5 +337,44 @@
           }
   
           return multipart;
  +    }
  +
  +    /** Field thisHost           */
  +    static String thisHost = null;
  +
  +    /** Field count           */
  +    private static int count = (int) (Math.random() * 100);
  +
  +    /**
  +     * Method getNewContentIdValue
  +     *
  +     * @return
  +     */
  +    public static String getNewContentIdValue() {
  +
  +        int lcount;
  +
  +        synchronized (org.apache.axis.Message.class) {
  +            lcount = ++count;
  +        }
  +
  +        if (null == thisHost) {
  +            try {
  +                thisHost = java.net.InetAddress.getLocalHost().getHostName();
  +            } catch (java.net.UnknownHostException e) {
  +                log.error(JavaUtils.getMessage("javaNetUnknownHostException00"),
  +                        e);
  +
  +                thisHost = "localhost";
  +            }
  +        }
  +
  +        StringBuffer s = new StringBuffer();
  +
  +        // Unique string is <hashcode>.<currentTime>.apache-soap.<hostname>
  +        s.append("cid:").append(lcount).append(s.hashCode()).append('.').append(
  +                System.currentTimeMillis()).append(".AXIS@").append(thisHost);
  +
  +        return s.toString();
       }
   }
  
  
  
  1.5       +1 -5      xml-axis/java/src/org/apache/axis/attachments/MultiPartDimeInputStream.java
  
  Index: MultiPartDimeInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MultiPartDimeInputStream.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MultiPartDimeInputStream.java	1 Jul 2002 20:01:39 -0000	1.4
  +++ MultiPartDimeInputStream.java	2 Jul 2002 11:31:46 -0000	1.5
  @@ -101,8 +101,6 @@
           super(null); //don't cache this stream.
           soapStream = dimeDelimitedStream = new DimeDelimitedInputStream(is); //The Soap
stream must always be first
           contentId = dimeDelimitedStream.getContentId();
  -        if(contentId == null)
  -            contentId = org.apache.axis.utils.SOAPUtils.getNewContentIdValue();
       }
   
       public Part getAttachmentByReference(final String[] id)
  @@ -191,8 +189,6 @@
               if (null != dimeDelimitedStream) {
                   do {
                       String contentId = dimeDelimitedStream.getContentId();
  -                    if(contentId == null)
  -                        contentId = org.apache.axis.utils.SOAPUtils.getNewContentIdValue();
                       String type = dimeDelimitedStream.getType();
   
                       if (type != null && !dimeDelimitedStream.getDimeTypeNameFormat().equals(DimeTypeNameFormat.MIME))
{
  @@ -206,7 +202,7 @@
                       AttachmentPart ap = new AttachmentPart(dh);
   
                       if (contentId != null) 
  -                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); 
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); 
   
                       addPart(contentId, "", ap);
   
  
  
  
  1.19      +18 -4     xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java
  
  Index: MultiPartRelatedInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- MultiPartRelatedInputStream.java	1 Jul 2002 20:01:39 -0000	1.18
  +++ MultiPartRelatedInputStream.java	2 Jul 2002 11:31:46 -0000	1.19
  @@ -162,6 +162,10 @@
                       rootPartContentId = rootPartContentId.substring(0,
                               rootPartContentId.length() - 1);
                   }
  +
  +                if (!rootPartContentId.startsWith("cid:")) {
  +                    rootPartContentId = "cid:" + rootPartContentId;
  +                }
               }
   
               // if start is null then the first attachment is the rootpart
  @@ -235,6 +239,12 @@
                       }
   
                       contentId = contentId.trim();
  +
  +                    if (!contentId.startsWith("cid:")) {
  +                        contentId =
  +                                "cid:"
  +                                + contentId;        // make sure its identified as cid
  +                    }
                   }
   
                   contentLocation =
  @@ -287,12 +297,12 @@
                       AttachmentPart ap = new AttachmentPart(dh);
   
                       if (contentId != null) {
  -                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
                                   contentId);
                       }
   
                       if (contentLocation != null) {
  -                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
                                   contentLocation);
                       }
   
  @@ -509,6 +519,10 @@
                                       contentId.substring(0, contentId.length() - 1);
                           }
   
  +                        if (!contentId.startsWith("cid:")) {
  +                            contentId = "cid:" + contentId;
  +                        }
  +
                           contentId = contentId.trim();
                       }
   
  @@ -551,12 +565,12 @@
                       AttachmentPart ap = new AttachmentPart(dh);
   
                       if (contentId != null) {
  -                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
                                   contentId);
                       }
   
                       if (contentLocation != null) {
  -                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
                                   contentLocation);
                       }
   
  
  
  
  1.14      +0 -1      xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerSerializer.java
  
  Index: JAFDataHandlerSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerSerializer.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JAFDataHandlerSerializer.java	1 Jul 2002 20:01:39 -0000	1.13
  +++ JAFDataHandlerSerializer.java	2 Jul 2002 11:31:46 -0000	1.14
  @@ -111,7 +111,6 @@
           //Add the attachment content to the message.
           Attachments attachments= context.getCurrentMessage().getAttachmentsImpl();
           Part attachmentPart= attachments.createAttachmentPart(dh);
  -        attachmentPart.setContentId(org.apache.axis.utils.SOAPUtils.getNewContentIdValue());
           String href= attachmentPart.getContentId();
   
           AttributesImpl attrs = new AttributesImpl();
  
  
  
  1.6       +0 -1      xml-axis/java/test/md5attach/MD5AttachTest.java
  
  Index: MD5AttachTest.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/md5attach/MD5AttachTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MD5AttachTest.java	1 Jul 2002 20:01:39 -0000	1.5
  +++ MD5AttachTest.java	2 Jul 2002 11:31:47 -0000	1.6
  @@ -54,7 +54,6 @@
           //Add the attachment content to the message.
           org.apache.axis.attachments.Attachments attachments = msg.getAttachmentsImpl();
           org.apache.axis.Part attachmentPart = attachments.createAttachmentPart(dh);
  -        attachmentPart.setContentId(org.apache.axis.utils.SOAPUtils.getNewContentIdValue());
           String href = attachmentPart.getContentId();
           //Have the parameter element set an href attribute to the attachment.
           paramElement.setAttribute(org.apache.axis.Constants.ATTR_HREF, href);
  
  
  
  1.31      +27 -11    xml-axis/java/src/org/apache/axis/SOAPPart.java
  
  Index: SOAPPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/SOAPPart.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SOAPPart.java	1 Jul 2002 20:01:39 -0000	1.30
  +++ SOAPPart.java	2 Jul 2002 11:31:47 -0000	1.31
  @@ -127,7 +127,7 @@
        * object is."
        */
       private Object currentMessage ;
  -
  +    
       /**
        * Message object this part is tied to. Used for serialization settings.
        */
  @@ -145,7 +145,9 @@
        * "Just something to us working..."
        */
       public SOAPPart(Message parent, Object initialContents, boolean isBodyStream) {
  -        mimeHeaders.setHeader("Content-Type", "text/xml");
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SOAPUtils.getNewContentIdValue());
  +
  +
           msgObject=parent;
           // originalMessage = initialContents;
           int form = FORM_STRING;
  @@ -169,7 +171,7 @@
               log.debug("Exit: SOAPPart ctor()");
           }
       }
  -    /* This could be rather costly with attachments.
  +    /* This could be rather costly with attachments.  
   
       public Object getOriginalMessage() {
           return originalMessage;
  @@ -213,15 +215,15 @@
           }
       }
       /**
  -     * This set the SOAP Envelope for this part.
  -     *
  +     * This set the SOAP Envelope for this part. 
  +     * 
        * Note: It breaks the chicken/egg created.
        *  I need a message to create an attachment...
        *  From the attachment I should be able to get a reference...
        *  I now want to edit elements in the envelope in order to
        *    place the  attachment reference to it.
        *  How do I now update the SOAP envelope with what I've changed?
  -     *
  +     *  
        */
   
       public void setSOAPEnvelope(org.apache.axis.message.SOAPEnvelope env){
  @@ -461,7 +463,7 @@
           }
   
           setCurrentMessage(dser.getEnvelope(), FORM_SOAPENVELOPE);
  -
  +        
           log.debug("Exit: SOAPPart::getAsSOAPEnvelope");
           return (SOAPEnvelope)currentMessage;
       }
  @@ -470,7 +472,7 @@
        * Add the specified MIME header, as per JAXM.
        */
       public void addMimeHeader (String header, String value) {
  -        mimeHeaders.addHeader(header, value);
  +        mimeHeaders.setHeader(header, value);
       }
   
       /**
  @@ -499,7 +501,7 @@
        * Set content location.
        */
       public void setContentLocation(String loc) {
  -        setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
       }
   
       /**
  @@ -509,14 +511,28 @@
            * @returns void
            */
           public void setContentId(String newCid){
  -                setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
  +                if(newCid!=null && !newCid.toLowerCase().startsWith("cid:")){
  +                        newCid="cid:"+newCid;
  +                }
  +                addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
           }
   
       /**
        * Content ID.
        */
       public String getContentId() {
  -        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        String ret= getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        //Do not let the contentID ever be empty.
  +        if(ret == null){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        ret= ret.trim();
  +        if(ret.length() ==0){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        return ret;
       }
   
   
  
  
  
  1.5       +0 -1      xml-axis/java/test/saaj/TestAttachment.java
  
  Index: TestAttachment.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/saaj/TestAttachment.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestAttachment.java	1 Jul 2002 20:01:39 -0000	1.4
  +++ TestAttachment.java	2 Jul 2002 11:31:47 -0000	1.5
  @@ -19,7 +19,6 @@
           MessageFactory factory = MessageFactory.newInstance();
           SOAPMessage message = factory.createMessage();
           AttachmentPart attachment = message.createAttachmentPart();
  -        attachment.setContentId(org.apache.axis.utils.SOAPUtils.getNewContentIdValue());
           String stringContent = "Update address for Sunny Skies " +
                   "Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
   
  
  
  

Mime
View raw message