whitlock 2003/03/14 03:41:41
Modified: java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFAXISUtils.java
java/test/mime MimeTest.java MimeImplAxisHelper.java
MimeImpl.java
java/src/org/apache/wsif WSIFAttachmentPart.java
Log:
16993: fixes for unreferenced attachments
Revision Changes Path
1.3 +3 -2
xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFAXISUtils.java
Index: WSIFAXISUtils.java
===================================================================
RCS file:
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFAXISUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WSIFAXISUtils.java 12 Mar 2003 11:42:24 -0000 1.2
+++ WSIFAXISUtils.java 14 Mar 2003 11:41:40 -0000 1.3
@@ -59,6 +59,7 @@
import java.util.Iterator;
+import javax.xml.soap.MimeHeader;
import javax.xml.soap.SOAPException;
import org.apache.axis.attachments.AttachmentPart;
@@ -105,8 +106,8 @@
Iterator it = axisAp.getAllMimeHeaders();
while (it.hasNext()) {
- String name = (String) it.next();
- wsifAp.setProperty(name, axisAp.getMimeHeader(name)[0]);
+ MimeHeader mh = (MimeHeader) it.next();
+ wsifAp.setProperty(mh.getName(), mh.getValue());
}
Trc.exit(wsifAp);
1.19 +2 -64 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- MimeTest.java 13 Mar 2003 16:22:02 -0000 1.18
+++ MimeTest.java 14 Mar 2003 11:41:41 -0000 1.19
@@ -146,7 +146,6 @@
private final static String ARRAY_OF_BINARY = "ARRAY-OF-BINARY";
private final static String OPTIONAL_SOAP_BODY = "OPTIONAL_SOAP_BODY";
private final static String MIX_MIME_PARTS = "MIX_MIME_PARTS";
- private final static String UNREF = "UNREF";
private final static String SEND_UNREF_AP = "SEND_UNREF_AP";
private final static String SEND_AP = "SEND_AP";
private final static String RECEIVE_AP = "RECEIVE_AP";
@@ -360,10 +359,6 @@
doit(server + "Port", MIX_MIME_PARTS, "Mime.wsdl");
}
-// public void testUnrefHttp() {
-// doit(server + "Port", UNREF, "Mime.wsdl");
-// }
-//
public void testSendUnrefAttachmentPartHttp() {
doit(server + "Port", SEND_UNREF_AP, "Mime.wsdl");
}
@@ -604,8 +599,6 @@
optional_soap_body(service, stub);
else if (cmd.equals(MIX_MIME_PARTS))
mix_mime_parts(portName, service, stub);
- else if (cmd.equals(UNREF))
- unref(portName, service);
else if (cmd.equals(SEND_UNREF_AP))
send_unref_ap(portName, service);
else if (cmd.equals(SEND_AP))
@@ -972,62 +965,6 @@
assertTrue(expected.equals(s));
}
-// private void unref(String portName, WSIFService service) throws Exception {
-// DataHandler dh1 = new DataHandler(new FileDataSource(flatfileLocation));
-// DataHandler dh2 =
-// new DataHandler(new FileDataSource(flatfileLocation2));
-//
-// WSIFPort port = service.getPort(portName);
-// WSIFMessage context = port.getContext();
-// context.setObjectPart("file2", dh2);
-// port.setContext(context);
-// WSIFOperation op = port.createOperation("unref");
-// WSIFMessage in = op.createInputMessage();
-// WSIFMessage out = op.createOutputMessage();
-// WSIFMessage fault = op.createFaultMessage();
-// in.setObjectPart("file", dh1);
-//
-// boolean success = op.executeRequestResponseOperation(in, out, fault);
-// assertTrue(success);
-//
-// String buff = (String) (out.getObjectPart("buff"));
-// assertTrue(compareFiles(flatfileLocation, buff));
-// }
-//
-// private void send_unref_ap(String portName, WSIFService service)
-// throws Exception {
-// DataHandler dh1 = new DataHandler(new FileDataSource(flatfileLocation));
-// DataHandler dh2 =
-// new DataHandler(new FileDataSource(flatfileLocation2));
-// AttachmentPart ap = new AttachmentPart(dh2);
-// ap.setContentLocation("peculiar");
-//
-// WSIFPort port = service.getPort(portName);
-// WSIFMessage context = port.getContext();
-// context.setObjectPart("file2", ap);
-// port.setContext(context);
-// WSIFOperation op = port.createOperation("unref");
-// WSIFMessage in = op.createInputMessage();
-// WSIFMessage out = op.createOutputMessage();
-// WSIFMessage fault = op.createFaultMessage();
-// in.setObjectPart("file", dh1);
-//
-// boolean success = op.executeRequestResponseOperation(in, out, fault);
-// assertTrue(success);
-//
-// String buff = (String) (out.getObjectPart("buff"));
-// assertTrue(compareFiles(flatfileLocation, buff));
-// }
-
- private void unref(String portName, WSIFService service) throws Exception {
- assertTrue(false);
- // DataHandler dh1 = new DataHandler(new
FileDataSource(flatfileLocation));
- // DataHandler dh2 = new DataHandler(new
FileDataSource(flatfileLocation2));
- // Mime stub = (Mime) service.getStub(portName, Mime.class);
- // String buff = stub.unref(dh1, dh2);
- // assertTrue(compareFiles(flatfileLocation, buff));
- }
-
/**
* The send unreferenced attachment test needs axis on the server and
* needs wsif.unreferencedattachments=on in wsif.properties.
@@ -1056,7 +993,8 @@
assertTrue(success);
String buff = (String) (out.getObjectPart("buff"));
-
+ assertTrue(buff.startsWith("Content-Location=peculiar!"));
+ buff = buff.substring(buff.indexOf("!")+1);
assertTrue(compareFiles(flatfileLocation, buff));
}
1.2 +19 -6 xml-axis-wsif/java/test/mime/MimeImplAxisHelper.java
Index: MimeImplAxisHelper.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/mime/MimeImplAxisHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MimeImplAxisHelper.java 12 Mar 2003 11:42:24 -0000 1.1
+++ MimeImplAxisHelper.java 14 Mar 2003 11:41:41 -0000 1.2
@@ -58,38 +58,51 @@
package mime;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.activation.DataHandler;
+import javax.xml.soap.MimeHeader;
import org.apache.axis.AxisEngine;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.attachments.AttachmentPart;
+import org.apache.wsif.providers.soap.apacheaxis.WSIFAXISUtils;
/**
+ * This helper class encapsulates Axis-specific code that needs to be
+ * run from the backend Mime service. Most of the MimeImpl service is
+ * common to soap and axis and only the parts that are axis-specific are
+ * separated out into this helper, to allow the other parts to run under
+ * a soap server.
+ *
* @author Mark Whitlock
*/
public class MimeImplAxisHelper {
- private MimeImplAxisHelper(){}
-
+ private MimeImplAxisHelper() {
+ }
+
+ /**
+ * getUnreferencedAttachments returns a list of DataHandlers and
+ * a list of maps of the mime headers that were set on those attachments.
+ */
public static List getUnreferencedAttachments() throws Exception {
- ArrayList al = new ArrayList();
MessageContext mc = AxisEngine.getCurrentMessageContext();
Message m = mc.getRequestMessage();
+ ArrayList waps = new ArrayList();
Iterator it = m.getAttachments();
while (it.hasNext()) {
Object next = it.next();
if (next instanceof AttachmentPart) {
AttachmentPart ap = (AttachmentPart) next;
- DataHandler dh = ap.getDataHandler();
- al.add(dh);
+ waps.add(WSIFAXISUtils.axisToWsifAttachmentPart(ap));
}
}
- return al;
+ return waps;
}
}
1.13 +9 -10 xml-axis-wsif/java/test/mime/MimeImpl.java
Index: MimeImpl.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/mime/MimeImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MimeImpl.java 13 Mar 2003 16:22:02 -0000 1.12
+++ MimeImpl.java 14 Mar 2003 11:41:41 -0000 1.13
@@ -63,7 +63,7 @@
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
+import java.util.Map;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
@@ -255,15 +255,7 @@
Method m = c.getMethod("getUnreferencedAttachments",null);
Object o = m.invoke(null,null);
List ua = (List)o;
-
- ListIterator it = ua.listIterator();
- while (it.hasNext()) {
- Object next = it.next();
- if (next instanceof DataHandler) {
- DataHandler dh = (DataHandler) next;
- s = s + dataHandlerToString(dh);
- }
- }
+ s = unref(ua);
} catch (Exception e) {
System.err.println("MimeImpl.unref==>" + e);
e.printStackTrace();
@@ -282,6 +274,13 @@
Object next = it.next();
if (next instanceof WSIFAttachmentPart) {
WSIFAttachmentPart wap = (WSIFAttachmentPart) next;
+
+ if (wap.containsProperty("Content-Location")) {
+ s = s + "Content-Location="
+ + wap.getProperty("Content-Location")
+ + "!";
+ }
+
DataHandler dh = wap.getDataHandler();
s = s + dataHandlerToString(dh);
}
1.3 +7 -0 xml-axis-wsif/java/src/org/apache/wsif/WSIFAttachmentPart.java
Index: WSIFAttachmentPart.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/WSIFAttachmentPart.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WSIFAttachmentPart.java 12 Mar 2003 11:42:42 -0000 1.2
+++ WSIFAttachmentPart.java 14 Mar 2003 11:41:41 -0000 1.3
@@ -119,6 +119,13 @@
return value;
}
+ public boolean containsProperty(String name) {
+ Trc.entry(this, name);
+ boolean ok = properties.containsKey(name);
+ Trc.exit(ok);
+ return ok;
+ }
+
public Iterator getPropertyIterator() {
Trc.entry(this);
Iterator it = properties.keySet().iterator();