Author: alex.guizar(a)jboss.com
Date: 2007-03-27 01:05:34 -0400 (Tue, 27 Mar 2007)
New Revision: 2690
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageImpl.java
Log:
JBCTS-468 implemented SAAJ 1.3 methods in SOAPMessage
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageImpl.java 2007-03-27
04:02:27 UTC (rev 2689)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPMessageImpl.java 2007-03-27
05:05:34 UTC (rev 2690)
@@ -41,7 +41,6 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
-import org.jboss.util.NotImplementedException;
import org.jboss.ws.WSException;
import org.jboss.ws.core.soap.attachment.AttachmentPartImpl;
import org.jboss.ws.core.soap.attachment.CIDGenerator;
@@ -142,13 +141,14 @@
String contentId = part.getContentId();
if (contentId.equals(cid))
{
- attachments.remove(part);
- return part;
+ attachments.remove(part);
+ return part;
}
}
return null;
}
+
public AttachmentPart getAttachmentByPartName(String partName)
{
for (AttachmentPart part : attachments)
@@ -428,14 +428,74 @@
@Override
public AttachmentPart getAttachment(SOAPElement element) throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ String ref = element.getAttribute("href");
+
+ if (ref.length() == 0)
+ {
+ ref = element.getValue();
+ if (ref == null || ref.length() == 0)
+ return null;
+ }
+
+ return getAttachmentByRef(ref);
}
+ private AttachmentPart getAttachmentByRef(String ref) throws SOAPException
+ {
+ AttachmentPart attachment;
+ if (ref.startsWith("cid:"))
+ {
+ /* SwA 2000-12-11 section 3: if a Content-ID header is present, then an absolute
URI
+ * label for the part is formed using the CID URI scheme
+ *
+ * WS-I AP 1.0 section 3.5: when using the CID URI scheme, the syntax and rules
defined
+ * in RFC 2392 apply.
+ */
+ String cid = '<' + ref.substring("cid:".length()) +
'>';
+ attachment = getAttachmentByContentId(cid);
+ }
+ else
+ {
+ /* SwA 2000-12-11 section 3: If a Content-Location header is present with an
absolute URI
+ * value then that URI is a label for the part
+ */
+ attachment = getAttachmentByContentLocation(ref);
+ }
+
+ if (attachment == null)
+ {
+ // autogenerated CID based on part name
+ attachment = getAttachmentByPartName(ref);
+ }
+
+ return attachment;
+ }
+
+ /**
+ * Looks for the first {@linkplain AttachmentPart attachment} where the
+ * {@linkplain AttachmentPart#getContentLocation() content location} matches the
+ * given <code>location</code>.
+ * @param location the content location to match
+ * @return the matching attachment or <code>null</code> if no match was
found
+ */
+ private AttachmentPart getAttachmentByContentLocation(String location)
+ {
+ for (AttachmentPart attachment : attachments)
+ {
+ if (location.equals(attachment.getContentLocation()))
+ return attachment;
+ }
+ return null;
+ }
+
@Override
public void removeAttachments(MimeHeaders headers)
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ /* this code exploits the fact that MimeMatchingAttachmentsIterator.next() returns
null
+ * rather than throwing an exception when there are no more elements
+ */
+ Iterator attachmentItr = new MimeMatchingAttachmentsIterator(headers,
attachments);
+ while (attachmentItr.next() != null)
+ attachmentItr.remove();
}
}
Show replies by date