Reputation: 10562
Why won't wsimport
preserve the toString()
method of my model class?
So I have this model class in my web service:
package webservice;
public class Book {
private String title;
private int pages;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
@Override
public String toString() {
return "Book [title=" + title + ", pages=" + pages + "]";
}
}
Now I want to generate the necessary artifacts for a WS client:
wsimport -keep http://localhost:8080/LibraryWs/BookWebServiceService?wsdl
And get the resulting class:
package webservice;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for book complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="book">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="pages" type="{http://www.w3.org/2001/XMLSchema}int"/>
* <element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "book", propOrder = {
"pages",
"title"
})
public class Book {
protected int pages;
protected String title;
/**
* Gets the value of the pages property.
*
*/
public int getPages() {
return pages;
}
/**
* Sets the value of the pages property.
*
*/
public void setPages(int value) {
this.pages = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
}
So there is no toString :) where can I find specs regarding this behavior or how can I make jax-ws explicitly include that method in my WSDL? Thanks.
Upvotes: 2
Views: 999
Reputation: 10562
This is actually a stupid question because in WSDL only class member variables are translated and not methods. They are coded as complexType
.
I would say that if you want a method exposed it has to go into the @WebService
and (optionally) annotated with @WebMethod
. Otherwise only properties of the classes used by you webservice will go into WSDL.
So here http://localhost:8080/LibraryWs/BookWebServiceService?xsd=1
we will have:
<?xml version='1.0' encoding='UTF-8'?>
<!--
Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419 (branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-API/2.2.12-b140109.1041 svn-revision#unknown.
-->
<xs:schema xmlns:tns="http://webservice/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://webservice/">
<xs:element name="addBook" type="tns:addBook"/>
<xs:element name="addBookResponse" type="tns:addBookResponse"/>
<xs:element name="getAllBooks" type="tns:getAllBooks"/>
<xs:element name="getAllBooksResponse" type="tns:getAllBooksResponse"/>
<xs:complexType name="getAllBooks">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="getAllBooksResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addBook">
<xs:sequence>
<xs:element name="arg0" type="tns:book" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="book">
<xs:sequence>
<xs:element name="pages" type="xs:int"/>
<xs:element name="title" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addBookResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>
Upvotes: 4