May the problem be here? > serializer="com.eaaxis.chapter5.DataSer" > deserializer="com.axis.DeserFactory"/>
-Taras > -----Original Message----- > From: Karna Harsha [mailto:[EMAIL PROTECTED]] > Sent: Monday, March 04, 2002 11:06 AM > To: [EMAIL PROTECTED] > Subject: Problem with serialization and deserialization > > > Hi, > > I am trying to send a custom bean type to the service. > Based on the examples in encoding section, I have > written custom serializer and deserializer. > I deploy the service and when I try to invoke it, I am > getting a null pointer exception at the service. > > Serialization part is working fine. The serializer is > able to create the XML structure properly by fecthing > the values from the bean instance. But at the server > side, > after deserialization, when I try to call the get > methods on the bean, it is throwing null pointer > exception. > > en: tomcat 4.0.1 win nt > > The serializer class is : > > public class DataSer implements Serializer > { > public static final String FIRSTNAME= "firstname"; > public static final String LASTNAME= "lastname"; > public static final QName myTypeQName = new > QName("CustomerService", "CustomerBean"); > > public void serialize(QName name, Attributes > attributes, > Object value, > SerializationContext context) > throws IOException > { > if (!(value instanceof SparePartBean)) > throw new IOException("Can't serialize a " > + value.getClass().getName() + " with a > DataSerializer."); > > CustomerBean customer = (CustomerBean)value; > context.startElement(name, attributes); > context.serialize(new QName("", FIRSTNAME), > null, customer .getFirstname(), String.class); > context.serialize(new QName("", LASTNAME), > null, customer .getLastname(), String.class); > context.endElement(); > } > public String getMechanismType() { return > Constants.AXIS_SAX; } > > public boolean writeSchema(Types types) throws > Exception { > return false; > } > } > > > The deserializer class: > > public class DataDeser extends DeserializerImpl > { > public static final String FIRSTNAME= "firstname"; > public static final String LASTNAME= "lastname"; > > public static final QName myTypeQName = new > QName("CustomerService", "CustomerBean"); > > private Hashtable typesByMemberName = new > Hashtable(); > > public DataDeser() > { > typesByMemberName.put(FIRSTNAME, > Constants.XSD_STRING); > typesByMemberName.put(LASTNAME, > Constants.XSD_STRING); > value = new SparePartBean(); > } > > public SOAPHandler onStartChild(String namespace, > String localName, > String prefix, > Attributes > attributes, > > DeserializationContext context) > throws SAXException > { > QName typeQName = > (QName)typesByMemberName.get(localName); > if (typeQName == null) > throw new SAXException("Invalid element in > Data struct - " + localName); > > // These can come in either order. > Deserializer dSer = > context.getDeserializerForType(typeQName); > try { > dSer.registerValueTarget(new > FieldTarget(value, localName)); > } catch (NoSuchFieldException e) { > throw new SAXException(e); > } > > if (dSer == null) > throw new SAXException("No deserializer > for a " + typeQName + "???"); > > return (SOAPHandler) dSer; > } > } > > I have added the typemapping to my deployment > descriptor as shown below: > > <service name="CustomerService" provider="java:RPC"> > > <parameter name="allowedMethods" > value="getDetails"/> > <parameter name="className" > value="com.axis.CustomerService"/> > <typeMapping qname="ns:local" > xmlns:ns="CusotmerService" > > languageSpecificType="java:com.axis.CustomerBean" > > serializer="com.eaaxis.chapter5.DataSer" > deserializer="com.axis.DeserFactory"/> > </service> > > > the soap request and response are: > > <?xml version="1.0" encoding="UTF-8"?> > <SOAP-ENV:Envelope > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> > <SOAP-ENV:Body> > <ns1:getDetails xmlns:ns1="CustomerService"> > <CustomerBeanhref="#id0"/> > </ns1:getDetails> > <multiRef id="id0" SOAP-ENC:root="0" > xsi:type="ns2:CustomerBean" > xmlns:ns2="CustomerService"> > <firstname xsi:type="xsd:string">billy</firstname > > <lastname xsi:type="xsd:string">bob</lastname > > </multiRef> > </SOAP-ENV:Body> > </SOAP-ENV:Envelope> > > <SOAP-ENV:Envelope > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <SOAP-ENV:Body> > <ns1:getDetailsResponse > SOAP-ENC:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:ns1="CustomerService" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> > <getDetailsResult > xsi:type="xsd:string">java.lang.NullPointerException</getDetailsResult > > > </ns1:etDetailsResponse> > </SOAP-ENV:Body> > </SOAP-ENV:Envelope> > > Please help me out. > > Regards, > Karna > > __________________________________________________ > Do You Yahoo!? > Yahoo! Sports - sign up for Fantasy Baseball > http://sports.yahoo.com >
