I solved this problem as follows:
I handcrafted the class
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
@XmlRootElement(name = "ClientModules")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso(JAXBClientModuleInfo.class)
public class ClientModuleInfoList {
@XmlElement(name = "ModuleInfo", namespace =
"http://archive.riskscape.org.nz")
private List<JAXBClientModuleInfo> list;
public ClientModuleInfoList() {
list = new ArrayList<JAXBClientModuleInfo>();
}
public ClientModuleInfoList(List<JAXBClientModuleInfo> list) {
this.list = list;
}
public void setList(List<JAXBClientModuleInfo> list) {
this.list = list;
}
public List<JAXBClientModuleInfo> getList() {
return list;
}
}
And modified the service spec:
@POST
@ClientResponseType(entityType = JAXBModuleList.class)
@Path("/updateStatus")
@Consumes(MediaType.APPLICATION_XML)
@Wrapped(element = "list", namespace =
"http://archive.riskscape.org.nz", prefix = "rs")
@Produces(MediaType.APPLICATION_XML)
public Response getUpdateStatus(ClientModuleInfoList clientModules);
Still, it's too bad it wouldn't work the other way, it seems more intuitive
Gaby
--
Dr Gabriella Turek
Sr. Software Engineer, Systems Development Team
NIWA Auckland, New Zealand
Tel: +64 9 3754645
www.niwa.co.nz
NIWA - Enhancing the benefit of New Zealand¹s natural resources.
On 24/01/13 11:26 AM, "Gabriella Turek" <[email protected]> wrote:
>Hello I have the following service request I am trying to execute:
>
>@POST
> @ClientResponseType(entityType = JAXBModuleList.class)
> @Path("/updateStatus")
> @Consumes(MediaType.APPLICATION_XML)
> @Produces(MediaType.APPLICATION_XML)
> public Response getUpdateStatus(JAXBClientModuleList clientModuleList);
>
>
>Where JAXBClientModuleList is just a list of JAXBClientModuleInfo objects,
>defined as follows:
>
>
><?xml version="1.0" encoding="UTF-8"?>
><schema xmlns="http://www.w3.org/2001/XMLSchema"
>targetNamespace="http://archive.riskscape.org.nz"
> xmlns:rs="http://archive.riskscape.org.nz"
>xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> jaxb:version="1.0" elementFormDefault="qualified">
>
> <element name="JAXBClientModuleList" type="rs:jaxbClientModuleList" />
> <element name="JAXBClientModuleInfo" type="rs:jaxbClientModuleInfo" />
>
> <complexType name="jaxbClientModuleList">
> <annotation>
> <appinfo>
> <jaxb:class name="JAXBClientModuleList" />
> </appinfo>
> </annotation>
> <sequence>
> <element name="ClientModule"
> type="rs:jaxbClientModuleInfo"
>maxOccurs="unbounded" minOccurs="1"></element>
> </sequence>
> </complexType>
>
> <complexType name="jaxbClientModuleInfo">
> <annotation>
> <appinfo>
> <jaxb:class name="JAXBClientModuleInfo" />
> </appinfo>
> </annotation>
> <sequence>
> <element name="Name" type="string" maxOccurs="1"
>minOccurs="1"></element>
> <element name="Organisation" type="string" maxOccurs="1"
>minOccurs="1"></element>
> <element name="Version" type="string" maxOccurs="1"
>minOccurs="1"></element>
> <element name="RSVersion" type="string" maxOccurs="1"
>minOccurs="1"></element>
> </sequence>
> </complexType>
>
></schema>
>
>
>I've tried both mock and live testing and in both cases I get a 500 error
>return.
>Here's the code for the mock test:
>
>@Test
> public void testGetUpdateStatus() throws Exception {
> MockHttpRequest request = MockHttpRequest.post("/updateStatus");
> request.contentType(MediaType.APPLICATION_XML_TYPE);
>
> StringWriter writer = new StringWriter();
>
> JAXBClientModuleList cml = new JAXBClientModuleList();
> JAXBClientModuleInfo cmi = new JAXBClientModuleInfo();
> cmi.setName("TestModule3");
> cmi.setOrganisation("Hobbits");
> cmi.setVersion("1.3.2");
> cmi.setRSVersion("0.2.4");
> cml.getClientModule().add(cmi);
>
> JAXBContext jc = JAXBContext.newInstance(JAXBClientModuleList.class);
> Marshaller marshaller = jc.createMarshaller();
> marshaller.marshal(cmi, writer);
> System.out.println(writer.toString());
> request.setInputStream(new
>ByteArrayInputStream(writer.toString().getBytes()));
>
> MockHttpResponse response = new MockHttpResponse();
> dispatcher.invoke(request, response);
> assertEquals(HttpResponseCodes.SC_OK,response.getStatus());
>
> jc = JAXBContext.newInstance(JAXBModuleList.class);
> Unmarshaller unmarshaller = jc.createUnmarshaller();
>
> StringReader reader = new StringReader(response.getContentAsString());
> JAXBModuleList result = (JAXBModuleList)
>unmarshaller.unmarshal(reader);
> assertTrue(result.getModule().size() == 1);
> JAXBModule module = result.getModule().get(0);
> assertEquals("TestModule3", module.getName());
> assertTrue(module.getModuleVersion().size() == 1);
> assertEquals("Joe Smith",
>module.getModuleVersion().get(0).getAuthor());
> assertEquals("2.0.0", module.getModuleVersion().get(0).getVersion());
> assertEquals("0.2.4",
>module.getModuleVersion().get(0).getRSVersion());
> }
>
>The test fails with server error 500.. The live test similarly as well.
>
>
>The frustrating aspect of this is that if I modify the service method and
>all the tests to just deal with the single
>
>JAXBClientModuleInfo object it works like a charm.
>But it does not "like" to deal with the list.
>Am I missing some annotation somewhere?
>
>I am using xjc to generate my objects, and I've already run into the
>problem of @XmlRootElement being missing from the generated objects.
>Perhaps I am missing something else?
>
>Thanx
>Gaby
>
>
>
--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric
Research Ltd.
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Resteasy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/resteasy-users