whitlock 2003/03/31 06:05:50
Modified: java/test/mime MimeTest.java
java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFOperation_ApacheAxis.java MIMEHelper.java
java/src/org/apache/wsif/providers InvocationHelper.java
java/src/org/apache/wsif/providers/java
WSIFOperation_Java.java
Log:
Input-only and output unreferenced attachments
Revision Changes Path
1.27 +10 -5 xml-axis-wsif/java/test/mime/MimeTest.java
Index: MimeTest.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/mime/MimeTest.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- MimeTest.java 28 Mar 2003 14:41:51 -0000 1.26
+++ MimeTest.java 31 Mar 2003 14:05:48 -0000 1.27
@@ -453,9 +453,9 @@
doit("SOAPJMSPort", SEND_AP, "Mime.wsdl");
}
-// public void testInputOnlyUnrefJms() {
-// doit("SOAPJMSPort", INPUTONLY_UNREF, "Mime.wsdl");
-// }
+ public void testInputOnlyUnrefJms() {
+ doit("SOAPJMSPort", INPUTONLY_UNREF, "Mime.wsdl");
+ }
//
// public void testInputOnlyRefJms() {
// doit("SOAPJMSPort", INPUTONLY_REF, "Mime.wsdl");
@@ -1102,6 +1102,9 @@
// assertTrue(compareFiles(ap, rhyme[0]));
}
+ /**
+ * Tests unreferenced attachments on input-only operations
+ */
private void inputonly_unref(
String portName,
WSIFService service)
@@ -1109,11 +1112,13 @@
DataHandler dh = new DataHandler(new FileDataSource(flatfileLocation));
WSIFPort port = service.getPort(portName);
putUnref(port,dh);
- // DataHandler dh2 = getUnref(port); TODO: fix getUnref
- DataHandler dh2 = getRef(port);
+ DataHandler dh2 = getUnref(port);
assertTrue(compareFiles(dh, dh2));
}
+ /**
+ * Tests referenced attachments on input-only operations
+ */
private void inputonly_ref(String portName, WSIFService service)
throws Exception {
DataHandler dh = new DataHandler(new FileDataSource(flatfileLocation));
1.84 +85 -23
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.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- WSIFOperation_ApacheAxis.java 26 Mar 2003 12:48:54 -0000 1.83
+++ WSIFOperation_ApacheAxis.java 31 Mar 2003 14:05:49 -0000 1.84
@@ -60,10 +60,12 @@
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Vector;
import javax.jms.TextMessage;
@@ -1568,7 +1570,7 @@
setCallParameterNames(call);
Object[] inputValues = getInputMessageValues(inMsg, dest);
- addUnreferencedAttachments(inMsg, call);
+ addUnreferencedAttachments(call);
Object response = null;
boolean respOK = true;
@@ -1597,23 +1599,24 @@
// setJMSOutPropsInContext( dest ); TODO doesn't work yet
- if (!isAsyncOperation()
- && (outputSOAPParts.size() > 0 || outputMIMEParts.size() > 0) ) {
- Map callParams = call.getOutputParams();
- if (callParams != null) {
- HashMap outParams = new HashMap();
- QName qn;
- for (Iterator i = callParams.keySet().iterator();
- i.hasNext();
- ) {
- qn = (QName) i.next();
- outParams.put(qn.getLocalPart(),
callParams.get(qn));
- }
- setResponseMessageParameters(outParams);
- }
- respOK =
- buildResponseMessages(response, outMsg, faultMsg);
- }
+ if (!isAsyncOperation()) {
+ if (outputSOAPParts.size() > 0 || outputMIMEParts.size() > 0) {
+ Map callParams = call.getOutputParams();
+ if (callParams != null) {
+ HashMap outParams = new HashMap();
+ QName qn;
+ for (Iterator i = callParams.keySet().iterator();
+ i.hasNext();
+ ) {
+ qn = (QName) i.next();
+ outParams.put(qn.getLocalPart(), callParams.get(qn));
+ }
+ setResponseMessageParameters(outParams);
+ }
+ respOK = buildResponseMessages(response, outMsg, faultMsg);
+ }
+ setResponseUnreferencedAttachments(call, outMsg);
+ }
return respOK;
}
@@ -1739,7 +1742,7 @@
setCallParameterNames(call);
Object[] inputValues = getInputMessageValues(inMsg, null);
- addUnreferencedAttachments(inMsg, call);
+ addUnreferencedAttachments(call);
// invoke the AXIS call
Trc.event(this, "Invoking AXIS call", call, inputValues);
@@ -1780,6 +1783,7 @@
respOK =
buildResponseMessages(response, outMsg, faultMsg);
}
+ setResponseUnreferencedAttachments(call, outMsg);
}
return respOK;
@@ -1799,7 +1803,7 @@
boolean workedOK = false;
List attachments = addReferencedAttachments(inMsg, call);
- addUnreferencedAttachments(inMsg, call);
+ addUnreferencedAttachments(call);
Object[] inputValues = getInputMessageValues(inMsg, null);
ArrayList soapBodies = new ArrayList();
@@ -1834,6 +1838,7 @@
Trc.event(this, "Returned from AXIS invoke, response: ", axisResponse);
setOutputMessageValues(axisResponse, outMsg);
+ setResponseUnreferencedAttachments(call, outMsg);
workedOK = true;
return workedOK;
@@ -2280,11 +2285,11 @@
}
/**
- * adds all the unreferenced attachments to the AXIS call
+ * Adds all the unreferenced attachments to the AXIS call
*/
- private void addUnreferencedAttachments(WSIFMessage inMsg, Call call)
+ private void addUnreferencedAttachments(Call call)
throws WSIFException {
- Trc.entry(this, inMsg, call);
+ Trc.entry(this, call);
if (WSIFProperties.areUnreferencedAttachmentsSupported()) {
List l = null;
@@ -2306,6 +2311,63 @@
AttachmentPart ap = MIMEHelper.getAttachementPart(next);
call.addAttachmentPart(ap);
}
+ }
+ }
+
+ Trc.exit();
+ }
+
+ /**
+ * Sets all the output unreferenced attachments on the message context.
+ * The list of unreferenced attachments is calculated by discovering the
+ * Content-Id's of all the DataHandlers/WSIFAttachmentParts in the output
+ * message. Then the unreferenced attachments are all the attachments,
+ * excluding those that have a Content-Id that matches one in the list of
+ * referenced Content-Id's.
+ */
+ private void setResponseUnreferencedAttachments(
+ Call call,
+ WSIFMessage outMsg)
+ throws WSIFException {
+ Trc.entry(this, call, outMsg);
+
+ if (WSIFProperties.areUnreferencedAttachmentsSupported()) {
+ Set refCids = null;
+ List unrefAps = new ArrayList();
+ MessageContext mc = call.getMessageContext();
+ Message m = mc.getResponseMessage();
+ Iterator it = m.getAttachments();
+ while (it.hasNext()) {
+ Object o = it.next();
+ AttachmentPart ap = MIMEHelper.getAttachementPart(o);
+ String cid = ap.getContentId();
+ if (refCids == null) {
+ refCids = new HashSet();
+ Iterator mit = outMsg.getPartNames();
+ while (mit.hasNext()) {
+ String name = (String) mit.next();
+ Object part = outMsg.getObjectPart(name);
+ AttachmentPart refAp = null;
+ try {
+ refAp = MIMEHelper.getAttachementPart(part);
+ } catch (WSIFException we) {
+ Trc.ignoredException(we);
+ }
+ if (refAp != null) {
+ refCids.add(refAp.getContentId());
+ }
+ }
+ }
+ if (!refCids.contains(cid)) {
+ unrefAps.add(WSIFAXISUtils.axisToWsifAttachmentPart(ap));
+ }
+ }
+ if (!unrefAps.isEmpty()) {
+ WSIFMessage context = getContext();
+ context.setObjectPart(
+ WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME,
+ unrefAps);
+ setContext(context);
}
}
1.6 +13 -10
xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/MIMEHelper.java
Index: MIMEHelper.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/MIMEHelper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MIMEHelper.java 18 Mar 2003 14:49:00 -0000 1.5
+++ MIMEHelper.java 31 Mar 2003 14:05:49 -0000 1.6
@@ -113,18 +113,21 @@
return ok;
}
- public static AttachmentPart getAttachementPart(Object o) throws WSIFException {
- Trc.entry(null, o);
+ public static AttachmentPart getAttachementPart(Object o)
+ throws WSIFException {
+ Trc.entry(null, o);
AttachmentPart ap = null;
- if (o instanceof WSIFAttachmentPart) {
- ap = WSIFAXISUtils.wsifToAxisAttachmentPart((WSIFAttachmentPart)o);
- } else if (o instanceof DataHandler) {
+ if (o instanceof WSIFAttachmentPart) {
+ ap = WSIFAXISUtils.wsifToAxisAttachmentPart((WSIFAttachmentPart) o);
+ } else if (o instanceof DataHandler) {
ap = new AttachmentPart((DataHandler) o);
- } else {
- throw new WSIFException("Object is not a DataHandler: " + o);
- }
- Trc.exit(ap);
- return ap;
+ } else if (o instanceof AttachmentPart) {
+ ap = (AttachmentPart) o;
+ } else {
+ throw new WSIFException("Object is not a DataHandler: " + o);
+ }
+ Trc.exit(ap);
+ return ap;
}
public static void setMIMEMessagePart(
1.3 +1 -1
xml-axis-wsif/java/src/org/apache/wsif/providers/InvocationHelper.java
Index: InvocationHelper.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/InvocationHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InvocationHelper.java 28 Mar 2003 14:41:52 -0000 1.2
+++ InvocationHelper.java 31 Mar 2003 14:05:49 -0000 1.3
@@ -86,7 +86,7 @@
public static void setMessageContext(WSIFMessage ctxt)
throws WSIFException {
- Trc.entry(null);
+ Trc.entry(null, ctxt);
context.set(ctxt);
set = true;
Trc.exit();
1.42 +10 -2
xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java
Index: WSIFOperation_Java.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- WSIFOperation_Java.java 25 Mar 2003 08:48:53 -0000 1.41
+++ WSIFOperation_Java.java 31 Mar 2003 14:05:49 -0000 1.42
@@ -993,7 +993,11 @@
Trc.entry(this, input, output, fault);
close();
- InvocationHelper.setMessageContext(getContext());
+ WSIFMessage ctxt = getContext();
+ if (ctxt != null) {
+ InvocationHelper.setMessageContext(ctxt);
+ setContext(ctxt);
+ }
boolean operationSucceeded = true;
boolean usedOutputParam = false;
@@ -1453,7 +1457,11 @@
Trc.entry(this, input);
close();
- InvocationHelper.setMessageContext(getContext());
+ WSIFMessage ctxt = getContext();
+ if (ctxt != null) {
+ InvocationHelper.setMessageContext(ctxt);
+ setContext(ctxt);
+ }
try {
Object result = null;