ws-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Nichol <snicholn...@scottnichol.com>
Subject Re: SOAP Serialization problem
Date Mon, 09 Sep 2002 20:07:37 GMT
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" <apanar@essex.ac.uk>
To: <soap-dev@xml.apache.org>
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:soap-dev-unsubscribe@xml.apache.org>
For additional commands, e-mail: <mailto:soap-dev-help@xml.apache.org>




Mime
View raw message