Hi Scott, Thanks for the example.Would I have to use my own interface serializer? Is there a way of using the BeanSerializer without having to create my own serializer? The reason I would like to avoid writing my own serializer is because when I try to distribute my application then all the clients that will use this service will have to register my own serializer which might be very inconvenient.
So on the following example: MyClass c = new MyClass(); MyInterfaceSerializer s = new MyInterfaceSerializer(); SOAPMappingRegistry smr = new SOAPMappingRegistry(); smr.mapTypes(soapEncURI, QName("urn:my-urn", "MyInterface"), MyInterface.class, s, s); Vector params = new Vector(); params.addElement(new Parameter("arg1", MyInterface.class, c, null)); If I use the BeanSerializer will it cope with Interface class? Alex -----Original Message----- From: Scott Nichol [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 10, 2002 7:03 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: SOAP Serialization problem You are allowed to map just the interface, but you must provide the interface as the data type for the parameter, not the class. For example, if class MyClass implements interface MyInterface, you can do MyClass c = new MyClass(); MyInterfaceSerializer s = new MyInterfaceSerializer(); SOAPMappingRegistry smr = new SOAPMappingRegistry(); smr.mapTypes(soapEncURI, QName("urn:my-urn", "MyInterface"), MyInterface.class, s, s); Vector params = new Vector(); params.addElement(new Parameter("arg1", MyInterface.class, c, null)); Basically, the type you specify when creating a Parameter must match a type that has been registered (whether explicitly by you or implicitly in the SOAPMappingRegistry). The disadvantage of only registering the interface, however, is that information about the original type is lost. In the example above, if another class MyClass2 implements MyInterface, but I serialize it as a MyInterface.class, the serialization of an instance of MyClass is indistinguishable from the serialization of an instance of MyClass2. This may not be a problem, but it depends on the signatures of the method(s) you will call, as well as differences the classes may have in the way they implement the interface. At the other extreme, you can map both interfaces and classes, then on a per-parameter basis choose which mapping to use: MyClass c = new MyClass(); MyClass2 c2 = new MyClass2(); MyInterfaceSerializer s1 = new MyInterfaceSerializer(); MyClassSerializer s2 = new MyClassSerializer(); MyClass2Serializer s3 = new MyClass2Serializer(); SOAPMappingRegistry smr = new SOAPMappingRegistry(); smr.mapTypes(soapEncURI, QName("urn:my-urn", "MyInterface"), MyInterface.class, s1, s1); smr.mapTypes(soapEncURI, QName("urn:my-urn", "MyClass"), MyClass.class, s2, s2); smr.mapTypes(soapEncURI, QName("urn:my-urn", "MyClass2"), MyClass2.class, s3, s3); Vector params = new Vector(); params.addElement(new Parameter("arg1", MyInterface.class, c, null)); params.addElement(new Parameter("arg2", MyClass.class, c, null)); params.addElement(new Parameter("arg3", MyClass2.class, c2, null)); Scott Nichol ----- Original Message ----- From: "Alexandros Panaretos" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, September 10, 2002 1:19 PM Subject: RE: SOAP Serialization problem Hi Scott, Thank you again for your reply I got one of the problems sorted. In the case of the interface I would like to ask another detail if possible please: When my Soap Client methods have a Java Interface Object that is has various concrete implementations do I have to provide the type mapping of the implementations in the deployment descriptor or only the interface class. Also When I create my SOAP Call Object and I pass the parameter do I again pass the Interface class or the Implementation of that class? I have tried it passing interface objects and it did not work. Anyway thank you very much for your help. Alex -----Original Message----- From: Scott Nichol [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 10, 2002 5:42 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: SOAP Serialization problem You can pass a JavaBean that has a property that is a Vector of another JavaBean, but you must supply a mapping for the other class. Basically, any type you want to serialize that is not a Java primitive (e.g. float, int), wrapper (e.g. Float, Integer) or one of the few others with built-in serializer mappings (e.g. Date), you have to provide a serializer mapping. For working with interfaces, you would typically write your own serializer, specifically because the deserializer must create an instance of a concrete class. This is done for collection interfaces. Serializing interfaces, on the other hand, is no different than serializing any class. If you have an interface that follows the JavaBean pattern, for example, I think you could serialize it using the BeanSerializer. Scott Nichol ----- Original Message ----- From: "Alexandros Panaretos" <[EMAIL PROTECTED]> To: "'Scott Nichol'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, September 10, 2002 5:27 AM Subject: RE: SOAP Serialization problem Hi Scott, Thanks for your e-mail. The problems I had before I managed to solve. I discovered that when you are passing JavaBeans through SOAP using the Bean Serializer despite the setters & getters you should and the empty constructor if you have any other methods that start with a get or set you should provide an equivalent set or get (empty) in order to work. Anyway, I have another problem now: Is it possible to pass a JavaBean through SOAP that one of its properties is Vector of another user defined objects which are JavaBeans as well ? Moreover I would like to ask if you can pass an Interface as a parameter of a SOAP method and then inside the SOAP Client specify the implementation class of the interface you want the Serializer and Deserializer to use. Thank you in advance. Alex -----Original Message----- From: Scott Nichol [mailto:[EMAIL PROTECTED]] Sent: Monday, September 09, 2002 9:08 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: SOAP Serialization problem Can you describe the problems you are having? Assuming you have getters and setters for all properties you wish to serialize, and the properties have data types that have serializers, BeanSerializer should work. As you have experienced, there are no serializers for URL or DataInputStream. Scott Nichol ----- Original Message ----- From: "Alexandros Panaretos" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, September 02, 2002 11:03 AM Subject: SOAP Serialization problem Hi there, I am quite new to SOAP and would like some help with the following if possible: Well, I am trying to pass my user defined object through SOAP. Now, I have read various tutorials about passing user defined objects through SOAP. From what I have understood there two ways of doing so: A. Code your object class as a JavaBean and the use the provided beanSerializer or B. Create your own custom serializer & deserializer. I am trying to do the first and I have a lot problems serializing the following Java class: <--------------- Start of Java Code ----------------> import java.io.InputStream; import java.io.DataInputStream; import java.net.URL; import java.util.Vector; public class MNistDataset implements ImageDataset { //InputStream is; //DataInputStream dis; //URL labelSetUrl; //URL imageSetUrl; String labelSetUrl; String imageSetUrl; byte[] labels; byte[] buf; Vector images; int maxPatterns = 1000000; int nImages; int nRows; int nCols; int nBytes; int nClasses; public MNistDataset(){ } public MNistDataset(String labelSetUrl, String imageSetUrl) throws Exception { this.labelSetUrl = labelSetUrl; this.imageSetUrl = imageSetUrl; readLabelSet(labelSetUrl); readImageSet(imageSetUrl); } public MNistDataset(String labelSetUrl, String imageSetUrl, int maxPatterns) throws Exception { this.labelSetUrl = labelSetUrl; this.imageSetUrl = imageSetUrl; this.maxPatterns = maxPatterns; readLabelSet(labelSetUrl); readImageSet(imageSetUrl); } public void readImageSet(String imageSetUrl) throws Exception { InputStream is; DataInputStream dis; is = new URL(imageSetUrl).openStream(); dis = new DataInputStream(is); int magic = dis.readInt(); //System.out.println("magic number is equal: " + magic); int n = dis.readInt(); n = Math.min( maxPatterns , n ); if (n != nImages) { throw new Exception(nImages + " <> " + n); } nRows = dis.readInt(); nCols = dis.readInt(); images = new Vector(); for (int i = 0; i < nImages; i++) { images.addElement(readImage(dis, nImages, nRows, nCols)); } } public byte[][] readImage(DataInputStream dis, int nImages, int nRows, int nCols) throws Exception { byte[][] imageByteArray = new byte[nRows][nCols]; nBytes = nRows * nCols; buf = new byte[nBytes]; dis.read(buf, 0, nBytes); for (int x = 0; x < nRows; x++) { for (int y = 0; y < nCols; y++) { imageByteArray[x][y] = buf[ x + y * nRows]; } } return imageByteArray; } public byte[][] getImage(int i) { return (byte[][]) images.elementAt(i); } public Object getPattern(int i) { return images.elementAt(i); } public int getClass(int i) { return labels[i]; } public int nClasses() { return nClasses + 1; } public int nPatterns() { return nImages; } public ClassifiedDataset emptyCopy() { // buggy - but probably not used! return this; } /** I have ommitted the setters and getters of the class variables in order to keep it short **/ } <--------------- End of Java Code ----------------> I already had a problem with the URLs and DataInputStream and DataOutputStream variables so I declared within the methods rather than global and I am not sure but I think SOAP can not handle the byte arrays as properties of the JavaBean. Do you think there is a way of passing this object through SOAP or is very complex and it can not serialize it? Your help would be very much appreciated because this has been very frustrating for me. Thank you very much in advance for patience in reading this post and your help. Alexandros Panaretos -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>