[Axis2] how to create custom serializer for only one part of a message
An xsd file shared by all of my wsdls defines a common simple datatype. I need to encrypt/decrypt this datatype any time it's used in any message. I spent the last few hours searching the archives, and I came across several threads that show how to create a custom serializer for a specific message, but nothing on how to do this for only one specific XML bean so that it's picked up automatically by all messages.Can anyone offer advice, or point me towards somewhere else to look? Thanks Larry Strollo
Re: [Axis2] AXIOM Custom Serializer/Deserializer
and use that xml with your stand alone program to see if that works? -- dims On 5/3/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next (OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject( CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart (); String uri = qname.getNamespaceURI(); if(!rootNsUri.equals(uri)) { throw new XMLStreamException(Invalid namespace + uri + . Expected namespace uri is + rootNsUri); } while(reader.hasNext ()) { int type = reader.next(); // Line number: 138 if(XMLStreamConstants.START_ELEMENT == type){ String element = reader.getLocalName (); if( rootLocalName.equals(element) ) { continue; } else if( element.equals (cardNumber) ){ obj.setCardNumber (reader.getElementText()); } else if( element.equals(expiryMonth) ) { obj.setExpiryMonth(reader.getElementText()); } else if( element.equals(expiryYear) ) { obj.setExpiryYear(reader.getElementText()); } else if( element.equals(brand) ) { obj.setBrand(reader.getElementText()); } else if( element.equals(totalAmount) ) { obj.setTotalAmount(reader.getElementText ()); } else if( element.equals(currency) ) { obj.setCurrency(reader.getElementText()); } else if( element.equals(systemId) ) { obj.setSystemId(reader.getElementText ()); } else if( element.equals(referenceNumber) ) { obj.setReferenceNumber(reader.getElementText ()); } else if( element.equals (op) ) { obj.setOp(reader.getElementText ()); } else { throw new RuntimeException(Unexpected element + element); } } if( XMLStreamConstants.END_ELEMENT == type){ if(reader.getLocalName ().equals(rootElementName)){ break; } } } return obj; } Regards, Xinjun -- Davanum Srinivas :: http://davanum.wordpress.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail
Re: [Axis2] AXIOM Custom Serializer/Deserializer
) { log.error(e); throw new AxisFault(e); } } As can be seen, this method does not contain any code dealing with StAX parser. I am wondering which step affects the StAX parser and cause the org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrapper.java:1115) NPE. I am not familiar with the implementation of AXIOM, and now cannot proceed. As far as I know, wstx-asl-3.2.0.jar is the implementation of stax-api. How about the axiom-impl-1.2.2.jar? Does it use wstx-asl-3.2.0? Regards, Xinjun On 5/4/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi Dims, The same soap request works with my standalone program. The same method toObject runs correctly gives correct result. Regards, Xinjun On 5/3/07, Davanum Srinivas [EMAIL PROTECTED] wrote: Xinjun, can you run tcpmon to capture the soap request and use that xml with your stand alone program to see if that works? -- dims On 5/3/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents (OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next (OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject(CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart (); String uri = qname.getNamespaceURI(); if(!rootNsUri.equals(uri
[Axis2] AXIOM Custom Serializer/Deserializer
Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents (OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next( OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject( CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart(); String uri = qname.getNamespaceURI(); if(!rootNsUri.equals(uri)) { throw new XMLStreamException(Invalid namespace + uri + . Expected namespace uri is + rootNsUri); } while(reader.hasNext()) { *int type = reader.next(); // Line number: 138* if(XMLStreamConstants.START_ELEMENT == type){ String element = reader.getLocalName(); if( rootLocalName.equals(element) ) { continue; } else if( element.equals(cardNumber) ){ obj.setCardNumber(reader.getElementText()); } else if( element.equals(expiryMonth) ) { obj.setExpiryMonth(reader.getElementText()); } else if( element.equals(expiryYear) ) { obj.setExpiryYear(reader.getElementText()); } else if( element.equals(brand) ) { obj.setBrand(reader.getElementText()); } else if( element.equals(totalAmount) ) { obj.setTotalAmount(reader.getElementText()); } else if( element.equals(currency) ) { obj.setCurrency(reader.getElementText()); } else if( element.equals(systemId) ) { obj.setSystemId(reader.getElementText()); } else if( element.equals(referenceNumber) ) { obj.setReferenceNumber(reader.getElementText()); } else if( element.equals(op) ) { obj.setOp(reader.getElementText()); } else { throw new RuntimeException(Unexpected element + element); } } if(XMLStreamConstants.END_ELEMENT == type){ if(reader.getLocalName().equals(rootElementName)){ break; } } } return obj; } Regards, Xinjun
Re: [Axis2] AXIOM Custom Serializer/Deserializer
I have tried to invoke the EPaymentHandler from JSP directly, it works fine. The EPaymentHandler.execute() invokes CreditCardPaymentRequestBinder.toObject. But when I invoke the EPaymentHandler from inside a child class of org.apache.axis2.receivers.RawXMLINOutMessageReceiver, then I get the NPE. The child class of RawXMLINOutMessageReceiver override the invokeBusinessLogic method as follows: public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext) throws AxisFault { log.debug(EPaymentHandler invoked.); try { epayHandler.execute(msgContext, newmsgContext); // epayHandler will invoke CreditCardPaymentRequestBinder. } catch (Exception e) { log.error(e); throw new AxisFault(e); } } As can be seen, this method does not contain any code dealing with StAX parser. I am wondering which step affects the StAX parser and cause the org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents( OMStAXWrapper.java:1115) NPE. I am not familiar with the implementation of AXIOM, and now cannot proceed. As far as I know, wstx-asl-3.2.0.jar is the implementation of stax-api. How about the axiom-impl-1.2.2.jar? Does it use wstx-asl-3.2.0? Regards, Xinjun On 5/4/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi Dims, The same soap request works with my standalone program. The same method toObject runs correctly gives correct result. Regards, Xinjun On 5/3/07, Davanum Srinivas [EMAIL PROTECTED] wrote: Xinjun, can you run tcpmon to capture the soap request and use that xml with your stand alone program to see if that works? -- dims On 5/3/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next (OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject( CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart (); String uri = qname.getNamespaceURI(); if(!rootNsUri.equals(uri)) { throw new XMLStreamException(Invalid namespace + uri + . Expected namespace uri is + rootNsUri); } while(reader.hasNext()) { int type = reader.next(); // Line number: 138 if(XMLStreamConstants.START_ELEMENT == type){ String element = reader.getLocalName (); if( rootLocalName.equals(element) ) { continue; } else if( element.equals(cardNumber) ){ obj.setCardNumber(reader.getElementText()); } else if( element.equals(expiryMonth) ) { obj.setExpiryMonth(reader.getElementText()); } else if( element.equals(expiryYear) ) { obj.setExpiryYear(reader.getElementText()); } else if( element.equals(brand) ) { obj.setBrand(reader.getElementText()); } else if( element.equals(totalAmount) ) { obj.setTotalAmount(reader.getElementText ()); } else if( element.equals(currency) ) { obj.setCurrency(reader.getElementText()); } else if( element.equals(systemId) ) { obj.setSystemId(reader.getElementText ()); } else if( element.equals(referenceNumber) ) { obj.setReferenceNumber(reader.getElementText()); } else if( element.equals(op) ) { obj.setOp(reader.getElementText ()); } else { throw new RuntimeException(Unexpected element + element); } } if(XMLStreamConstants.END_ELEMENT == type){ if(reader.getLocalName ().equals(rootElementName)){ break; } } } return obj; } Regards, Xinjun -- Davanum Srinivas :: http://davanum.wordpress.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [Axis2] AXIOM Custom Serializer/Deserializer
I have tried to invoke the EPaymentHandler from JSP directly, it works fine. The EPaymentHandler.execute() invokes CreditCardPaymentRequestBinder.toObject. But when I invoke the EPaymentHandler from inside a child class of org.apache.axis2.receivers.RawXMLINOutMessageReceiver, then I get the NPE. The child class of RawXMLINOutMessageReceiver override the invokeBusinessLogic method as follows: public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext) throws AxisFault { log.debug(EPaymentHandler invoked.); try { epayHandler.execute(msgContext, newmsgContext); // epayHandler will invoke CreditCardPaymentRequestBinder. } catch (Exception e) { log.error(e); throw new AxisFault(e); } } As can be seen, this method does not contain any code dealing with StAX parser. I am wondering which step affects the StAX parser and cause the org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents( OMStAXWrapper.java:1115) NPE. I am not familiar with the implementation of AXIOM, and now cannot proceed. As far as I know, wstx-asl-3.2.0.jar is the implementation of stax-api. How about the axiom-impl-1.2.2.jar? Does it use wstx-asl-3.2.0? Regards, Xinjun On 5/4/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi Dims, The same soap request works with my standalone program. The same method toObject runs correctly gives correct result. Regards, Xinjun On 5/3/07, Davanum Srinivas [EMAIL PROTECTED] wrote: Xinjun, can you run tcpmon to capture the soap request and use that xml with your stand alone program to see if that works? -- dims On 5/3/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next (OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject( CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart (); String uri = qname.getNamespaceURI(); if(!rootNsUri.equals(uri)) { throw new XMLStreamException(Invalid namespace + uri + . Expected namespace uri is + rootNsUri); } while(reader.hasNext()) { int type = reader.next(); // Line number: 138 if(XMLStreamConstants.START_ELEMENT == type){ String element = reader.getLocalName (); if( rootLocalName.equals(element) ) { continue; } else if( element.equals(cardNumber) ){ obj.setCardNumber(reader.getElementText()); } else if( element.equals(expiryMonth) ) { obj.setExpiryMonth(reader.getElementText()); } else if( element.equals(expiryYear) ) { obj.setExpiryYear(reader.getElementText()); } else if( element.equals(brand) ) { obj.setBrand(reader.getElementText()); } else if( element.equals(totalAmount) ) { obj.setTotalAmount(reader.getElementText ()); } else if( element.equals(currency) ) { obj.setCurrency(reader.getElementText()); } else if( element.equals(systemId) ) { obj.setSystemId(reader.getElementText ()); } else if( element.equals(referenceNumber) ) { obj.setReferenceNumber(reader.getElementText()); } else if( element.equals(op) ) { obj.setOp(reader.getElementText ()); } else { throw new RuntimeException(Unexpected element + element); } } if(XMLStreamConstants.END_ELEMENT == type){ if(reader.getLocalName ().equals(rootElementName)){ break; } } } return obj; } Regards, Xinjun -- Davanum Srinivas :: http://davanum.wordpress.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [Axis2] AXIOM Custom Serializer/Deserializer
Here is the source code of OMStAXWrapper: http://tinyurl.com/33k5m7 Here are some things I noticed: 1.) The NPE occurs at generateEvents on line 1115 because the passed-in node parameter is null. 2.) Method next(), which calls generateEvents() at line 911, does not check to see if the currentNode parameter is null. So apparently we have a case where the state is NAVIGABLE but currentNode is null. (This I believe is OK, because client code should call hasNext() before calling next().) 3.) Your code calls method hasNext() at line 797 before calling next(). But you can see the AXIOM implementation of hasNext() has a different business logic depending on the boolean value of needToThrowEndDocument. So my guess would be that the needToThrowEndDocument value is different between standalone usage and web service usage, which changes the business logic of hasNext(). Further, the business logic for standalone is correct but not working properly under certain circumstances for web service usage (i.e., it returns true when it should be false, causing your code to call next() erroneously, causing the NPE.) Glen Am Freitag, den 04.05.2007, 11:36 +0800 schrieb Xinjun Chen: I have tried to invoke the EPaymentHandler from JSP directly, it works fine. The EPaymentHandler.execute() invokes CreditCardPaymentRequestBinder.toObject. But when I invoke the EPaymentHandler from inside a child class of org.apache.axis2.receivers.RawXMLINOutMessageReceiver, then I get the NPE. The child class of RawXMLINOutMessageReceiver override the invokeBusinessLogic method as follows: public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext) throws AxisFault { log.debug(EPaymentHandler invoked.); try { epayHandler.execute (msgContext, newmsgContext); // epayHandler will invoke CreditCardPaymentRequestBinder. } catch (Exception e) { log.error(e); throw new AxisFault(e); } } As can be seen, this method does not contain any code dealing with StAX parser. I am wondering which step affects the StAX parser and cause the org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrapper.java:1115) NPE. I am not familiar with the implementation of AXIOM, and now cannot proceed. As far as I know, wstx-asl-3.2.0.jar is the implementation of stax-api. How about the axiom-impl-1.2.2.jar? Does it use wstx-asl-3.2.0? Regards, Xinjun On 5/4/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi Dims, The same soap request works with my standalone program. The same method toObject runs correctly gives correct result. Regards, Xinjun On 5/3/07, Davanum Srinivas [EMAIL PROTECTED] wrote: Xinjun, can you run tcpmon to capture the soap request and use that xml with your stand alone program to see if that works? -- dims On 5/3/07, Xinjun Chen [EMAIL PROTECTED] wrote: Hi, I wrote a sample custom serializer/deserializer to serialize an object. When I use a standalone program to test the serializer, it works fine. But when I deploy the serializer as part of a web service and and invoke the web service through a SOAP request, I got the following null pointer execption. I googled but didn't find the reason of this. Why does the NPE occur only when I deploy the binder as part of the web service? I used the same SOAPEnvelope to test. java.lang.NullPointerException at org.apache.axiom.om.impl.llom.OMStAXWrapper.generateEvents(OMStAXWrap per.java:1115) at org.apache.axiom.om.impl.llom.OMStAXWrapper.next (OMStAXWrapper.java:9 11) at com.mycom.CreditCardPaymentRequestBinder.toObject(CreditCardPaymentRequestBinder.java:138) The toObject method definition is as follows: public CreditCardPaymentRequest toObject(QName qname, XMLStreamReader reader) throws XMLStreamException { CreditCardPaymentRequest obj = new CreditCardPaymentRequest(); String rootElementName = qname.getLocalPart
[Axis2] Custom serializer for HashMap
Hi, Is anyone aware of the effort involved in writing a custom serializer for HashMap? I've not been able to find much help/tutorial on axis2 website. Will appreciate if others who've been through this can share their experiences. Thanks, Sathija - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Custom Serializer writeSchema() - adding xsd:import and wrapped arrays
Hey everyone, I have two questions regarding generating schema with custom serializers. I'm using Axis 1.3 and I have some complex type objects that I want to expose in a Web Service. These objects aren't pure Java Beans so I had to write my own custom serializer and deserializer. These objects have getters and setters that deal with Lists of other complex type objects. In the writeSchema() method of my serializer I add an element to handle the getters/setters as arrays. When I run wsdl2java the schema in the WSDL comes out like this: schema elementFormDefault=qualified targetNamespace=http://my.class.package.name xmlns=http://www.w3.org/2001/XMLSchema complexType name=MyClass1 sequence element maxOccurs=1 minOccurs=0 name=myClass2s nillable=true type=tns2:ArrayOfMyClass2/ /sequence /complexType /schema I have tns2:ArrayOfMyClass2 defined farther down in the types section of the WSDL and it's in a different namespace then MyClass1. When I validate the WSDL it says that it's invalid because it's missing an xsd:import namespace= http://my.class2.package.name/ from the above schema definition. My question is how can I add this import from the writeSchema() method in my serializer? The org.apache.wsdl.fromJava.Types class doesn't give you access to the WSDL document as a whole, or even the current schema element that's being written. Does anyone know of a way to do this? My second question is that my service has methods that take in object arrays. So in my WSDD file I have arrayMappings defined and the schema in my WSDL I have wrapped array types like this: complexType name=ArrayOfMyClass sequence element maxOccurs=unbounded minOccurs=0 name=MyClass type=tns1:MyClass/ /sequence/complexType The problem is that when I run wsdl2java the operation definitions in the default namespace schema section of the wsdl:types come out like: element name=myOperation complexType sequence element maxOccurs=unbounded name=ArrayOfMyClass type=tns1:MyClass/ /sequence/complexType/element This is incorrect because the maxOccurs should be 1, not unbounded, since it's a wrapped array type. It doesn't seem like the org.apache.wsdl.fromJava.Types has any methods to write out a wrapped array definition and it doesn't give you access to change this. Does anyone know how this can be done? If anyone knows how to accomplish either of these thanks in advance, Ben
Re: Custom Serializer writeSchema() - adding xsd:import and wrapped arrays
Sorry, in the email below I meant that I ran the java2wsdl utility. On 6/29/06, Ben Reif [EMAIL PROTECTED] wrote: Hey everyone, I have two questions regarding generating schema with custom serializers. I'm using Axis 1.3 and I have some complex type objects that I want to expose in a Web Service. These objects aren't pure Java Beans so I had to write my own custom serializer and deserializer. These objects have getters and setters that deal with Lists of other complex type objects. In the writeSchema() method of my serializer I add an element to handle the getters/setters as arrays. When I run wsdl2java the schema in the WSDL comes out like this: schema elementFormDefault=qualified targetNamespace= http://my.class.package.name xmlns=http://www.w3.org/2001/XMLSchema complexType name=MyClass1 sequence element maxOccurs=1 minOccurs=0 name=myClass2s nillable=true type=tns2:ArrayOfMyClass2/ /sequence /complexType /schema I have tns2:ArrayOfMyClass2 defined farther down in the types section of the WSDL and it's in a different namespace then MyClass1. When I validate the WSDL it says that it's invalid because it's missing an xsd:import namespace= http://my.class2.package.name/ from the above schema definition. My question is how can I add this import from the writeSchema() method in my serializer? The org.apache.wsdl.fromJava.Types class doesn't give you access to the WSDL document as a whole, or even the current schema element that's being written. Does anyone know of a way to do this? My second question is that my service has methods that take in object arrays. So in my WSDD file I have arrayMappings defined and the schema in my WSDL I have wrapped array types like this: complexType name=ArrayOfMyClass sequence element maxOccurs=unbounded minOccurs=0 name=MyClass type=tns1:MyClass/ /sequence/complexType The problem is that when I run wsdl2java the operation definitions in the default namespace schema section of the wsdl:types come out like: element name=myOperation complexType sequence element maxOccurs=unbounded name=ArrayOfMyClass type=tns1:MyClass/ /sequence/complexType/element This is incorrect because the maxOccurs should be 1, not unbounded, since it's a wrapped array type. It doesn't seem like the org.apache.wsdl.fromJava.Types has any methods to write out a wrapped array definition and it doesn't give you access to change this. Does anyone know how this can be done? If anyone knows how to accomplish either of these thanks in advance, Ben
Writing a custom serializer for Axis
Hello, (I had posted this to comp.lang.java.programmer more than a month ago, with absolutely no success...hoping someone can answer this here.) Can anyone point me to documentation explaining how to write a custom serializer for Axis in Java ? I need to write a serializer to handle data that contains a xsd:choice construct...I'm using axis 1.2.1, and the generated stub code does not handle the choice at all (as expected after consulting the Axis homepage). I have found some examples but they consist in tons of raw code and don't explain choices made in the deployment descriptor (WSDD file) for namespaces and such, what is optional (do I really need to write a deserializer if it's not used ?, can Serializer.writeSchema() return null ?), nor how the serializer is called (serializer directly called, or only factory ?). In theory writing the custom serializer seems simple : I can write a Serializer that returns a string-format XML document representing my object, but I don't see how to feed this into the Axis architecture. Cheers, Alice. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Custom serializer and java2wsdl
Hello, How can I register a custom serializer to be used by java2wsdl ant task ? My business object has lot's of get/set (for intenal use) that doesn't have to be exposed in the WSDL. I use a custom serializer that produces expected XML, but Java2WSDL doens't know about it to build the service WSDL. Nico. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Custom Serializer
Does anyone know of any tutorials on custom serialization? I've been hacking through the BeanSerializer, but my results are not encouraging. Thanks.-T
Custom serializer for xml-aware classes
I've got a situation where I need to write a custom serializer for classes that are able to give the XML representations of themselves via toString(). I've messed around with writing a custom serializer in various ways, following the examples of BeanSerializer, DocumentSerializer, etc.. just trying thing out and can't seem to come up with any encouraging leads. Here's my current serializer factory: package grega.encoding.ser; import javax.xml.namespace.QName; import javax.xml.rpc.JAXRPCException; import org.apache.axis.encoding.Serializer; import org.apache.axis.encoding.ser.BaseSerializerFactory; public class MySerializerFactory extends BaseSerializerFactory { public MySerializerFactory(Class javaType, QName xmlType) { super(MySerializer.class, xmlType, javaType); } public javax.xml.rpc.encoding.Serializer getSerializerAs(String mechanismType) throws JAXRPCException { return (Serializer) super.getSerializerAs(mechanismType); } /** * Optimize construction of a BeanSerializer by caching the type and property * descriptors. */ protected Serializer getGeneralPurpose(String mechanismType) { return new MySerializer(); } } and here's my current serializer: package grega.encoding.ser; import java.io.IOException; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.axis.Constants; import org.apache.axis.encoding.SerializationContext; import org.apache.axis.encoding.Serializer; import org.apache.axis.wsdl.fromJava.Types; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import grega.SaxContainer; public class MySerializer implements Serializer { public void serialize(QName qName, Attributes attribs, Object value, SerializationContext ctx) throws IOException { if (value instanceof SaxContainer) { ctx.startElement(qName, attribs); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(value.toString()); ctx.writeDOMElement(doc.getDocumentElement()); ctx.endElement(); } catch (SAXException e) { throw new IOException(e.getMessage()); } catch (ParserConfigurationException e) { throw new IOException(e.getMessage()); } } else { throw new IOException(value is a + value.getClass() + , not a SaxContainer); } } public Element writeSchema(Class clazz, Types types) throws Exception { return null; } public String getMechanismType() { return Constants.AXIS_SAX; } } Now what's confusing to me is that if I have a server-config.wsdd containing this: typeMapping qname=typens:Country type=java:grega.CountryXml serializer=grega.encoding.ser.MySerializerFactory deserializer=grega.ser.MyDeserializerFactory / in the MySerializer.serialize method, the QName argument has a value of multiRef. I don't want to serialize to a multiref element, I want to serialize directly into the place where the type is used in the SOAP message, right? So I figure that Axis is trying to do some kind of multi-ref SOAP encoding, and I remember reading somewhere (this whole Axis thing is kind of a haze), about using encodingStyle= on the typemapping when using document or wrapped style services, which I am, so I changed it to: typeMapping qname=typens:Country type=java:grega.CountryXml serializer=grega.encoding.ser.MySerializerFactory deserializer=grega.ser.MyDeserializerFactory encodingStyle= / but then I get the following AxisFault at serialization time: AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.io.IOException: No serializer found for class grega.CountryXml in registry [EMAIL PROTECTED] so apparently setting encodingStyle= causes my typeMapping to not register MySerializer as valid for the type I'm configuring. Why? Any pointers on how to get the serializer to work would be greatly appreciated. There's so little documentation on how custom serialization works in Axis. Thanks, Greg Adams
Re: working example of custom serializer for a class (does anyone hav e one they can post?)
see XMLBeans based serializer/de-serializer sample: http://svn.apache.org/viewcvs.cgi/webservices/axis/trunk/java/samples/xbeans/ The serializer/de-serializer code is here: http://svn.apache.org/viewcvs.cgi/webservices/axis/trunk/java/src/org/apache/axis/encoding/ser/xbeans/ -- dims On 11/10/05, Kahn, Ralph [EMAIL PROTECTED] wrote: Hi There, I am new to Axis and after using Google and reading the documentation, I still am having trouble creating and deploying a web service that uses a custom serializer and de-serializer for a Java Class that I have. I understand the need to do the typeMapping in the deploy.wsdd file. I have a working class that performs the function that I want and returns a collection of data (many rows of dynamically defined results). What I am missing is how the serializer would take the results of the class and convert them into XML. I can write the class to iterate through the collection and create whatever output I need to but I am having trouble figuring out what Axis expects the serialization class to provide as output(a string, a DOM, ??). Does anyone have a complete example of a web service that uses a custom serializer and de-serializer on a relatively complex class (i.e. rows of dynamically defined results)? By complete example, I mean the .wsdd file, the web service java source file and serializer and de-serializer java source files. Any help would be much appreciated. If I get my web service working, I promise to post it back to the list as a working example. Thanks, Ralph Kahn -- Davanum Srinivas : http://wso2.com/blogs/
working example of custom serializer for a class (does anyone hav e one they can post?)
Hi There, I am new to Axis and after using Google and reading the documentation, I still am having trouble creating and deploying a web service that uses a custom serializer and de-serializer for a Java Class that I have. I understand the need to do the typeMapping in the deploy.wsdd file. I have a working class that performs the function that I want and returns a collection of data (many rows of dynamically defined results). What I am missing is how the serializer would take the results of the class and convert them into XML. I can write the class to iterate through the collection and create whatever output I need to but I am having trouble figuring out what Axis expects the serialization class to provide as output(a string, a DOM, ??). Does anyone have a complete example of a web service that uses a custom serializer and de-serializer on a relatively complex class (i.e. rows of dynamically defined results)? By complete example, I mean the .wsdd file, the web service java source file and serializer and de-serializer java source files. Any help would be much appreciated. If I get my web service working, I promise to post it back to the list as a working example. Thanks, Ralph Kahn
Issue with Custom Serializer/Deserializer Factory
Is any issue when we define Custom Serializers/Deserializers and custom serializer factory and custom deserializer factory,because when i use the custom serializer factories and custom deserializers in typemappings definition in client-config.wsdd,it giving null serializer factory. If any one have defined custom serializer factory,they may really help me out. /Regards, Somendra __ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
custom serializer/deserializer code
Hi, I have a Java class that is final and the construtor is private i want to write my own serializer/deserializer. Can any one send/guide me the custom serializer/deserializer code. Regards, Muhammad Iqbal
Re: Custom Serializer is invoked twice for a single web service call
From reading the development list, I see that the debug logging needs to be turned off to prevent the serializer from executing twice. But, how do I turn it off? I ended up putting this in my log4j.properties to stop it. log4j.logger.org.apache.axis.client=info, stdout Thanks, A --- Davanum Srinivas [EMAIL PROTECTED] wrote: Open a JIRA issue and then you can upload the zip as attachment (http://issues.apache.org/jira). -- dims On Thu, 11 Nov 2004 09:55:20 +, tom ONeill [EMAIL PROTECTED] wrote: sorry the example is missing because I cannot seem to send a mail with an attachment to the mailing list. The zip file is only 45kb but each time I send it I get a delivery failure. I did not read anywhere that mails with attachments cannot be sent to the mailing list! From: tom ONeill [EMAIL PROTECTED] Reply-To: axis-user@ws.apache.org To: axis-user@ws.apache.org Subject: Re: Custom Serializer is invoked twice for a single web service call Date: Thu, 11 Nov 2004 09:17:18 + Hi all, As requested by Davanum I created a simple example to test this scenario. It turns out that the simple example works correctly - the custom serializer is only invoked once. The second invocation is due to some special processing I am doing within my application. I had a a question on this list some weeks ago on how to deserialize XML into Java classes (as I receive an XML message which I have to use to create Java classes to invoke our partner web service) and I received some very useful code from Michael Binz which illustrated how to do this. I have updated Michaels code somewhat so that it suits our needs. Within this deserialization code an AxisClient object is created (it is used in the creation of a MessageContext object which is required to do the serialization) and this AxisClient object is still reachable when the web service is invoked. Somehow or other the pressence of the AxisClient object leads Axis to invoke the custom serializer twice. There is probably some valid reason for this but I dont currently understand enough of the Axis internals to explain it. I have attached a zip file which contains the code to execute a test of this scenario (if anyone wants to). As John requested, this example should be a help to you in showing how to create and register your own custom serializers and deserializers. To run the test first update the WSTEST_ServiceLocator source file so that you set your own IP address and then recompile this class into the classes directory. To execute a simple test which only results in a single invocation of the custom serializers edit (and recompile) the TestCustomSerializer source file so that the argument to the web service invocation is created explicitly in the code. To execute the test so that the Custom serializer is invoked twice update the TestCustomSerializer source so that it creates the argument to the web service by using our AxisMapping class to deserialize an XML string into the relevent Java classes. Start the test server by executing the runTestServer batch file. This must be executed in the base directory so that the server can load the server-config.wsdd file. This will start a SimpleAxisServer on port 8200. Then execute the TestCustomSerializer client (after updating your classpath to include the Axis jars and the classes directory). These tests were executed using Axis1_2beta Cheers, Tom p.s. sorry about the really bad naming conventions :) From: Davanum Srinivas [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: axis-user@ws.apache.org Subject: Re: Custom Serializer is invoked twice for a single web service call Date: Wed, 10 Nov 2004 07:19:32 -0500 that is weird!! Can you please create a bug report with a small test? are u using latest nightly? thanks, dims On Wed, 10 Nov 2004 12:14:20 +, tom ONeill [EMAIL PROTECTED] wrote: Hi all, I have written a custom serializer and deserializer for one of my complex types and I have configured my client to use these custom serializers using a client-config.wsdd file. I have added some debug output to the serialize method of my custom Serializer and I have noticed that this method seems to be invoked twice for a single invocation of a web service method (I expect that the serializtion of my datatype to XML needs only to be done once to invoke the web service). I added a stack dump to the serialize method of my custom serializer and the result is that I got the following two stack dumps upon a single web service invocation java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1071) at com.mycompany.www.type.MyDataSer.serialize(Unknown Source
RE: General Question about having custom Serializer/Deserializer
is it that the response soap message structure/format should be in accordance with the wsdl most of the times or it can be different provided we have custom (de)serializer on the client side ? No, The request and response messages have to conform to the WSDL. Always. A custom serializer is not intended to morph the XML on the wire so that it does not comply with the WSDL. A Custom serializer is intended to bridge between your chosen in-memory representation (a graph of objects) and the contracted wire format, described in the WSDL. What Anne has said previously is, Given a valid WSDL, any client should be able to interact with it. True. Now, if what you want is, on the client side, to instantiate a particular set of object types, That may require a custom serializer or de-serializer on the client side. In the same way, if on the server side you have an existing set of objects, you may want to map between a relatively flat and simple XML wire structure (for example), and a relatively hierarchical object graph. Hence, a custom serializer. You can also do this bridging, in application code, manually. -Original Message- From: Dark Devil [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 13, 2005 10:13 AM To: Anne Thomas Manes Cc: axis-user@ws.apache.org Subject: Re: General Question about having custom Serializer/Deserializer Anne, Thank you for the response. So is it that the response soap message structure/format should be in accordance with the wsdl most of the times or it can be different provided we have custom (de)serializer on the client side ? Thanks, Kumar.
Re: General Question about having custom Serializer/Deserializer
Dino Anne, Thank you for the response. That clarifies lot of questions. - Kumar.
Re: General Question about having custom Serializer/Deserializer
Anne All - Say I have used custom (de)serializers with the help of jaxb, castor etc. and generated a customized response soap message from server that uses axis then how can we assume a simple AXIS client (that does not use any custom (de)serializers)) or a .NET client understand our customized response soap message and successfully consume the web serivce ? Does such client need custom (de)serializer and do we need them on .NET side as well ? Please clarify ? Thanks Regards, Kumar.
Re: General Question about having custom Serializer/Deserializer
Kumar, It depends on how well you've described your schema. As long as you're using document style, and your WSDL accurately represents the message structure, then a .NET client should be able to handle the response without needing a special deserializer. Anne On 4/13/05, Dark Devil [EMAIL PROTECTED] wrote: Anne All - Say I have used custom (de)serializers with the help of jaxb, castor etc. and generated a customized response soap message from server that uses axis then how can we assume a simple AXIS client (that does not use any custom (de)serializers)) or a .NET client understand our customized response soap message and successfully consume the web serivce ? Does such client need custom (de)serializer and do we need them on .NET side as well ? Please clarify ? Thanks Regards, Kumar.
Re: General Question about having custom Serializer/Deserializer
Don't put cyclic loops in your schema. On Apr 12, 2005 4:39 PM, Soti, Dheeraj [EMAIL PROTECTED] wrote: Hi, I have a schema which has cyclic loops and AXIS goes into a circular loop while trying to serialize the objects (throws Stack overflow exception). I can write my own serializer/deserializer but I am confused that how it is going to work on client's end. In addition to WSDL wouldn't the client also need the serializer/deserializer? Till now I have been thinking that the best approach is to just write a WSDL and that is the only thing any client would need to get access to my service. If I make sure that it is interoperable then they can generate client side proxies in any environment and they should be ready to go. I can generate server side classes using AXIS or anything other tool. Am I correct or I am missing some very basic concept here? Thanks Dheeraj
Re: General Question about having custom Serializer/Deserializer
I think this is a bug in Axis. By cyclic loops in the schema, the poster probably means recursive types, but there could be implicit loops in an instance document via IDREFs. Recursive (or mutually recursive) types are sometimes desirable. Consider an organization chart, or the descenants or ancestors of a person in a genealogy application. There is no reason why the serialization code shoould crash with a stack overflow since the data actually sent clearly has a recursion which terminates. Cycles using IDREFs should be handled using the multiref construct in serialization. It seems to me a bug if this fails. Jeff Anne Thomas Manes wrote: Don't put cyclic loops in your schema. On Apr 12, 2005 4:39 PM, Soti, Dheeraj [EMAIL PROTECTED] wrote: Hi, I have a schema which has cyclic loops and AXIS goes into a circular loop while trying to serialize the objects (throws Stack overflow exception). I can write my own serializer/deserializer but I am confused that how it is going to work on client's end. In addition to WSDL wouldn't the client also need the serializer/deserializer? Till now I have been thinking that the best approach is to just write a WSDL and that is the only thing any client would need to get access to my service. If I make sure that it is interoperable then they can generate client side proxies in any environment and they should be ready to go. I can generate server side classes using AXIS or anything other tool. Am I correct or I am missing some very basic concept here? Thanks Dheeraj
RE: General Question about having custom Serializer/Deserializer
Anne, That's what I am trying to do as well (remove the cyclic loops by normalizing the internal structures) so that the schema exposed through WSDL is simple. But do you think that my understanding of the fact that WSDL alone should be enough for a client to interact with a web service is correct and a good approach to follow. Thanks Dheeraj -Original Message- From: Anne Thomas Manes [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 12, 2005 2:48 PM To: axis-user@ws.apache.org Subject: Re: General Question about having custom Serializer/Deserializer Don't put cyclic loops in your schema. On Apr 12, 2005 4:39 PM, Soti, Dheeraj [EMAIL PROTECTED] wrote: Hi, I have a schema which has cyclic loops and AXIS goes into a circular loop while trying to serialize the objects (throws Stack overflow exception). I can write my own serializer/deserializer but I am confused that how it is going to work on client's end. In addition to WSDL wouldn't the client also need the serializer/deserializer? Till now I have been thinking that the best approach is to just write a WSDL and that is the only thing any client would need to get access to my service. If I make sure that it is interoperable then they can generate client side proxies in any environment and they should be ready to go. I can generate server side classes using AXIS or anything other tool. Am I correct or I am missing some very basic concept here? Thanks Dheeraj
Re: General Question about having custom Serializer/Deserializer
If you have a complex type that requires a customer serializer on the server, you can assume that you will also require one on the client. On Apr 12, 2005 5:59 PM, Soti, Dheeraj [EMAIL PROTECTED] wrote: Anne, That's what I am trying to do as well (remove the cyclic loops by normalizing the internal structures) so that the schema exposed through WSDL is simple. But do you think that my understanding of the fact that WSDL alone should be enough for a client to interact with a web service is correct and a good approach to follow. Thanks Dheeraj -Original Message- From: Anne Thomas Manes [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 12, 2005 2:48 PM To: axis-user@ws.apache.org Subject: Re: General Question about having custom Serializer/Deserializer Don't put cyclic loops in your schema. On Apr 12, 2005 4:39 PM, Soti, Dheeraj [EMAIL PROTECTED] wrote: Hi, I have a schema which has cyclic loops and AXIS goes into a circular loop while trying to serialize the objects (throws Stack overflow exception). I can write my own serializer/deserializer but I am confused that how it is going to work on client's end. In addition to WSDL wouldn't the client also need the serializer/deserializer? Till now I have been thinking that the best approach is to just write a WSDL and that is the only thing any client would need to get access to my service. If I make sure that it is interoperable then they can generate client side proxies in any environment and they should be ready to go. I can generate server side classes using AXIS or anything other tool. Am I correct or I am missing some very basic concept here? Thanks Dheeraj