- Do these changes "guarantee" that when a content-id header is gotten that the href will have a "cid:" prefix this is a must in order to identify the reference as a content-id and not a relative location reference. I don't think I should worry about this as an application since the content-id is supposed from an application perspective be a handle to the attachment.
- Where does it state the when an attachment is created that it many not be automatically assigned a content-id? This is preferable since content-id's should be considered "global unique immutable" handle to the attachment and the previous logic did it's best to maintain this. -The logic before allowed me as a handler to just create the attachment and ask for it's content-id value and the use that in an href attribute to associate the attachment. Now to that I need to generate my own, and then set it? - As far as every example I have read every attachment should have a content-id value when sent regardless if it as being used to reference the attachment. Does this change now still do that? - Not a major point the content-id generation logic seems specific to attachments why has it been moved to SOAPUtils ? I still need to study this changes some more. As of right now I don't believe anything that was implemented before violated JAX-RPC or JAX-M specification. If this is the reason for changes, please I'd kindly appreciate pointing out the specific sections. If the changes are solely to facilitate TCK verification, then I argue logic prior to these change is a VALID and more appropriate implementation of the JAX-RPC and JAX-M specification with regard to providing useable attachment support and my position is to VOTE a -1 to these changes. Rick Rineholt "The truth is out there... All you need is a better search engine!" [EMAIL PROTECTED] [EMAIL PROTECTED] on 07/01/2002 04:01:40 PM Please respond to [EMAIL PROTECTED] To: [EMAIL PROTECTED] cc: Subject: cvs commit: xml-axis/java/test/saaj TestAttachment.java dims 2002/07/01 13:01:39 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: Fixes for SAAJ compliance. Revision Changes Path 1.18 +5 -24 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.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- AttachmentPart.java 1 Jul 2002 17:40:29 -0000 1.17 +++ AttachmentPart.java 1 Jul 2002 20:01:39 -0000 1.18 @@ -96,7 +96,6 @@ * Constructor AttachmentPart */ public AttachmentPart() { - addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, SOAPUtils.getNewContentIdValue()); } /** @@ -105,11 +104,9 @@ * @param dh */ public AttachmentPart(javax.activation.DataHandler dh) { - addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, - SOAPUtils.getNewContentIdValue()); datahandler = dh; if(dh != null) - addMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType()); + setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType()); } /** @@ -137,7 +134,7 @@ * @param value */ public void addMimeHeader(String header, String value) { - mimeHeaders.setHeader(header, value); + mimeHeaders.addHeader(header, value); } /** @@ -191,7 +188,7 @@ * @param loc */ public void setContentLocation(String loc) { - addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc); + setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc); } /** @@ -201,10 +198,7 @@ * @returns void */ public void setContentId(String newCid) { - if (newCid!=null && !newCid.toLowerCase().startsWith("cid:")) { - newCid = "cid:" + newCid; - } - addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid); + setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid); } /** @@ -213,20 +207,7 @@ * @return */ public String getContentId() { - 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; + return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID); } /** 1.22 +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.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- AttachmentsImpl.java 1 Jul 2002 17:40:29 -0000 1.21 +++ AttachmentsImpl.java 1 Jul 2002 20:01:39 -0000 1.22 @@ -223,7 +223,8 @@ Part removedPart = getAttachmentByReference(reference); if (removedPart != null) { - attachments.remove(removedPart.getContentId()); + if(removedPart.getContentId()!=null) + attachments.remove(removedPart.getContentId()); attachments.remove(removedPart.getContentLocation()); orderedAttachments.remove(removedPart); } @@ -250,7 +251,9 @@ mergeinAttachments(); - Part oldPart = (Part) attachments.put(newPart.getContentId(), newPart); + Part oldPart = null; + if(newPart.getContentId()!=null) + oldPart = (Part) attachments.put(newPart.getContentId(), newPart); if (oldPart != null) { orderedAttachments.remove(oldPart); @@ -475,6 +478,8 @@ 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())); } @@ -586,15 +591,10 @@ log.warn(JavaUtils.getMessage("exception00")); } - 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); - } - } + multipart = null; + dimemultipart = null; + attachments.clear(); + orderedAttachments.clear(); } /** 1.19 +4 -48 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- MimeUtils.java 1 Jul 2002 17:40:29 -0000 1.18 +++ MimeUtils.java 1 Jul 2002 20:01:39 -0000 1.19 @@ -267,12 +267,7 @@ javax.mail.internet.MimeMultipart multipart = null; try { - String rootCID = getNewContentIdValue(); - - if (rootCID.startsWith("cid:")) { - rootCID = rootCID.substring(4); - } - + String rootCID = org.apache.axis.utils.SOAPUtils.getNewContentIdValue(); multipart = new javax.mail.internet.MimeMultipart( "related; type=\"text/xml\"; start=\"<" + rootCID + ">\""); @@ -293,11 +288,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 (); @@ -337,44 +332,5 @@ } 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.4 +5 -1 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MultiPartDimeInputStream.java 1 Jul 2002 17:40:29 -0000 1.3 +++ MultiPartDimeInputStream.java 1 Jul 2002 20:01:39 -0000 1.4 @@ -101,6 +101,8 @@ 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) @@ -189,6 +191,8 @@ 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)) { @@ -202,7 +206,7 @@ AttachmentPart ap = new AttachmentPart(dh); if (contentId != null) - ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); + ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); addPart(contentId, "", ap); 1.18 +4 -18 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.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- MultiPartRelatedInputStream.java 1 Jul 2002 17:40:29 -0000 1.17 +++ MultiPartRelatedInputStream.java 1 Jul 2002 20:01:39 -0000 1.18 @@ -162,10 +162,6 @@ 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 @@ -239,12 +235,6 @@ } contentId = contentId.trim(); - - if (!contentId.startsWith("cid:")) { - contentId = - "cid:" - + contentId; // make sure its identified as cid - } } contentLocation = @@ -297,12 +287,12 @@ AttachmentPart ap = new AttachmentPart(dh); if (contentId != null) { - ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, + ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); } if (contentLocation != null) { - ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, + ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, contentLocation); } @@ -519,10 +509,6 @@ contentId.substring(0, contentId.length() - 1); } - if (!contentId.startsWith("cid:")) { - contentId = "cid:" + contentId; - } - contentId = contentId.trim(); } @@ -565,12 +551,12 @@ AttachmentPart ap = new AttachmentPart(dh); if (contentId != null) { - ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, + ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); } if (contentLocation != null) { - ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, + ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, contentLocation); } 1.13 +1 -0 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JAFDataHandlerSerializer.java 1 Jul 2002 17:40:31 -0000 1.12 +++ JAFDataHandlerSerializer.java 1 Jul 2002 20:01:39 -0000 1.13 @@ -111,6 +111,7 @@ //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.5 +1 -0 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MD5AttachTest.java 29 May 2002 14:30:02 -0000 1.4 +++ MD5AttachTest.java 1 Jul 2002 20:01:39 -0000 1.5 @@ -54,6 +54,7 @@ //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.30 +11 -27 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.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- SOAPPart.java 1 Jul 2002 17:40:29 -0000 1.29 +++ SOAPPart.java 1 Jul 2002 20:01:39 -0000 1.30 @@ -127,7 +127,7 @@ * object is." */ private Object currentMessage ; - + /** * Message object this part is tied to. Used for serialization settings. */ @@ -145,9 +145,7 @@ * "Just something to us working..." */ public SOAPPart(Message parent, Object initialContents, boolean isBodyStream) { - addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SOAPUtils.getNewContentIdValue()); - - + mimeHeaders.setHeader("Content-Type", "text/xml"); msgObject=parent; // originalMessage = initialContents; int form = FORM_STRING; @@ -171,7 +169,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; @@ -215,15 +213,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){ @@ -463,7 +461,7 @@ } setCurrentMessage(dser.getEnvelope(), FORM_SOAPENVELOPE); - + log.debug("Exit: SOAPPart::getAsSOAPEnvelope"); return (SOAPEnvelope)currentMessage; } @@ -472,7 +470,7 @@ * Add the specified MIME header, as per JAXM. */ public void addMimeHeader (String header, String value) { - mimeHeaders.setHeader(header, value); + mimeHeaders.addHeader(header, value); } /** @@ -501,7 +499,7 @@ * Set content location. */ public void setContentLocation(String loc) { - addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc); + setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc); } /** @@ -511,28 +509,14 @@ * @returns void */ public void setContentId(String newCid){ - if(newCid!=null && !newCid.toLowerCase().startsWith ("cid:")){ - newCid="cid:"+newCid; - } - addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid); + setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid); } /** * Content ID. */ public String getContentId() { - 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; + return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID); } 1.4 +1 -0 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestAttachment.java 24 Jun 2002 13:19:10 -0000 1.3 +++ TestAttachment.java 1 Jul 2002 20:01:39 -0000 1.4 @@ -19,6 +19,7 @@ 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";