You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by wh...@apache.org on 2003/03/07 16:38:39 UTC
cvs commit: xml-axis-wsif/java/src/org/apache/wsif WSIFAttachmentPart.java
whitlock 2003/03/07 07:38:39
Modified: java/src/org/apache/wsif/providers/soap/apacheaxis
MIMEHelper.java
java/test/mime MimeTest.java
Added: java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFAXISUtils.java
java/src/org/apache/wsif WSIFAttachmentPart.java
Log:
16993: create WSIFAttachmentPart
Revision Changes Path
1.4 +3 -2 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MIMEHelper.java 6 Mar 2003 10:10:27 -0000 1.3
+++ MIMEHelper.java 7 Mar 2003 15:38:38 -0000 1.4
@@ -75,6 +75,7 @@
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
+import org.apache.wsif.WSIFAttachmentPart;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.logging.Trc;
@@ -115,8 +116,8 @@
public static AttachmentPart getAttachementPart(Object o) throws WSIFException {
Trc.entry(null, o);
AttachmentPart ap = null;
- if (o instanceof AttachmentPart) {
- ap = (AttachmentPart)o;
+ if (o instanceof WSIFAttachmentPart) {
+ ap = WSIFAXISUtils.wsifToAxisAttachmentPart((WSIFAttachmentPart)o);
} else if (o instanceof DataHandler) {
ap = new AttachmentPart((DataHandler) o);
} else {
1.1 xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/WSIFAXISUtils.java
Index: WSIFAXISUtils.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.providers.soap.apacheaxis;
import java.util.Iterator;
import javax.xml.soap.SOAPException;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.wsif.WSIFAttachmentPart;
import org.apache.wsif.WSIFException;
import org.apache.wsif.logging.Trc;
/**
* Utility class to convert between WSIFAttachmentParts and Axis AttachmentParts.
*
* @author Mark Whitlock
*/
public class WSIFAXISUtils {
public static AttachmentPart wsifToAxisAttachmentPart(WSIFAttachmentPart wsifAp)
throws WSIFException {
Trc.entry(null, wsifAp);
AttachmentPart axisAp = new AttachmentPart(wsifAp.getDataHandler());
Iterator it = wsifAp.getMimeHeaderIterator();
while (it.hasNext()) {
String name = (String) it.next();
axisAp.addMimeHeader(name, wsifAp.getMimeHeader(name));
}
Trc.exit(axisAp);
return axisAp;
}
public static WSIFAttachmentPart axisToWsifAttachmentPart(AttachmentPart axisAp)
throws WSIFException {
Trc.entry(null, axisAp);
WSIFAttachmentPart wsifAp = null;
try {
wsifAp = new WSIFAttachmentPart(axisAp.getDataHandler());
} catch (SOAPException se) {
Trc.exception(se);
throw new WSIFException(
"Could not convert WSIFAttachmentPart to Axis AttachmentPart. "
+ se);
}
Iterator it = axisAp.getAllMimeHeaders();
while (it.hasNext()) {
String name = (String) it.next();
wsifAp.setMimeHeader(name, axisAp.getMimeHeader(name)[0]);
}
Trc.exit(wsifAp);
return wsifAp;
}
}
1.16 +3 -3 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MimeTest.java 7 Mar 2003 14:15:58 -0000 1.15
+++ MimeTest.java 7 Mar 2003 15:38:39 -0000 1.16
@@ -77,7 +77,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.apache.axis.attachments.AttachmentPart;
+import org.apache.wsif.WSIFAttachmentPart;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
@@ -1009,8 +1009,8 @@
throws Exception {
DataHandler dh1 = new DataHandler(new FileDataSource(flatfileLocation));
DataHandler dh2 = new DataHandler(new FileDataSource(flatfileLocation2));
- AttachmentPart ap = new AttachmentPart(dh1);
- ap.setContentLocation("peculiar");
+ WSIFAttachmentPart ap = new WSIFAttachmentPart(dh1);
+ ap.setMimeHeader("Content-Location","peculiar");
WSIFPort port = service.getPort(portName);
WSIFOperation op = port.createOperation("unref");
1.1 xml-axis-wsif/java/src/org/apache/wsif/WSIFAttachmentPart.java
Index: WSIFAttachmentPart.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.activation.DataHandler;
import org.apache.wsif.logging.Trc;
/**
* WSIFAttachmentPart is a MIME attachment that is described in a binding
* independent way.
*
* @author Mark Whitlock
*/
public class WSIFAttachmentPart /* implements Serializable */ {
private static final long serialVersionUID = 1L;
private transient DataHandler dh;
private Map mimeHeaders;
public WSIFAttachmentPart() {
Trc.entry(this);
this.dh = null;
this.mimeHeaders = new HashMap();
Trc.exit();
}
public WSIFAttachmentPart(DataHandler dh) {
Trc.entry(this, dh);
this.dh = dh;
this.mimeHeaders = new HashMap();
Trc.exit();
}
public WSIFAttachmentPart(DataHandler dh, Map mimeHeaders)
throws WSIFException {
Trc.entry(this, dh, mimeHeaders);
validateMimeHeaders(mimeHeaders);
this.dh = dh;
this.mimeHeaders = mimeHeaders;
Trc.exit();
}
public void setMimeHeader(String name, String value) throws WSIFException {
Trc.entry(this, name, value);
mimeHeaders.put(name, value);
Trc.exit();
}
public void setMimeHeaders(Map mimeHeaders) throws WSIFException {
Trc.entry(this, mimeHeaders);
validateMimeHeaders(mimeHeaders);
mimeHeaders.putAll(mimeHeaders);
Trc.exit();
}
public String getMimeHeader(String name) {
Trc.entry(this, name);
String value = (String) mimeHeaders.get(name);
Trc.exit(value);
return value;
}
public Iterator getMimeHeaderIterator() {
Trc.entry(this);
Iterator it = mimeHeaders.keySet().iterator();
Trc.exit(it);
return it;
}
public void clearMimeHeaders() {
Trc.entry(this);
mimeHeaders = new HashMap();
Trc.exit();
}
public DataHandler getDataHandler() {
Trc.entry(this);
Trc.exit(dh);
return dh;
}
public void setDataHandler(DataHandler dh) {
Trc.entry(this, dh);
this.dh = dh;
Trc.exit();
}
private void validateMimeHeaders(Map mimeHeaders) throws WSIFException {
Trc.entry(this, mimeHeaders);
Iterator it = mimeHeaders.keySet().iterator();
while (it.hasNext()) {
String next = (String) it.next();
if (!(mimeHeaders.get(next) instanceof String))
throw new WSIFException(
"mimeHeader " + next + " was not a String.");
}
Trc.exit();
}
// /**
// * Override default deserialization
// */
// private void writeObject(ObjectOutputStream oos) throws IOException {
// Trc.entry(this, oos);
// oos.defaultWriteObject();
// writeOutDh(oos);
// oos.flush();
// Trc.exit();
// }
//
// /**
// * Override default deserialization
// */
// private void readObject(ObjectInputStream ois)
// throws ClassNotFoundException, IOException {
// Trc.entry(this, ois);
// ois.defaultReadObject();
// dh = convertDh(ois.readObject());
// Trc.exit();
// }
//
// private DataHandler convertDh(Object o) {
// return null;
// }
//
// private void writeOutDh(ObjectOutputStream oos) {
// }
}