users@jax-ws.java.net

Annotaion help for newbe pls

From: Steve <Homer30_at_web.de>
Date: Fri, 17 Feb 2006 16:07:18 +1100

Hi there,

I just started using Jax-WS 2.0 a couple of days ago and was pretty
happy with my first test, I
managed to send an Image object to the web-service and get a List of
Images back (actually a List of byte[] which I reencoded to the images).
I didn't have to use annotations so far (besides the @Webservice in my
server class) because JAX-WS 2.0 seems to handle basic Java data types
by its own.

Now I have to send my own data types over the wire via the webservice
and get a
javax.xml.ws.soap.SOAPFaultException: Internal server error
when I try to return my self-defined class.

Here my Web-service server class:

package application.webservice.server;

import java.awt.Image;
import java.util.ArrayList;

import javax.jws.WebService;

import application.webservice.server.logic.ImageComparer;
import application.webservice.server.logic.ImageNode;

@WebService
public class ImageFinderJAXWS {

    public ArrayList<ImageNode> findImages(Image queryImage, String[]
selectedImagePaths,
                                       int numberOfImagesToReturn){
       
        ArrayList<ImageNode> responseImageList = new
ArrayList<ImageNode>();
        ImageComparer imageComparer = new
ImageComparer(queryImage,selectedImagePaths);
       
        responseImageList =
imageComparer.getSimilarImages(numberOfImagesToReturn);
       
        return responseImageList;
    }
}

This is my client class:

public ArrayList<ImageNode> getImages(Image queryImage, String[]
selectedImagePaths,
            int numberOfImagesToReturn){
        connectToService();
        ArrayList<byte[]> byteArrayList = new ArrayList<byte[]>();
        ArrayList<ImageNode> imageNodeList = new ArrayList<ImageNode>();
        ArrayList<String> selectedImagePathsList = new ArrayList<String>();
       
        //encode the image to a byte array for the web-service
        byte[] queryImageByteArray = RGBUtils.getImageByteArray(queryImage);
       
        //put all Strings into an ArrayList of Strings for the web-service
        for(String path : selectedImagePaths ){
            selectedImagePathsList.add(path);
        }
       
        Iterator imageNodeIterator =
port.findImages(queryImageByteArray, selectedImagePathsList,
                                 numberOfImagesToReturn).iterator();
       
        while(imageNodeIterator.hasNext()){
            imageNodeList.add((ImageNode)imageNodeIterator.next());
        }

        return imageNodeList;
    }

The port.findImages(queryImageByteArray, selectedImagePathsList,
numberOfImagesToReturn) call throws the internal server
error exception.
 From what I read in the JAXB 2.0 /JAX-WS 2.0 forum and this mailing
list so far, I believe I have to add annotations
to my ImageNode class so that it can be marshalled and unmarshalled.

Here is my ImageNode Class:

public class ImageNode implements Comparable{

    private Image image = null;
    private String imagePath = null;
    private double distance = 0.0;
   
    public ImageNode(){
       
    }
   
    public ImageNode(Image image, double distance, String imagePath){
        this.image = image;
        this.distance = distance;
        this.imagePath = imagePath;
    }
   
    /* (non-Javadoc)
     * @see java.lang.Comparable#compareTo(T)
     */
    public int compareTo(Object o) {
        int result = 0;
       
        if (o != null){
            ImageNode in2 = (ImageNode)o;
            if (this.distance > in2.getDistance()) result =1;
            else if (this.distance < in2.getDistance()) result = -1;
            else if (this.distance == in2.getDistance()) result = 0;
        }
        else{
            throw new NullPointerException();
        }
        return result;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

}

Can somebody please give me a short introduction what I would have to
annotate or point me to a tutorial / example.
Where and how would I use a Marshaller/Unmarshaller ? I think it's quite
important to add an example like this one to
the JAX-WS 2.0 samples folder (I hope I didn't overlook it) because all
examples only show simple Java data types but
no user data types.

Thanks a lot for your help.

Regards,
Steve

-- 
Steve Mammani
23 / 166-172 Arden Street
Coogee NSW 2034
Australia
mobile: +61 431209435
home:  +61 2 9664 6146
email:  Homer30_at_web.de