Search code examples
javaweb-servicesjax-rpc

error: invalid type for JAX-RPC structure: jspf.common.ForumPost


I have to make a web service using JAX-RPC for a project and I get error: invalid type for JAX-RPC structure: jspf.common.ForumPost when trying to compile it. We have to use JDK 5 and J2EE 1.4. I'm using Netbeans 7.0 with the JAX-RPC plugin and Glassfish v1 support plugin to use Application Server PE 9 as my container.

This is my class:

package jspf.common;

import java.sql.Date;


public class ForumPost extends java.lang.Object implements java.io.Serializable {

    private String poster;
    private String content;
    private int topic_id;
    private int post_id;
    private Date time;

    /**
     * Creates a new ForumPost object.
     * @param poster The username of the user that posted the post.
     * @param content The body/content of the post.
     * @param topic_id The topic ID that this post replies to.
     * @param post_id This post's ID.
     */
    public ForumPost() {
    }

    public ForumPost(int post_id, int topic_id, String poster, String content, Date time) {
        this.poster = poster;
        this.content = content;
        this.topic_id = topic_id;
        this.post_id = post_id;
        this.time = time;
    }

    public Date getTime() {
        return time;
    }

    public String getContent() {
        return content;
    }

    public int getPost_id() {
        return post_id;
    }

    public String getPoster() {
        return poster;
    }

    public int getTopic_id() {
        return topic_id;
    }
}

Yes, I have to use this old technology unfortunately.

I was having similar issues with another class but that seemed to be fixed by removing the ArrayList that was within it, but I actually need that ArrayList.

Why am I getting this error?

EDIT: I got rid of all references to java.sql.Date, as follows:

package jspf.common;

public class ForumPost extends java.lang.Object implements java.io.Serializable {

    private String poster;
    private String content;
    private int topic_id;
    private int post_id;
    private long time;

    /**
     * Creates a new ForumPost object.
     * @param poster The username of the user that posted the post.
     * @param content The body/content of the post.
     * @param topic_id The topic ID that this post replies to.
     * @param post_id This post's ID.
     */
    public ForumPost() {
    }

    public ForumPost(int post_id, int topic_id, String poster, String content, long time) {
        this.poster = poster;
        this.content = content;
        this.topic_id = topic_id;
        this.post_id = post_id;
        this.time = time;
    }

    public long getTime() {
        return time;
    }

    public String getContent() {
        return content;
    }

    public int getPost_id() {
        return post_id;
    }

    public String getPoster() {
        return poster;
    }

    public int getTopic_id() {
        return topic_id;
    }
}

And I still get the same error. I don't understand what the problem is.


Solution

  • I found the problem. Value types as defined in the J2EE 1.4 documentation must contain getter and setter methods, my class contained only getter methods.

    Value Types

    A value type is a class whose state can be passed between a client and a remote service as a method parameter or return value. For example, in an application for a university library, a client might call a remote procedure with a value type parameter named Book, a class that contains the fields Title, Author, and Publisher.

    To be supported by JAX-RPC, a value type must conform to the following rules:

    • It must have a public default constructor.
    • It must not implement (either directly or indirectly) the java.rmi.Remote interface.
    • Its fields must be supported JAX-RPC types.

    The value type can contain public, private, or protected fields. The field of a value type must meet these requirements:

    • A public field cannot be final or transient.
    • A nonpublic field must have corresponding getter and setter methods.

    Source: http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXRPC4.html#wp130601