Question

I have a web service that receives an object of complexType Pic,

Pic.java

public class Pic implements KvmSerializable{

    private double latitude;
    private double longitude;
    private long time;
    private double accuracy;
    private String name;
    private byte[] imageInByte;

    public byte[] getImageInByte() {
        return imageInByte;
    }
    public void setImageInByte(byte[] imageInByte) {
        this.imageInByte = imageInByte;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getLatitude() {
        return latitude;
    }
    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }
    public double getLongitude() {
        return longitude;
    }
    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }
    public double getAccuracy() {
        return accuracy;
    }
    public void setAccuracy(double accuracy) {
        this.accuracy = accuracy;
    }
    public long getTime() {
        return time;
    }
    public void setTime(long time) {
        this.time = time;
    }

    @Override
    public Object getProperty(int arg0) {
        switch(arg0){
        case 0:
            return latitude;
        case 1:
            return longitude;
        case 2:
            return time;
        case 3:
            return accuracy;
        case 4:
            return name;
        case 5:
            return imageInByte;
        }
        return null;
    }
    @Override
    public int getPropertyCount() {
        return 6;
    }
    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        switch(arg0){
        case 0:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "latitude";
            break;
        case 1:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "longitude";
            break;
        case 2:
            arg2.type = PropertyInfo.LONG_CLASS;
            arg2.name = "time";
            break;
        case 3:
            arg2.type = Double.class;
            arg2.name = "accuracy";
            break;
        case 4:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "name";
            break;
        case 5:
            arg2.type = MarshalBase64.BYTE_ARRAY_CLASS;
            arg2.name = "imageInBytes";
        default:
            break;
        }
    }
    @Override
    public void setProperty(int arg0, Object arg1) {
        // TODO Auto-generated method stub
        switch(arg0){
        case 0:
            latitude = Double.parseDouble(arg1.toString());
            break;
        case 1:
            longitude = Double.parseDouble(arg1.toString());
            break;
        case 2:
            time = Long.parseLong(arg1.toString());
            break;
        case 3:
            accuracy = Double.parseDouble(arg1.toString());
            break;
        case 4:
            name = arg1.toString();
            break;
        case 5:
                imageInByte = Base64.decode(arg1.toString(), Base64.DEFAULT);
                    break;
    default:
            break;
        }
    }
}

I send it to a webservice by registering in the envelope doubles and marshalBase64. So far everything runs smoothly although in the web service once i get the object the method picture.imageInByte() returns null. I am not sure of what is happening because i could pass just a byte[] variable like this and write the file to disk. But i only passed a byte[] not a complex object with a byte[] inside.

What is the problem?

Was it helpful?

Solution

The way i solved was by altering the web service to receive 2 parameters instead of one.

like this:

public void receivePicture(Pic picture, byte[] image){

}

where picture is the information i need about the image itself and image is the actual image file.

I know this is somehow a hack and not exactly the good solution i was looking for but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top