Hi,
I'm trying to get my schema shown on wadl response. But I don't quite get it yet
Can someone help me
Here is my code
public class Student
{
private String name;
private Date birthday;
//getter and setter;
}
@Path("students")
@Component
@Scope("request")
public class StudentsResource
{
@GET
@Produces("application/xml")
public ArrayList<Student> getStudents()
{
ArrayList<Student> students = new ArrayList<Student>();
...
return students;
}
}
@Provider
@Produces("application/xml")
public class ListWriter implements MessageBodyWriter<ArrayList<Student>>
{
public long getSize(ArrayList<Student> students, Class<?> arg1,Type arg2,
Annotation[] arg3, MediaType arg4)
{
return -1;
}
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[]
arg2, MediaType arg3)
{
return type == ArrayList.class;
}
@Override
public void writeTo(ArrayList<Student> students, Class<?> arg1, Type arg2,
Annotation[] arg3, MediaType arg4, MultivaluedMap<String, Object> arg5,
OutputStream out) throws IOException,
WebApplicationException
{
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<students>";
Iterator<Student> iterator = students.iterator();
while(iterator.hasNext())
{
Student student = (Student) iterator.next();
result += "<student>"
+ "<name>" + student.getName() + "</name>"
+ "<birthday>" + student.getBirthday + "</birthday>"
+ "</student>";
}
result += "</students>";
out.write(result.getBytes());
}
}
public class ExtendedWADL extends WadlGeneratorConfig
{
@Override
public List<WadlGeneratorDescription> configure()
{
return
generator(WadlGeneratorGrammarsSupport.class).prop("grammarsStream","application-grammars.xml").descriptions();
}
}
application-grammars.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:xi="
http://www.w3.org/1999/XML/xinclude">
<include href="schema.xsd" />
</grammars>
schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:element name="name" type="xs:string"/>
<xs:element name="birthday" type="xs:dateTime"/>
<xs:element name="students">
<xs:complexType>
<xs:sequence>
<xs:element ref="students" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="birthday"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This is what I currently get in my wadl.
<application>
<doc jersey:generatedBy="Jersey: 1.5 01/14/2011 12:36 PM"/>
<grammars>
<include href="schema.xsd"/>
</grammars>
<resource path="/hello">
<method name="GET" id="getClichedMessage">
<response>
<representation mediaType="text/plain"/> <!-- I'm expecting some
kind of representation mediaType="text/plain" element="p:student" -->
</response>
</method>
</resource>
</resources>
</application>