antelder 2003/01/16 09:30:46
Modified: java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFOperation_ApacheAxis.java
Log:
Fix attachments with messaging to enable the attachment part be nested anywhere
within the input Element tree structure.
Previously attachment parts had to be in the top level of the Element, which they
are not always.
Also delete an old method which I noticed isn't used anymore
Revision Changes Path
1.62 +39 -109
xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java
Index: WSIFOperation_ApacheAxis.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFOperation_ApacheAxis.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- WSIFOperation_ApacheAxis.java 14 Jan 2003 17:29:50 -0000 1.61
+++ WSIFOperation_ApacheAxis.java 16 Jan 2003 17:30:46 -0000 1.62
@@ -1485,88 +1485,6 @@
}
}
- /**
- * This tells AXIS the name and type of the input, return, and output
parameters.
- */
- private void setCallParameterNames2(Call call) throws WSIFException {
-
- String inputNamespace = getInputNamespace();
- String outputNamespace = "";
-
- List soapParts;
- // style=wrapped uses the unwrapped parts
- if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
- soapParts = inputUnwrappedSOAPParts;
- } else {
- soapParts = inputSOAPParts;
- }
-
- // setup the input SOAP parts
- for (int i = 0; i < soapParts.size(); i++) {
- Part p = (Part) soapParts.get(i);
- String partName = p.getName();
- if (!inJmsProps.containsKey(partName)) {
- if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)) {
- QName qn = p.getElementName();
- if (qn != null) {
- partName = qn.getLocalPart();
- }
- }
- QName name = new QName(inputNamespace, partName);
- QName type = getPartType(p);
- call.addParameter(name, type, ParameterMode.IN);
- }
- }
-// // setup the input MIME parts
-// for (int i = 0; i < inputMIMEParts.size(); i++) {
-// Part p = (Part) inputMIMEParts.get(i);
-// QName name = new QName(inputNamespace, p.getName());
-// QName type = getPartType(p);
-// call.addParameter(name, type, ParameterMode.IN);
-// }
-
- // style=wrapped uses the unwrapped parts
- if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) {
- soapParts = outputUnwrappedSOAPParts;
- } else {
- soapParts = outputSOAPParts;
- }
-
- // setup the return part
- Part returnPart = null;
- if (soapParts.size() > 0) {
- returnPart = (Part)soapParts.get(0);
- }
-// } else if (outputMIMEParts.size() > 0) {
-// returnPart = (Part)outputMIMEParts.get(0);
-// }
- if (returnPart == null) {
- call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
- } else {
- QName type = getPartType(returnPart);
- call.setReturnType(type);
- }
-
- // setup output SOAP parts
- // from 1 to skip the return part
- for (int i = 1; i < soapParts.size(); i++) {
- Part p = (Part) soapParts.get(i);
- QName name = new QName(outputNamespace, p.getName());
- QName type = getPartType(p);
- call.addParameter(name, type, ParameterMode.OUT);
- }
-
-// // setup the output MIME parts
-// // if no soap parts dont add 1st as its the return part
-// int startMIMEIndex = (soapParts.size() > 0) ? 0 : 1;
-// for (int i = startMIMEIndex; i < outputMIMEParts.size(); i++) {
-// Part p = (Part) outputMIMEParts.get(i);
-// QName name = new QName(outputNamespace, p.getName());
-// QName type = getPartType(p);
-// call.addParameter(name, type, ParameterMode.OUT);
-// }
- }
-
/**
* Gets the type of a Part, if the Part doesn't have a type,
* then gets the Element name as WSIF treats this as the same thing.
@@ -1843,35 +1761,47 @@
*/
private void fixAttachmentPartsCID(Element body, List attachments) throws
WSIFException {
- NodeList childNodes = body.getChildNodes();
-
- /* this isn't so nice: the AttachentPart has no name
- * but I know they were added to the attachments list
- * in the same order as inputMIMEParts so I can get the
- * part name from there.
+ // find all the attachment Elements in the body
+ ArrayList al = new ArrayList();
+ getAttachmentElements(al, body);
+
+ /* this isn't so nice: the AttachmentPart has no name
+ * so we have to assume the the List is in the same
+ * order as the attachment Elements in the body.
*/
- int mimePartIndex = 0;
- for (Iterator i = attachments.iterator(); i.hasNext(); ) {
+ if (al.size() != attachments.size()) {
+ throw new WSIFException("unexpected number of attachments,"
+ + attachments.size() + " AttachmentParts, "
+ + al.size() + " attachment href elements");
+ }
+
+ // fiddle the cid: for each attachment
+ for (int i = 0; i < attachments.size(); i++ ) {
+ AttachmentPart attachment = (AttachmentPart) attachments.get(i);
+ Element attachmentElement = (Element) al.get(i);
+ attachmentElement.setAttribute("href", "cid:" +
attachment.getContentId());
+ }
+ }
- AttachmentPart attachment = (AttachmentPart) i.next();
- Part part = (Part) inputMIMEParts.get(mimePartIndex);
- String partName = part.getName();
-
- Element el = null;
- for(int j = 0; j < childNodes.getLength() && el == null; j++) {
- Node n = childNodes.item(j);
- if (partName.equals(n.getLocalName()) && n instanceof Element)
{
- el = (Element) n;
- el.setAttribute("href", "cid:" + attachment.getContentId());
- }
- }
-
- if (el == null) {
- throw new WSIFException(
- "could not find attachment part '"
- + partName
- + "' in body: "
- + body);
+ /**
+ * Gets all attachment Elements within an Element
+ * This recurses through the DOM tree structure adding any
+ * attachment Element's to the ArrayList.
+ * An attachment Element is one which has an href attribute
+ * which has a value starting with the String "cid:"
+ */
+ private static void getAttachmentElements(ArrayList al, Element el) {
+ NodeList childNodes = el.getChildNodes();
+ for (int j = 0; j < childNodes.getLength(); j++) {
+ Node n = childNodes.item(j);
+ if (n instanceof Element) {
+ Element childElement = (Element) n;
+ String s = childElement.getAttribute("href");
+ if (s != null && s.toLowerCase().startsWith("cid:")) {
+ al.add(childElement);
+ } else {
+ getAttachmentElements(al, childElement);
+ }
}
}
}