How can I expose an custom object as parameter in a class using web services?
For example, I have a class called OrderWS.java
and in that class I have OrderLineWS.java
as parameter. Now when I exposed this OrderWS.java
to web services on client side. It did not include OrderLineWS
as parameter to OrderWS
class on client side. Can anybody help me please?
OrderWS.java
package com.dev.backend.order;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.dev.backend.customer.CustomerWS;
public class OrderWS implements Serializable{
private String orderNumber;
private String customerCode ;
private BigDecimal totalPrice;
private List<OrderLineWS> orderLineWSs = new ArrayList<OrderLineWS>();
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
public String getCustomerCode() {
return customerCode;
}
public void setCustomerCode(String customerCode) {
this.customerCode = customerCode;
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
public List<OrderLineWS> getOrderLineWSs() {
return orderLineWSs;
}
public void setOerLineWSs(List<OrderLineWS> orderLineWSs) {
this.orderLineWSs = orderLineWSs;
}
}
OrderLineWS.java
package com.dev.backend.order;
import java.io.Serializable;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.dev.backend.product.ProductWS;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class OrderLineWS implements Serializable{
private Integer quantity;
private BigDecimal unitPrice;
private BigDecimal totalPrice;
private String productCode;
private String orderCode;
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getOrderCode() {
return orderCode;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
}
IWebService.java
package com.dev.backend.webservices;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.dev.backend.customer.CustomerWS;
import com.dev.backend.order.OrderWS;
import com.dev.backend.product.ProductWS;
@WebService
public interface IWebService {
@WebMethod
Integer saveOrder(OrderWS orderWS);
}
I generated classes on client side using this command
wsimport -Xnocompile . http://localhost:8080/WS/IWebService?wsdl
On client side OrderWS.java is generated like this
package com.dev.backend.webservices;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for orderWS complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="orderWS">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="customerCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="orderNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="totalPrice" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "orderWS", propOrder = {
"customerCode",
"orderNumber",
"totalPrice"
})
public class OrderWS {
protected String customerCode;
protected String orderNumber;
protected BigDecimal totalPrice;
/**
* Gets the value of the customerCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCustomerCode() {
return customerCode;
}
/**
* Sets the value of the customerCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCustomerCode(String value) {
this.customerCode = value;
}
/**
* Gets the value of the orderNumber property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getOrderNumber() {
return orderNumber;
}
/**
* Sets the value of the orderNumber property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setOrderNumber(String value) {
this.orderNumber = value;
}
/**
* Gets the value of the totalPrice property.
*
* @return
* possible object is
* {@link BigDecimal }
*
*/
public BigDecimal getTotalPrice() {
return totalPrice;
}
/**
* Sets the value of the totalPrice property.
*
* @param value
* allowed object is
* {@link BigDecimal }
*
*/
public void setTotalPrice(BigDecimal value) {
this.totalPrice = value;
}
}