You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ri...@apache.org on 2001/11/10 04:35:41 UTC
cvs commit: xml-axis/java/src/org/apache/axis/encoding JAFDataHandlerSerializer.java SerializationContext.java
rineholt 01/11/09 19:35:41
Modified: java build.xml
java/src/org/apache/axis/attachments AttachmentUtils.java
Attachments.java AttachmentsImpl.java
java/src/org/apache/axis/encoding SerializationContext.java
Added: java/samples/attachments EchoAttachment.java
java/src/org/apache/axis/encoding
JAFDataHandlerSerializer.java
Log:
Work in progress. Allows from the Call method to add Java Activation
DataHandlers as attachments. Serializers can control what type of HREF
to generate. Also serializers could decide not add the attachment at all
and provide a URL to the actual source ... tomorrow.
Revision Changes Path
1.84 +2 -0 xml-axis/java/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/build.xml,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- build.xml 2001/11/09 22:51:15 1.83
+++ build.xml 2001/11/10 03:35:41 1.84
@@ -186,6 +186,7 @@
<exclude name="org/apache/axis/attachments/AttachmentPart.java" unless="attachments.present"/>
<exclude name="org/apache/axis/attachments/AttachmentUtils.java" unless="attachments.present"/>
<exclude name="org/apache/axis/attachments/MimeUtils.java" unless="attachments.present"/>
+ <exclude name="org/apache/axis/encoding/JAFDataHandlerSerializer.java" unless="attachments.present"/>
<exclude name="org/apache/axis/attachments/ManagedMemoryDataSource.java" unless="attachments.present"/>
<exclude name="org/apache/axis/handlers/MD5AttachHandler.java" unless="attachments.present"/>
<exclude name="org/apache/axis/attachments/MultiPartRelatedInputStream.java" unless="attachments.present"/>
@@ -238,6 +239,7 @@
<exclude name="**/old/**/*.java" />
<exclude name="samples/userguide/example2/Calculator.java"/>
<exclude name="samples/addr/*.java" />
+ <exclude name="samples/attachments/**/*.java" unless="attachments.present"/>
</javac>
</target>
1.1 xml-axis/java/samples/attachments/EchoAttachment.java
Index: EchoAttachment.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 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 "Axis" 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package samples.attachments;
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.Transport;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.JAFDataHandlerSerializer;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.axis.utils.Options;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.rpc.namespace.QName;
import java.net.URL;
/**
*
* @author Rick Rineholt
*/
/**
* An example of sending an attachment via RPC.
* This class has a main method that beside the standard arguments
* allows you to specify an attachment that will be sent to a
* service which will then send it back.
* WORK IN PROGRESS!
*
*/
public class EchoAttachment {
Options opts = null;
EchoAttachment( Options opts){
this.opts= opts;
}
public float echo(String filename) throws Exception {
//Create the data for the attached file.
DataHandler dh= new DataHandler( new FileDataSource( filename ));
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new URL(opts.getURL()) ); //Set the target service host and service location,
call.setOperationName( "echo" ); //This is the target services method to invoke.
call.setProperty( Call.NAMESPACE, "urn:EchoAttachmentsService" );
QName qnameAttachment= new QName("urn:EchoAttachmentsService", "SourceFile");
call.addSerializer(dh.getClass(),//Add serializer for attachment.
qnameAttachment,
new JAFDataHandlerSerializer());
call.addParameter( "source", new XMLType(qnameAttachment),
Call.PARAM_MODE_IN ); //Add the file.
call.setReturnType( XMLType.XSD_FLOAT ); //bogus for now
call.setProperty( Transport.USER, opts.getUser() );
call.setProperty( Transport.PASSWORD, opts.getPassword() );
Object ret = call.invoke( new Object[] {dh} ); //Add the attachment.
if (ret instanceof String) {
System.out.println("Received problem response from server: "+ret);
throw new AxisFault("", (String)ret, null, null);
}
return 1.0f;//make it happy.
}
/**
* Send an attachment and have it return.
*/
public static void main(String args[]) {
try {
Options opts = new Options(args);
EchoAttachment echoattachment= new EchoAttachment(opts);
args = opts.getRemainingArgs();
float val = echoattachment.echo(args[0]);
}
catch( Exception e ) {
if ( e instanceof AxisFault ) {
((AxisFault)e).dump();
} else
e.printStackTrace();
}
}
}
1.2 +13 -0 xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java
Index: AttachmentUtils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AttachmentUtils.java 2001/11/06 20:06:02 1.1
+++ AttachmentUtils.java 2001/11/10 03:35:41 1.2
@@ -82,4 +82,17 @@
}
return ((AttachmentPart) part).getActiviationDataHandler();
}
+
+ /**
+ * Determine if an object is to be treated as an attchment.
+ *
+ * @param value the value that is to be determined if
+ * its an attachment.
+ *
+ * @return True if value should be treated as an attchment.
+ */
+ public static boolean isAttachment( Object value){
+ if( null == value ) return false;
+ return value instanceof javax.activation.DataHandler;
+ }
}
1.3 +11 -0 xml-axis/java/src/org/apache/axis/attachments/Attachments.java
Index: Attachments.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/Attachments.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Attachments.java 2001/11/06 20:06:02 1.2
+++ Attachments.java 2001/11/10 03:35:41 1.3
@@ -110,5 +110,16 @@
*This is the number of attachments.
**/
public int getAttachmentCount();
+
+ /**
+ * Determine if an object is to be treated as an attchment.
+ *
+ * @param value the value that is to be determined if
+ * its an attachment.
+ *
+ * @return True if value should be treated as an attchment.
+ */
+
+ public boolean isAttachment( Object value);
}
1.3 +13 -0 xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java
Index: AttachmentsImpl.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AttachmentsImpl.java 2001/11/06 20:06:02 1.2
+++ AttachmentsImpl.java 2001/11/10 03:35:41 1.3
@@ -188,4 +188,17 @@
public int getAttachmentCount(){
return attachments.size();
}
+
+ /**
+ * Determine if an object is to be treated as an attchment.
+ *
+ * @param value the value that is to be determined if
+ * its an attachment.
+ *
+ * @return True if value should be treated as an attchment.
+ */
+
+ public boolean isAttachment( Object value){
+ return AttachmentUtils.isAttachment(value);
+ }
}
1.56 +25 -0 xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
Index: SerializationContext.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- SerializationContext.java 2001/11/07 22:21:51 1.55
+++ SerializationContext.java 2001/11/10 03:35:41 1.56
@@ -58,6 +58,7 @@
import org.apache.axis.AxisEngine;
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
+import org.apache.axis.Message;
import org.apache.axis.client.Call;
import org.apache.axis.utils.Mapping;
import org.apache.axis.utils.NSStack;
@@ -82,6 +83,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Stack;
+import org.apache.axis.attachments.Attachments;
/** Manage a serialization, including keeping track of namespace mappings
* and element stacks.
@@ -219,6 +221,12 @@
{
return getPrefixForURI(uri, "ns" + lastPrefixIndex++);
}
+
+
+ public Message getCurrentMessage(){
+
+ return msgContext.getCurrentMessage();
+ }
public String getPrefixForURI(String uri, String defaultPrefix)
{
@@ -301,6 +309,23 @@
"CDATA", "true");
startElement(qName, attrs);
endElement();
+ }
+
+ Message msg= getCurrentMessage();
+ if(null != msg){
+ //Get attachments. returns null if no attachment support.
+ Attachments attachments= getCurrentMessage().getAttachments();
+
+ if( null != attachments && attachments.isAttachment(value)){
+ //Attachment support and this is an object that should be treated as an attachment.
+
+ //Allow an the attachment to do its own serialization.
+ getTypeMappingRegistry().serialize(qName, attributes, value, this);
+
+ //No need to add to mulitRefs. Attachment data stream handled by
+ // the message;
+ return;
+ }
}
// If multi-reference is enabled and this object value is not a primitive
1.1 xml-axis/java/src/org/apache/axis/encoding/JAFDataHandlerSerializer.java
Index: JAFDataHandlerSerializer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 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 "Axis" 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.encoding;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import javax.xml.rpc.namespace.QName;
import java.io.IOException;
import javax.activation.DataHandler;
import org.apache.axis.Part;
import org.apache.axis.attachments.Attachments;
import org.apache.axis.Constants;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
/**
* General purpose serializer/deserializerFactory for an arbitrary java bean.
*
* @author Rick Rineholt
*/
public class JAFDataHandlerSerializer implements Serializer {
/**
* Serialize a JAF DataHandler quantity.
*/
public void serialize(QName name, Attributes attributes,
Object value, SerializationContext context)
throws IOException
{
DataHandler dh= (DataHandler)value;
//Add the attachment content to the message.
Attachments attachments= context.getCurrentMessage().getAttachments();
Part attachmentPart= attachments.createAttachmentPart(dh);
String href= attachmentPart.getContentId();
AttributesImpl attrs = new AttributesImpl();
if (attributes != null)
attrs.setAttributes(attributes); //copy the existing ones.
attrs.addAttribute("", Constants.ATTR_HREF, "href",
"CDATA", href);
context.startElement(name, attrs);
context.endElement(); //There is no data to so end the element.
}
}