|
I created my own serializer based on your code and
it works. Thanks for that.
But I have problems with the server side. I
modified the wsdd to include my de/serializers and I modified my skeleton stub
to remove the DataHandler type and put my Attachment_attribute class type. I
must have modified the skeleton incorrectly because now the there is a
exception: No such operation: "myoperation". I didn�t modified the name. Do you
know something about this.
----- Original Message -----
Sent: Wednesday, January 15, 2003 3:49
PM
Subject: Re: Attachments with
atributtes
I wrote a custom serializer to
do something similar. I needed a referenced attachment to be serialized
within a bean. The <content> element needed to support byte[]
content or just be empty and reference the attachment if available. You
need to do some additional stuff like write a Serializer Factory and setup
type mappings in your server-config.wsdd. Look at the encoding samples
for more complete information on this. Also take a look at the source
for org.apache.axis.encoding.ser.Simple*. I think I started with these
classes as the basis for my custom serializer.
Hope this helps!
Here is the Serializer:
package
com.integro.neien.node.ser; import
org.apache.axis.encoding.SerializationContext; import
org.apache.axis.encoding.Serializer; import
org.apache.axis.message.SOAPHandler; import
org.apache.axis.Constants; import org.apache.axis.Message; import
org.apache.axis.attachments.AttachmentPart; import org.xml.sax.Attributes; import
org.xml.sax.helpers.AttributesImpl; import
org.xml.sax.SAXException; import org.apache.axis.Constants; import
org.apache.axis.wsdl.fromJava.Types; import org.w3c.dom.Element;
import
javax.xml.namespace.QName; import java.io.IOException; import java.util.Hashtable;
import
javax.activation.DataHandler; import com.integro.neien.node.CdxDocument; public class CdxDocSerializer implements
Serializer { public static final String NAME =
"name"; public static final String TYPE = "type";
public static final String CONTENT = "content"; public
static final QName myTypeQName = new
QName("http://www.neien.org/schema/v0.9/cdx.xsd", "cdxDocument");
/** SERIALIZER
STUFF */ /** * Serialize an
element named name, with the indicated attributes * and
value. * @param name is the element name *
@param attributes are the attributes...serialize is free to add
more. * @param value is the value * @param
context is the SerializationContext */ public
void serialize(QName name,
Attributes attributes,
Object value,
SerializationContext
context) throws IOException
{ if (!(value instanceof
CdxDocument)) throw new
IOException("Can't serialize a " + value.getClass().getName() + " with a
DataSerializer."); CdxDocument doc =
(CdxDocument)value;
context.startElement(name, attributes);
context.serialize(new QName("", NAME), null,
doc.getName()); context.serialize(new QName("",
TYPE), null, doc.getType()); // if datahandler is not null
DataHandler dh = doc.getDh();
String apCID = null; AttributesImpl
conAttribs = null;
if(dh != null) {
// get response message and create an
attachment
Message msg =
context.getCurrentMessage();
AttachmentPart ap = (AttachmentPart)
msg.createAttachmentPart();
ap.setContent(dh.getInputStream(),
"");
// get the attachment
content id
apCID = ap.getContentIdRef();
msg.addAttachmentPart(ap);
conAttribs = new
AttributesImpl();
conAttribs.addAttribute("",
"href",
"",
"String",
apCID);
}
// Create an href attribute
with the attachment id context.serialize(new
QName("", CONTENT), conAttribs, doc.getContent());
context.endElement(); } public String
getMechanismType() { return Constants.AXIS_SAX; } public boolean writeSchema(Types types)
throws Exception { return
false; } } Here
is the bean:
/** * CdxDocument.java * * This
file was auto-generated from WSDL * by the Apache Axis WSDL2Java
emitter. */ package
com.integro.neien.node; import
javax.activation.DataHandler; public class CdxDocument implements java.io.Serializable
{ public java.lang.String name; public
com.integro.neien.node.DocumentType type; public byte[]
content; public DataHandler dh; public CdxDocument() {
} public
java.lang.String getName() { return
name; }
public void setName(java.lang.String name) {
this.name = name; } public com.integro.neien.node.DocumentType getType()
{ return type; }
public void
setType(com.integro.neien.node.DocumentType type) {
this.type = type; } public byte[] getContent() {
return content; } public void setContent(byte[] content) {
this.content = content; }
public DataHandler getDh() {
return dh; }
public void setDh(DataHandler dh) {
this.dh = dh; } private java.lang.Object __equalsCalc =
null; public synchronized boolean
equals(java.lang.Object obj) { if (!(obj
instanceof CdxDocument)) return false;
CdxDocument other = (CdxDocument)
obj; if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj); }
__equalsCalc = obj; boolean
_equals; _equals = true &&
((name==null &&
other.getName()==null) ||
(name!=null &&
name.equals(other.getName()))) &&
((type==null && other.getType()==null) ||
(type!=null &&
type.equals(other.getType())))
&& ((content==null
&& other.getContent()==null) ||
(content!=null &&
java.util.Arrays.equals(content, other.getContent())));
__equalsCalc = null; return
_equals; }
private boolean __hashCodeCalc = false; public
synchronized int hashCode() { if
(__hashCodeCalc) { return
0; }
__hashCodeCalc = true; int _hashCode =
1; if (getName() != null) {
_hashCode += getName().hashCode();
} if (getType() != null)
{ _hashCode +=
getType().hashCode(); }
if (getContent() != null) {
for (int i=0;
i<java.lang.reflect.Array.getLength(getContent());
i++) {
java.lang.Object obj =
java.lang.reflect.Array.get(getContent(), i);
if (obj != null &&
!obj.getClass().isArray())
{
_hashCode += obj.hashCode();
} }
} __hashCodeCalc =
false; return _hashCode;
} // Type
metadata private static org.apache.axis.description.TypeDesc
typeDesc = new
org.apache.axis.description.TypeDesc(CdxDocument.class); static {
org.apache.axis.description.FieldDesc field = new
org.apache.axis.description.ElementDesc();
field.setFieldName("name");
field.setXmlName(new
javax.xml.namespace.QName("http://node.neien.integro.com/schema/cdx.xsd",
"name")); field.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
typeDesc.addFieldDesc(field);
field = new
org.apache.axis.description.ElementDesc();
field.setFieldName("type");
field.setXmlName(new
javax.xml.namespace.QName("http://node.neien.integro.com/schema/cdx.xsd",
"type")); field.setXmlType(new
javax.xml.namespace.QName("http://node.neien.integro.com/schema/cdx.xsd",
"DocumentType"));
typeDesc.addFieldDesc(field);
field = new
org.apache.axis.description.ElementDesc();
field.setFieldName("content");
field.setXmlName(new
javax.xml.namespace.QName("http://node.neien.integro.com/schema/cdx.xsd",
"content")); field.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"base64Binary"));
typeDesc.addFieldDesc(field); }; /** * Return type
metadata object */ public static
org.apache.axis.description.TypeDesc getTypeDesc() {
return typeDesc; } /** * Get Custom Serializer
*/ //public static org.apache.axis.encoding.Serializer
getSerializer( // java.lang.String
mechType, // java.lang.Class _javaType,
// javax.xml.namespace.QName
_xmlType) { // return //
new com.integro.neien.node.ser.CdxDocSerializer(
// _javaType, _xmlType, typeDesc);
//}
/** * Get Custom Deserializer */
//public static org.apache.axis.encoding.Deserializer
getDeserializer( // java.lang.String
mechType, // java.lang.Class _javaType,
// javax.xml.namespace.QName
_xmlType) { // return //
new
com.integro.neien.node.ser.CdxDocDeserializer( //
_javaType, _xmlType, typeDesc); //}
}
|
| Rolando Pablos S�nchez
<[EMAIL PROTECTED]>
01/15/2003 03:34 AM Please respond to axis-user
| To:
"axis-user" <[EMAIL PROTECTED]>
cc:
Subject: Attachments
with atributtes | I made this question time ago, but nobody answered. I need attachments, and now I am specifying the attachment
in the wsdl file like this:
<xs:element name="Content" type="apachesoap:DataHandler" minOccurs="0"
maxOccurs="unbounded"/> But I need to specify more attributes in this element,
because I don�t know how to write the element description to include
attributes and besides that the WSDL2Java generates the correct stubs.
May be there is another form of doing attachments;
if you know, please, let me know.
So my question is how can I get a element that is
an attachment and also has attributes. The result would be similar to
this: <Content href=""
myatt1="XXX" myatt2="XXX"/> P.D.: I tried:
<xs:element name="Content"
minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent> <xs:extension
base="apachesoap:DataHandler">
<xs:attribute name="type" type="tns:ContentQuality"/>
<xs:attribute name="allowAdaptations"
type="xs:boolean" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType> </xs:element>
But it didn't work.
It generates a class extending SimpleType,
and axis thinks that always is possible the String representation of the
value. In few words, what you get is a call to the toString() method in the
DataHandler class. Thank you in advance
|