English 中文(简体)
JAX-WS: How to Exclude a "member/field" in a Response Object (WS Response) that is inherited?
原标题:
  • 时间:2009-11-14 13:45:28
  •  标签:
  • jax-ws

I have a WebService that returns as the result of the Invokation of the Web-Service a ResponseObject called "CustomerResponse". When I implement this object "from scratch" everything works fine: My implementation in this case only contains all the needed "Simple Types" like Strings, Integers but NO Object references/associations.

However what I wanted to do is, "reuse" existing Objects. I have in my domain-model a "Customer" Object that is used in the Application itself. Instead of stupidly more or less cloning the Customer into the "CustomerReponse" object (by manually typing again all the members/fields), I wanted to base the CutomerResponse object on the Customer Object by extension:

class CustomerResponse extends Customer

==> The Problem is that now CustomerResponse contains some "internal" fields that were inherited from the Customer Object (like DatabaseID, Security-Stuff) that I do not want to expose via the Web-Service. Furthermore (and thats currently the main problem") Customer also contains a lot of "object references/associations" to other objects like Address, Orders, History that I do not want to expose via the Webservice either. (It seems that Apache CXF "evaluates" the whole Objectgraph and tries to include them in the ResponseObject...)

==> Is it possible to "Extend" WebService Response Objects based on existing Objects and somehow exclude some "members/fields" of the extended supertyp? (So I want to exclude some members (like the DatabseID) and all of the "object associations" like (Address/Orders/Histroy).. How can I acomplish this, with what annotations and procedures?

Thank you very much!! Jan

最佳回答

The @XmlTransient annotation is used to hide members which you do not want shown. You should be able to annotate these members, and they won t be bound. Alternatively, change your @XmlAccessorType to XmlAccessType.NONE and only specifically annotated methods will be bound to XML.

问题回答

Regarding the @XmlTransient annotation, I found out that you need to put it on the getter method of the field you want to hide.

public class InputBean
{
    private String fieldShow;
    private transient String fieldHide;

    public String getFieldShow() {
        return fieldShow;
    }

    public void setFieldShow(String fieldShow) {

        this.fieldShow = fieldShow;
    }

    @XmlTransient
    public String getFieldHide() {
        return fieldHide;
    }

    public void setFieldHide(String fieldHide) {
        this.fieldHide = fieldHide;
    }
}

In the example, "fieldHide" will not be visible on the service xsd.





相关问题
Groovy & Jax-ws: @WebMethod annotation ignored

I recently found an example on implementing a We3bService with groovy and jax-ws: the problem is that the @webmethod annotation seems to be ignored. This is the source code of the groovy script: ...

JBoss Web Services Behind IIS Through HTTPs

This is a tangled web that s woven, I suppose, but it really shouldn t be all that hard. Let me see if I can paint the picture: I have written a web service, starting with a WSDL, which is to run in ...

Advantages of using a Dynamic Client with JAX-WS

What are the advantages of using a dynamic client with JAX-WS services as opposed to just using generated client classes? What are the disadvantages? **For my particular case I am using Apache CXF, I ...

wsimport ant task assumptions and how to work around those

I use the ant task from jax-ws - wsimport to generate my dto s. What I m wanting to know is what assumptions does wsimport make? for example, w.r.t to the service endpoint and the location of the ...

Jaxb2Marshaller and primitive types

Is it possible to create a web service operation using primitive or basic Java types when using the Jaxb2Marschaller in spring-ws? For example a method looking like this: @Override @PayloadRoot(...

热门标签