whitlock 2003/03/28 06:41:52
Modified: java/test/mime Mime.wsdl MimeTest.java
MimeImplAxisHelper.java Mime.java MimeImpl.java
java/src/org/apache/wsif/providers InvocationHelper.java
Log:
Test attachments on input-only operations
Revision Changes Path
1.17 +135 -0 xml-axis-wsif/java/test/mime/Mime.wsdl
Index: Mime.wsdl
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/mime/Mime.wsdl,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Mime.wsdl 19 Mar 2003 17:11:36 -0000 1.16
+++ Mime.wsdl 28 Mar 2003 14:41:51 -0000 1.17
@@ -164,6 +164,20 @@
<input message="tns:NullMessage"/>
<output message="tns:StringMessage"/>
</operation>
+ <operation name="putRefDhInputOnly">
+ <input message="tns:DataHandlerMessage"/>
+ </operation>
+ <operation name="getRefDh">
+ <input message="tns:NullMessage"/>
+ <output message="tns:DataHandlerMessage"/>
+ </operation>
+ <operation name="putUnrefDhInputOnly">
+ <input message="tns:NullMessage"/>
+ </operation>
+ <operation name="getUnrefDh">
+ <input message="tns:NullMessage"/>
+ <output message="tns:NullMessage"/>
+ </operation>
</portType>
<!-- binding declns -->
@@ -589,6 +603,56 @@
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
+
+ <operation name="putRefDhInputOnly">
+ <soap:operation soapAction=""/>
+ <input>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="file" type="text/html"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </input>
+ </operation>
+
+ <operation name="getRefDh">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ <output>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="file" type="text/html"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </output>
+ </operation>
+
+ <operation name="putUnrefDhInputOnly">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ </operation>
+
+ <operation name="getUnrefDh">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ <output>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </output>
+ </operation>
</binding>
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
@@ -1013,6 +1077,56 @@
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
+
+ <operation name="putRefDhInputOnly">
+ <soap:operation soapAction=""/>
+ <input>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="file" type="text/html"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </input>
+ </operation>
+
+ <operation name="getRefDh">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ <output>
+ <mime:multipartRelated>
+ <mime:part>
+ <mime:content part="file" type="text/html"/>
+ </mime:part>
+ </mime:multipartRelated>
+ </output>
+ </operation>
+
+ <operation name="putUnrefDhInputOnly">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ </operation>
+
+ <operation name="getUnrefDh">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </input>
+ <output>
+ <soap:body use="encoded"
+ namespace="http://mime/"
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
+ </output>
+ </operation>
</binding>
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
@@ -1048,6 +1162,27 @@
<operation name="unref">
<java:operation
methodName="unref"
+ methodType="instance" />
+ <input/>
+ <output/>
+ </operation>
+ <operation name="putUnrefDhInputOnly">
+ <java:operation
+ methodName="putUnrefDhInputOnly"
+ methodType="instance" />
+ <input/>
+ <output/>
+ </operation>
+ <operation name="getUnrefDh">
+ <java:operation
+ methodName="getUnrefDh"
+ methodType="instance" />
+ <input/>
+ <output/>
+ </operation>
+ <operation name="getRefDh">
+ <java:operation
+ methodName="getRefDh"
methodType="instance" />
<input/>
<output/>
1.26 +108 -0 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- MimeTest.java 20 Mar 2003 16:15:20 -0000 1.25
+++ MimeTest.java 28 Mar 2003 14:41:51 -0000 1.26
@@ -152,6 +152,8 @@
private final static String MIX_MIME_PARTS = "MIX_MIME_PARTS";
private final static String SEND_UNREF_AP = "SEND_UNREF_AP";
private final static String SEND_UNREF_AP_LOTS = "SEND_UNREF_AP_LOTS";
+ private final static String INPUTONLY_UNREF = "INPUTONLY_UNREF";
+ private final static String INPUTONLY_REF = "INPUTONLY_REF";
private final static String SEND_AP = "SEND_AP";
private final static String RECEIVE_AP = "RECEIVE_AP";
private final static String MAP_TYPE = "MAP-TYPE";
@@ -347,6 +349,14 @@
// doit(server + "Port", RECEIVE_AP, "Mime.wsdl");
// }
+ public void testInputOnlyUnrefHttp() {
+ doit(server + "Port", INPUTONLY_UNREF, "Mime.wsdl");
+ }
+
+ public void testInputOnlyRefHttp() {
+ doit(server + "Port", INPUTONLY_REF, "Mime.wsdl");
+ }
+
/* ***************************************************/
/* AXIS/JMS tests */
/* ***************************************************/
@@ -443,6 +453,14 @@
doit("SOAPJMSPort", SEND_AP, "Mime.wsdl");
}
+// public void testInputOnlyUnrefJms() {
+// doit("SOAPJMSPort", INPUTONLY_UNREF, "Mime.wsdl");
+// }
+//
+// public void testInputOnlyRefJms() {
+// doit("SOAPJMSPort", INPUTONLY_REF, "Mime.wsdl");
+// }
+
/* ***************************************************/
/* Java tests */
/* ***************************************************/
@@ -467,6 +485,10 @@
doit("JavaPort", SEND_AP, "Mime.wsdl");
}
+ public void testInputOnlyUnrefJava() {
+ doit("JavaPort", INPUTONLY_UNREF, "Mime.wsdl");
+ }
+
/* ***************************************************/
/* ERROR tests */
/* ***************************************************/
@@ -611,6 +633,10 @@
send_ap(portName, service);
else if (cmd.equals(RECEIVE_AP))
receive_ap(service, stub);
+ else if (cmd.equals(INPUTONLY_REF))
+ inputonly_ref(portName, service);
+ else if (cmd.equals(INPUTONLY_UNREF))
+ inputonly_unref(portName, service);
else if (cmd.equals(BAD_NO_PART))
bad_no_part(portName, service);
else if (cmd.equals(BAD_PART))
@@ -1076,6 +1102,88 @@
// assertTrue(compareFiles(ap, rhyme[0]));
}
+ private void inputonly_unref(
+ String portName,
+ WSIFService service)
+ throws Exception {
+ 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);
+ assertTrue(compareFiles(dh, dh2));
+ }
+
+ private void inputonly_ref(String portName, WSIFService service)
+ throws Exception {
+ DataHandler dh = new DataHandler(new FileDataSource(flatfileLocation));
+ WSIFPort port = service.getPort(portName);
+ putRef(port,dh);
+ DataHandler dh2 = getRef(port);
+ assertTrue(compareFiles(dh, dh2));
+ }
+
+ private void putUnref(WSIFPort port, DataHandler dh) throws Exception {
+ WSIFAttachmentPart ap = new WSIFAttachmentPart(dh);
+ List apList = new ArrayList(Arrays.asList(new Object[] { ap }));
+
+ WSIFOperation op = port.createOperation("putUnrefDhInputOnly");
+ WSIFMessage in = op.createInputMessage();
+
+ WSIFMessage context = op.getContext();
+ context.setObjectPart(
+ WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME,
+ apList);
+ op.setContext(context);
+
+ op.executeInputOnlyOperation(in);
+ }
+
+ private DataHandler getUnref(WSIFPort port) throws Exception {
+ WSIFOperation op = port.createOperation("getUnrefDh");
+ WSIFMessage in = op.createInputMessage();
+ WSIFMessage out = op.createOutputMessage();
+ WSIFMessage fault = op.createFaultMessage();
+
+ boolean success = op.executeRequestResponseOperation(in, out, fault);
+ assertTrue(success);
+
+ WSIFMessage context = op.getContext();
+ List apList =
+ (List) context.getObjectPart(
+ WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME);
+ WSIFAttachmentPart ap = (WSIFAttachmentPart) apList.get(0);
+ DataHandler dh = ap.getDataHandler();
+ return dh;
+ }
+
+ private void putRef(WSIFPort port, DataHandler dh) throws Exception {
+ WSIFAttachmentPart ap = new WSIFAttachmentPart(dh);
+ WSIFOperation op = port.createOperation("putRefDhInputOnly");
+ WSIFMessage in = op.createInputMessage();
+ in.setObjectPart("file", ap);
+ op.executeInputOnlyOperation(in);
+ }
+
+ private DataHandler getRef(WSIFPort port) throws Exception {
+ WSIFOperation op = port.createOperation("getRefDh");
+ WSIFMessage in = op.createInputMessage();
+ WSIFMessage out = op.createOutputMessage();
+ WSIFMessage fault = op.createFaultMessage();
+
+ boolean success = op.executeRequestResponseOperation(in, out, fault);
+ assertTrue(success);
+
+ Object o = out.getObjectPart("file");
+ DataHandler dh = null;
+ if (o instanceof DataHandler) {
+ dh = (DataHandler)o;
+ } else if (o instanceof WSIFAttachmentPart) {
+ dh = ((WSIFAttachmentPart) o).getDataHandler();
+ }
+ return dh;
+ }
+
/* *********************** ERRORS ********************************** */
private void bad_no_part(String portName, WSIFService service)
1.3 +24 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MimeImplAxisHelper.java 14 Mar 2003 11:41:41 -0000 1.2
+++ MimeImplAxisHelper.java 28 Mar 2003 14:41:51 -0000 1.3
@@ -58,17 +58,14 @@
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.attachments.WSIFAttachmentPart;
import org.apache.wsif.providers.soap.apacheaxis.WSIFAXISUtils;
/**
@@ -103,6 +100,29 @@
}
}
return waps;
+ }
+
+ /**
+ *
+ */
+ public static void putUnreferencedAttachments(List waps) throws Exception {
+ System.out.println("putUnreferencedAttachments entry");
+ MessageContext mc = AxisEngine.getCurrentMessageContext();
+ Message m = mc.getResponseMessage();
+
+ Iterator it = waps.iterator();
+ while (it.hasNext()) {
+ Object next = it.next();
+ if (next instanceof WSIFAttachmentPart) {
+ WSIFAttachmentPart wap = (WSIFAttachmentPart) next;
+ System.out.println("putUnreferencedAttachments found " + wap);
+ m.addAttachmentPart(
+ WSIFAXISUtils.wsifToAxisAttachmentPart(wap));
+ }
+
+ }
+ System.out.println("putUnreferencedAttachments exit");
+
}
}
1.13 +5 -0 xml-axis-wsif/java/test/mime/Mime.java
Index: Mime.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/mime/Mime.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Mime.java 18 Mar 2003 14:49:00 -0000 1.12
+++ Mime.java 28 Mar 2003 14:41:51 -0000 1.13
@@ -106,6 +106,11 @@
// public String unref(DataHandler dh1, DataHandler dh2);
public String dataHandlerToString(WSIFAttachmentPart ap);
+ public void putRefDhInputOnly(DataHandler dh);
+ public DataHandler getRefDh();
+ public void putUnrefDhInputOnly();
+ public void getUnrefDh();
+
public String badNoPart(DataHandler dh) throws Exception;
public String badPart(DataHandler dh) throws Exception;
public String badNested(DataHandler dh) throws Exception;
1.19 +132 -21 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- MimeImpl.java 20 Mar 2003 16:15:20 -0000 1.18
+++ MimeImpl.java 28 Mar 2003 14:41:51 -0000 1.19
@@ -60,7 +60,10 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -79,6 +82,8 @@
public class MimeImpl {
private static final boolean verbose = false;
+ private String stored = null;
+ private String errText = null;
public String dataHandlerToString(DataHandler dh) {
try {
@@ -269,27 +274,7 @@
}
public String unref() {
- String errText = null;
- List l = null;
- try {
- WSIFMessage context = InvocationHelper.getMessageContext();
- l =
- (List) context.getObjectPart(
- WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME);
- } catch (Exception e) {
- errText += e.toString() + "\n";
- }
-
- if (l == null) {
- try {
- Class c = Class.forName("mime.MimeImplAxisHelper");
- Method m = c.getMethod("getUnreferencedAttachments", null);
- Object o = m.invoke(null, null);
- l = (List) o;
- } catch (Exception e) {
- errText += e.toString() + "\n";
- }
- }
+ List l = getUnrefAttachments();
String s = new String();
try {
@@ -321,6 +306,71 @@
return s;
}
+ public void putRefDhInputOnly(DataHandler dh) {
+ if (verbose)
+ System.out.println(
+ "MimeImpl.putRefDhInputOnly dh="
+ + (dh == null ? "<null>" : dh.toString()));
+
+ this.stored = dataHandlerToString(dh);
+
+ if (verbose)
+ System.out.println(
+ "MimeImpl.putRefDhInputOnly stored="
+ + (stored == null ? "<null>" : stored));
+ }
+
+ public DataHandler getRefDh() {
+ if (verbose)
+ System.out.println(
+ "MimeImpl.getRefDh stored="
+ + (stored == null ? "<null>" : stored));
+
+ DataHandler dh = stringToDataHandler(this.stored);
+
+ if (verbose)
+ System.out.println(
+ "MimeImpl.getRefDh dh="
+ + (dh == null ? "<null>" : dh.toString()));
+ return dh;
+ }
+
+ public void putUnrefDhInputOnly() {
+ List l = getUnrefAttachments();
+ DataHandler dh = ((WSIFAttachmentPart) l.get(0)).getDataHandler();
+ this.stored = dataHandlerToString(dh);
+
+ if (verbose)
+ System.out.println(
+ "MimeImpl.putUnrefDhInputOnly stored="
+ + (stored == null ? "<null>" : stored));
+ }
+
+ public void getUnrefDh() {
+ if (verbose)
+ System.out.println(
+ "MimeImpl.getUnrefDh stored="
+ + (stored == null ? "<null>" : stored));
+
+ WSIFAttachmentPart wap =
+ new WSIFAttachmentPart(stringToDataHandler(stored));
+ ArrayList l = new ArrayList();
+ l.add(wap);
+ if (!putUnrefAttachments(l)) {
+ System.err.println("getUnrefDh failed " + errText);
+ }
+ }
+
+// public void getUnrefDh() {
+// MessageContext mc = AxisEngine.getCurrentMessageContext();
+// Message m = mc.getResponseMessage();
+// PlainTextDataSource ptds =
+// new PlainTextDataSource("UnrefAttachment", "Hello!");
+// DataHandler dh = new DataHandler(ptds);
+// AttachmentPart ap = new AttachmentPart(dh);
+// m.addAttachmentPart(ap);
+// }
+
/* ******************* ERRORS *********************** */
public String badNoPart(DataHandler dh) {
@@ -353,5 +403,66 @@
File f = File.createTempFile("WSIFMimeTest", "."+type);
f.deleteOnExit();
return new FileDataSource(f);
+ }
+
+ private List getUnrefAttachments() {
+ List l = null;
+ errText = new String();
+ try {
+ WSIFMessage context = InvocationHelper.getMessageContext();
+ l =
+ (List) context.getObjectPart(
+ WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME);
+ } catch (Exception e) {
+ errText += e.toString() + "\n";
+ }
+
+ if (l == null) {
+ try {
+ Class c = Class.forName("mime.MimeImplAxisHelper");
+ Method m = c.getMethod("getUnreferencedAttachments", null);
+ Object o = m.invoke(null, null);
+ l = (List) o;
+ } catch (Exception e) {
+ errText += e.toString() + "\n";
+ }
+ }
+ return l;
+ }
+
+ private boolean putUnrefAttachments(List l) {
+ errText = new String();
+ boolean success = true;
+
+ try {
+ WSIFMessage context = InvocationHelper.getMessageContext();
+ context.setObjectPart(
+ WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME,
+ l);
+ } catch (Exception e) {
+ success = false;
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ errText += "Java attempt failed with " + sw.toString() + "\n";
+ }
+
+ if (!success) {
+ try {
+ Class c = Class.forName("mime.MimeImplAxisHelper");
+ Method m =
+ c.getMethod(
+ "putUnreferencedAttachments",
+ new Class[] { List.class });
+ m.invoke(null, new Object[] { l });
+ success = true;
+ } catch (Exception e) {
+ success = false;
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ errText += "Axis attempt failed with " + sw.toString() + "\n";
+ }
+ }
+
+ return success;
}
}
1.2 +26 -11
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvocationHelper.java 18 Mar 2003 15:09:30 -0000 1.1
+++ InvocationHelper.java 28 Mar 2003 14:41:52 -0000 1.2
@@ -67,20 +67,35 @@
* @author Mark Whitlock
*/
public class InvocationHelper {
- transient private static ThreadLocal context = new ThreadLocal();
-
- private InvocationHelper() {}
-
- public static WSIFMessage getMessageContext() {
+ private static ThreadLocal context = new ThreadLocal();
+ private static boolean set = false;
+
+ private InvocationHelper() {
+ }
+
+ public static WSIFMessage getMessageContext() throws WSIFException {
Trc.entry(null);
- WSIFMessage ctxt = (WSIFMessage)context.get();
+ if (!set) {
+ throw new WSIFException("Message context not set");
+ }
+
+ WSIFMessage ctxt = (WSIFMessage) context.get();
Trc.exit(ctxt);
return ctxt;
}
-
- public static void setMessageContext(WSIFMessage ctxt) throws WSIFException {
- Trc.entry(null);
- context.set(ctxt);
- Trc.exit();
+
+ public static void setMessageContext(WSIFMessage ctxt)
+ throws WSIFException {
+ Trc.entry(null);
+ context.set(ctxt);
+ set = true;
+ Trc.exit();
+ }
+
+ public static void unsetMessageContext()
+ throws WSIFException {
+ Trc.entry(null);
+ set = false;
+ Trc.exit();
}
}