antelder 2002/12/16 09:54:17
Modified: java/src/org/apache/wsif/providers/soap/apacheaxis
WSIFOperation_ApacheAxis.java
Added: java/src/org/apache/wsif/providers/soap/apacheaxis
MIMEHelper.java
Log:
Fix AXIS provider to:
- allow attachements with messaging operations
- remove depedancy on mail and activation jars when not using attachments
Revision Changes Path
1.48 +26 -120
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.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- WSIFOperation_ApacheAxis.java 16 Dec 2002 09:24:16 -0000 1.47
+++ WSIFOperation_ApacheAxis.java 16 Dec 2002 17:54:16 -0000 1.48
@@ -57,9 +57,6 @@
package org.apache.wsif.providers.soap.apacheaxis;
-import java.awt.Image;
-import java.io.IOException;
-import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -68,11 +65,7 @@
import java.util.Map;
import java.util.Vector;
-import javax.activation.DataHandler;
import javax.jms.TextMessage;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMultipart;
-import javax.swing.ImageIcon;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
@@ -94,11 +87,6 @@
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
-import javax.xml.soap.AttachmentPart;
-import javax.xml.soap.SOAPException;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
import org.apache.axis.AxisEngine;
import org.apache.axis.AxisFault;
@@ -115,8 +103,6 @@
import org.apache.axis.encoding.ser.ArraySerializerFactory;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
-import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
-import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
import org.apache.axis.message.RPCElement;
import org.apache.axis.message.RPCParam;
import org.apache.axis.message.SOAPBodyElement;
@@ -1244,11 +1230,10 @@
Part returnPart = null;
if (soapParts.size() > 0) {
returnPart = (Part)soapParts.get(0);
+ setSOAPMessagePart(outMsg,returnPart.getName(), resp);
} else if (outputMIMEParts.size() > 0) {
returnPart = (Part)outputMIMEParts.get(0);
- }
- if (returnPart != null) {
- setMessagePart(
+ setMIMEMessagePart(
outMsg,
returnPart.getName(),
resp,
@@ -1277,11 +1262,7 @@
Part p = (Part) soapParts.get(i);
String name = p.getName();
Object value = respParms.get(name);
- setMessagePart(
- outMsg,
- name,
- value,
- value == null ? null :
value.getClass());
+ setSOAPMessagePart(outMsg, name, value);
}
int startMIMEindex;
if (soapParts.size() > 0) {
@@ -1293,7 +1274,7 @@
Part p = (Part) outputMIMEParts.get(i);
String name = p.getName();
Object value = respParms.get(name);
- setMessagePart(
+ setMIMEMessagePart(
outMsg,
name,
value,
@@ -1304,7 +1285,21 @@
}
- private static void setMessagePart(
+ private static void setSOAPMessagePart(
+ WSIFMessage msg,
+ String name,
+ Object value)
+ throws WSIFException {
+ Trc.entry(null, msg, name, value);
+
+ //TODO type checking against the WSDL part type
+ msg.setObjectPart(name, value);
+
+ Trc.exit();
+ }
+
+
+ private static void setMIMEMessagePart(
WSIFMessage msg,
String name,
Object value,
@@ -1312,92 +1307,7 @@
throws WSIFException {
Trc.entry(null, msg, name, value, type);
- Class valueType = value == null ? null : value.getClass();
- try {
- if (valueType != null
- && DataHandler.class.equals(type)
- && AttachmentPart.class.isAssignableFrom(valueType)) {
- AttachmentPart ap = (AttachmentPart) value;
- DataHandler dh = ap.getDataHandler();
- msg.setObjectPart(name, dh);
- } else if (
- // Attachments that are Strings, Images, etc are
unsupported at present.
- // Attachments can only be DataHandlers.
- valueType
- != null
- && (String.class.equals(type)
- || Image.class.equals(type)
- || StreamSource.class.equals(type)
- || DOMSource.class.equals(type)
- || SAXSource.class.equals(type)
- || MimeMultipart.class.equals(type))
- &&
AttachmentPart.class.isAssignableFrom(valueType)) {
-
- AttachmentPart ap = (AttachmentPart) value;
- InputStream is = ap.getDataHandler().getInputStream();
-
- if (String.class.equals(type)) {
- byte[] bBuff = new byte[is.available()];
- is.read(bBuff);
- msg.setObjectPart(name, new String(bBuff));
- } else if (Image.class.equals(type)) {
- byte[] bBuff = new byte[is.available()];
- is.read(bBuff);
- msg.setObjectPart(name, new
ImageIcon(bBuff).getImage());
- } else if (StreamSource.class.equals(type))
- // Warning: this next line of code has never
been tested.
- msg.setObjectPart(name, new StreamSource(is));
- else if (DOMSource.class.equals(type))
- throw new WSIFException("DOMSource is not
supported");
- else if (SAXSource.class.equals(type))
- throw new WSIFException("SAXSource is not
supported");
- else if (MimeMultipart.class.equals(type))
- // Warning: this next line of code has never
been tested.
- msg.setObjectPart(
- name,
- new
MimeMultipart(ap.getDataHandler().getDataSource()));
- } else if (
- valueType != null
- && type != null // will be null for async
responses
- && !type.isPrimitive()
- && !(type.isAssignableFrom(valueType))) {
- throw new WSIFException(
- "return value "
- + value
- + " has unexpected type "
- + valueType
- + " instead of "
- + type);
- } else
- msg.setObjectPart(name, value);
- } catch (SOAPException se) {
- Trc.exception(se);
- throw new WSIFException(
- "WSIFOperation_ApacheAxis.setMessagePart messageName="
- + (msg.getName() == null ? "null" :
msg.getName())
- + " partName="
- + name
- + " caught "
- + se);
- } catch (IOException ioe) {
- Trc.exception(ioe);
- throw new WSIFException(
- "WSIFOperation_ApacheAxis.setMessagePart messageName="
- + (msg.getName() == null ? "null" :
msg.getName())
- + " partName="
- + name
- + " caught "
- + ioe);
- } catch (MessagingException me) {
- Trc.exception(me);
- throw new WSIFException(
- "WSIFOperation_ApacheAxis.setMessagePart messageName="
- + (msg.getName() == null ? "null" :
msg.getName())
- + " partName="
- + name
- + " caught "
- + me);
- }
+ MIMEHelper.setMIMEMessagePart(msg, name, value, type);
Trc.exit();
}
@@ -1802,16 +1712,16 @@
boolean workedOK = false;
Object[] inputValues = getInputMessageValues(inMsg, null);
- SOAPBodyElement[] axisInputs = new SOAPBodyElement[inputValues.length];
+ ArrayList soapBodies = new ArrayList();
for (int i = 0; i < inputValues.length; i++) {
if (inputValues[i] instanceof Element) {
- axisInputs[i] = new SOAPBodyElement((Element)
inputValues[i]);
- } else {
+ soapBodies.add(new SOAPBodyElement((Element)
inputValues[i]));
+ } else if (!MIMEHelper.addAttachementIfMIMEPart(call,
inputValues[i])){
throw new WSIFException(
"unexpected input type: " + inputValues[i]);
}
}
-
+ Object[] axisInputs = soapBodies.toArray();
call.setOperationStyle(WSIFAXISConstants.AXIS_STYLE_MESSAGE);
Trc.event(this, "Invoking AXIS call", call, axisInputs);
@@ -2008,18 +1918,14 @@
private void registerMIMETypes(
List mimeParts,
Call call) {
- if (mimeParts != null) {
+ if (mimeParts != null && !mimeParts.isEmpty()) {
for (Iterator i = mimeParts.iterator(); i.hasNext(); ) {
Part p = (Part) i.next();
QName type = p.getTypeName();
if (type == null) {
type = p.getElementName();
}
- call.registerTypeMapping(
- DataHandler.class,
- type,
- JAFDataHandlerSerializerFactory.class,
- JAFDataHandlerDeserializerFactory.class);
+ MIMEHelper.registerAttachmentType(call, type);
}
}
}
1.1
xml-axis-wsif/java/src/org/apache/wsif/providers/soap/apacheaxis/MIMEHelper.java
Index: MIMEHelper.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 [EMAIL PROTECTED]
*
* 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.awt.Image;
import java.io.IOException;
import java.io.InputStream;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
import javax.swing.ImageIcon;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.logging.Trc;
/**
* The sole purpose of this class is to collect all the code that uses
* attachement classes outside of the WSIFOperation_ApacheAxis class
* so that there is not a runtime requirement on activation.jar and
* mail.jar unless attachements are actually being used.
*
* @author Ant Elder <[EMAIL PROTECTED]>
*/
public class MIMEHelper {
public static void registerAttachmentType(Call call, QName type) {
call.registerTypeMapping(
DataHandler.class,
type,
JAFDataHandlerSerializerFactory.class,
JAFDataHandlerDeserializerFactory.class);
}
public static boolean addAttachementIfMIMEPart(Call call, Object o) {
Trc.entry(null, call, o);
boolean ok;
if (o instanceof DataHandler) {
call.addAttachmentPart(new AttachmentPart((DataHandler)o));
ok = true;
} else {
ok = false;
}
Trc.exit(new Boolean(ok));
return ok;
}
public static void setMIMEMessagePart(
WSIFMessage msg,
String name,
Object value,
Class type)
throws WSIFException {
Trc.entry(null, msg, name, value, type);
Class valueType = value == null ? null : value.getClass();
try {
if (valueType != null
&& DataHandler.class.equals(type)
&& AttachmentPart.class.isAssignableFrom(valueType)) {
AttachmentPart ap = (AttachmentPart) value;
DataHandler dh = ap.getDataHandler();
msg.setObjectPart(name, dh);
} else if (
// Attachments that are Strings, Images, etc are
unsupported at present.
// Attachments can only be DataHandlers.
valueType
!= null
&& (String.class.equals(type)
|| Image.class.equals(type)
|| StreamSource.class.equals(type)
|| DOMSource.class.equals(type)
|| SAXSource.class.equals(type)
|| MimeMultipart.class.equals(type))
&&
AttachmentPart.class.isAssignableFrom(valueType)) {
AttachmentPart ap = (AttachmentPart) value;
InputStream is = ap.getDataHandler().getInputStream();
if (String.class.equals(type)) {
byte[] bBuff = new byte[is.available()];
is.read(bBuff);
msg.setObjectPart(name, new String(bBuff));
} else if (Image.class.equals(type)) {
byte[] bBuff = new byte[is.available()];
is.read(bBuff);
msg.setObjectPart(name, new
ImageIcon(bBuff).getImage());
} else if (StreamSource.class.equals(type))
// Warning: this next line of code has never
been tested.
msg.setObjectPart(name, new StreamSource(is));
else if (DOMSource.class.equals(type))
throw new WSIFException("DOMSource is not
supported");
else if (SAXSource.class.equals(type))
throw new WSIFException("SAXSource is not
supported");
else if (MimeMultipart.class.equals(type))
// Warning: this next line of code has never
been tested.
msg.setObjectPart(
name,
new
MimeMultipart(ap.getDataHandler().getDataSource()));
} else if (
valueType != null
&& type != null // will be null for async
responses
&& !type.isPrimitive()
&& !(type.isAssignableFrom(valueType))) {
throw new WSIFException(
"return value "
+ value
+ " has unexpected type "
+ valueType
+ " instead of "
+ type);
} else
msg.setObjectPart(name, value);
} catch (SOAPException se) {
Trc.exception(se);
throw new WSIFException(
"WSIFOperation_ApacheAxis.setMessagePart messageName="
+ (msg.getName() == null ? "null" :
msg.getName())
+ " partName="
+ name
+ " caught "
+ se);
} catch (IOException ioe) {
Trc.exception(ioe);
throw new WSIFException(
"WSIFOperation_ApacheAxis.setMessagePart messageName="
+ (msg.getName() == null ? "null" :
msg.getName())
+ " partName="
+ name
+ " caught "
+ ioe);
} catch (MessagingException me) {
Trc.exception(me);
throw new WSIFException(
"WSIFOperation_ApacheAxis.setMessagePart messageName="
+ (msg.getName() == null ? "null" :
msg.getName())
+ " partName="
+ name
+ " caught "
+ me);
}
Trc.exit();
}
}