Design thoughts on a schema based request object for CXF endpoint

Trying to seek design suggestion on a schema based request object for a CXF endpoint. I’ve created a CXF SOAP endpoint which takes the following object as an input. The request object will have required fields, non-mandatory fields as well as user-defined fields.Required fields are enforced through the schema. The tag object is defined as a placeholder for user defined properties. The eventual goal of the endpoint has transformed the values into Tag object and send them for processing.


    public class TestServiceRequest{
    
      @XmlElement(required = true)
        protected String url;
        @XmlElement(required = true)
        protected String title;
        protected String source;
        protected List tags;
        
        public void setUrl(String value) {
            this.url = value;
        }
        public void setTitle(String title) {
            this.title = title;
        }
        public void setSource(String value) {
                this.text = value;
            }
            public List getTags() {
                if (tags == null) {
                    tags = new ArrayList();
                }
                return this.tags;
            }
        

Tag object :

<pre><code>
public class Tag{
   public String name;
   public String value;
   public String weight;
}
</code></pre>

Schema snippet:

<pre><code>
<xsd:complexType name="tag">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1" />
            <xsd:element name="value" type="xsd:string" minOccurs="1" maxOccurs="1" />
            <xsd:element name="weight" type="xsd:string" minOccurs="0" maxOccurs="1" />
            <xsd:element name="attribute" type="tns:attribute" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="testServiceRequest">
        <xsd:complexType>
            <xsd:complexContent>
                <xsd:extension base="br:BaseRequest">
                    <xsd:sequence>
                        <xsd:element name="url" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="title" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="text" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="source" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="tags" type="tns:tag" minOccurs="0" maxOccurs="unbounded"/>
                    </xsd:sequence>
                </xsd:extension>
            </xsd:complexContent>
        </xsd:complexType>
    </xsd:element>
</code></pre>

As you can see, Tag object has an additional field called weight, which is the crux of the issue. Weight is an optional field for each property defined as required (url, title) and optional fields (source) as well. The weights are static value defined for these properties.

The reason why I inclined towards this model is first, property field names (URL, title, etc.) conform to a standard and cannot deviate. Having defined them in a schema and generating the request based on it, allows me to impose that. The end-user is free from using the exact field name and just use the setter instead, thus reducing the scope of error. Moreover, schema validation can be integrated with CXF endpoint easily, hence maintenance is easy. Any change is restricted to the schema.

An issue with this model is the service endpoint explicitly needs to add the weight for the fields while converting them to Tag objects. If the client ever decides to send their own weight values specific to properties, then this model will break.

The other option is to use a simplified request object instead of a schema generated one.

<pre><code>
public class Tag{
   public String name;
   public String value;
   public String weight;
}
</code></pre>

The pros are that this model is simple and flexible and allows user to define weights and other metadata if required.

An issue with this, I need an explicit validation code to make sure the required fields are provided and the field names are correct. That means, every time a new field is added, I need to touch the code to add it as part of the validation.

I’m in a dilemma to decide which is the best possible way to design this. Maybe, there’s a better way to do this instead.

You should be able to define a MinimalTag with name and value properties. Then inherit from that to define a StandardTag that includes the weight property.

If your model only expects MinimalTag, then the user input will be valid without the weight property. If the weight property is present, then the type can be inferred as StandardTag and used as required.

public class MinimalTag
{
   public String name;
   public String value;
}

public class StandardTag : MinimalTag
{
   public String weight;
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật