Hi Sergey,
Thank you for your message! I was able to resolve both of my problems
following your suggestions.
Sergey Beryozkin wrote:
>
> Hi
>
> You probably need to add an Accept header value set to application/xml
> when requesting Locations or add @Produces("application/xml") on that
> method.
> Not sure though why the list of locations is empty on POST, it appears the
> incoming XML does not match the one which is produced :
>
> <Locations><locations><id>1</id></locations></Locations>
>
> meaning that JAXB is probably expecting tags with diff names, so it
> probably should be :
>
> <Locations>
> <locations>
> <id>1</id>
> </locations>
> </Locations>
>
> Cheers, Sergey
>
>
> yong wrote:
>>
>> Hi Sergey,
>>
>> Thank you for your reply.
>>
>> Per your suggestion, I added the default constructor and now I am getting
>> data back but somehow in json format:
>>
>> {"Locations":{"locations":[{"id":1},{"id":2}]}}
>>
>> I thought JAXB binding was default.
>>
>> Also my POST of the collection is still not going through. The list is
>> always empty. Can you please shed some light on this too? Thank you!
>>
>>
>>
>> Sergey Beryozkin wrote:
>>>
>>> Hi
>>>
>>> Unfortunately the actual messages available from JAXBExceptions are
>>> limiting, it is really a stack trace which contains some useful
>>> information, so on the trunk the stack traces are also being logged now.
>>> I'm quite convinced it's a JAXB thing - some sort of naming convention
>>> issue or whatever. I'd advise to check on JAXB lists in such cases.
>>>
>>> Doing a quick test on the trunk reveals :
>>>
>>> 24-Jul-2009 09:53:49 org.apache.cxf.jaxrs.provider.AbstractJAXBProvider
>>> handleJAXBException
>>> WARNING: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1
>>> counts of IllegalAnnotationExceptions
>>> org.apache.cxf.jaxrs.provider.JAXBElementProviderTest$Location does not
>>> have a no-arg default constructor.
>>> this problem is related to the following location:
>>> at
>>> org.apache.cxf.jaxrs.provider.JAXBElementProviderTest$Location
>>> at public java.util.List
>>> org.apache.cxf.jaxrs.provider.JAXBElementProviderTest$Locations.getLocations()
>>> at
>>> org.apache.cxf.jaxrs.provider.JAXBElementProviderTest$Locations
>>>
>>> After adding a default Location constructor we now get :
>>>
>>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>>> <Locations><locations><id>1</id></locations></Locations>
>>>
>>> cheers, Sergey
>>>
>>>
>>>
>>> yong wrote:
>>>>
>>>> Hello,
>>>>
>>>> I have googled these issues before coming to tihs forum. I have seen a
>>>> couple of related posts on this forum but didn't see how they were
>>>> resolved.
>>>>
>>>> Here is the simple test code I have:
>>>>
>>>> Locations.java
>>>> --------------
>>>> @XmlRootElement(name = "Locations")
>>>> public class Locations
>>>> {
>>>> private List<Location> locations;
>>>>
>>>> public void setLocations(final List<Location> locations)
>>>> {
>>>> this.locations = locations;
>>>> }
>>>>
>>>> public List<Location> getLocations()
>>>> {
>>>> return locations;
>>>> }
>>>> }
>>>>
>>>> Location.java
>>>> -------------
>>>> @XmlRootElement(name = "Location")
>>>> public class Location
>>>> {
>>>> private String id;
>>>>
>>>> public Location(String id)
>>>> {
>>>> this.id = id;
>>>> }
>>>>
>>>> public void setId(String id)
>>>> {
>>>> this.id = id;
>>>> }
>>>>
>>>> public String getId()
>>>> {
>>>> return id;
>>>> }
>>>> }
>>>>
>>>> LocationServices.java
>>>> ---------------------
>>>> @Path("/locationservices/")
>>>> public class LocationServices
>>>> {
>>>> private static final Logger log = LogManager
>>>> .getLogger(LocationManagerServiceImpl.class);
>>>>
>>>> @POST
>>>> @Path("/pilot/{id}")
>>>> public Response updatePilotLocations(@PathParam("id") String id,
>>>> Locations locations)
>>>> {
>>>> Long appId = Long.parseLong(id);
>>>> log.debug("Received appid = " + appId);
>>>>
>>>> if (locations == null || locations.getLocations() == null)
>>>> {
>>>> log.warn("Received empty location list.");
>>>> return Response.notModified().build();
>>>> }
>>>>
>>>> for (Location loc : locations.getLocations())
>>>> {
>>>> log.debug("Received loc = " + loc.getId());
>>>> }
>>>>
>>>> return Response.ok(locations).build();
>>>> }
>>>>
>>>> @GET
>>>> @Path("/pilot/{id}")
>>>> public String getPilotLocation(@PathParam("id") String id)
>>>> {
>>>> log.debug("Received id = " + id);
>>>> return "OK";
>>>> }
>>>>
>>>> @GET
>>>> @Path("/pilot/")
>>>> public Locations getPilotLocations()
>>>> {
>>>> log.debug("In getPilotLocations");
>>>> Locations locs = new Locations();
>>>> List<Location> l = new ArrayList<Location>();
>>>> l.add(new Location("1"));
>>>> l.add(new Location("2"));
>>>> locs.setLocations(l);
>>>> return locs;
>>>> }
>>>> }
>>>>
>>>> I am seeing 2 issues related to Collection/List:
>>>>
>>>> Issue #1
>>>> ======
>>>> In getPilotLocations(), it is giving:
>>>> 2009-07-23 17:09:49,387 INFO [STDOUT] (TP-Processor3) 7145811
>>>> [TP-Processor3] DEBUG com.apps.service.rest.LocationServices - In
>>>> getPilotLocations
>>>> 2009-07-23 17:09:49,484 ERROR [STDERR] (TP-Processor3) Jul 23, 2009
>>>> 5:09:49 PM org.apache.cxf.jaxrs.provider.AbstractJAXBProvider
>>>> handleJAXBException
>>>> WARNING: JAXBException occurred : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> 2009-07-23 17:09:49,485 INFO [STDOUT] (TP-Processor3) 7145909
>>>> [TP-Processor3] ERROR STDERR - Jul 23, 2009 5:09:49 PM
>>>> org.apache.cxf.jaxrs.provider.AbstractJAXBProvider handleJAXBException
>>>> WARNING: JAXBException occurred : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> 2009-07-23 17:09:49,493 ERROR [STDERR] (TP-Processor3) Jul 23, 2009
>>>> 5:09:49 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper
>>>> toResponse
>>>> WARNING: WebApplicationException has been caught : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> 2009-07-23 17:09:49,494 INFO [STDOUT] (TP-Processor3) 7145918
>>>> [TP-Processor3] ERROR STDERR - Jul 23, 2009 5:09:49 PM
>>>> org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
>>>> WARNING: WebApplicationException has been caught : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> 2009-07-23 17:09:49,517 ERROR [STDERR] (TP-Processor3) Jul 23, 2009
>>>> 5:09:49 PM
>>>> org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback
>>>> onClose
>>>> INFO: Outbound Message
>>>> ---------------------------
>>>> ID: 1
>>>> Encoding:
>>>> Content-Type: text/plain
>>>> Headers: {Content-Type=[text/plain]}
>>>> Payload: JAXBException occurred : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> --------------------------------------
>>>> 2009-07-23 17:09:49,518 INFO [STDOUT] (TP-Processor3) 7145942
>>>> [TP-Processor3] ERROR STDERR - Jul 23, 2009 5:09:49 PM
>>>> org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback
>>>> onClose
>>>> INFO: Outbound Message
>>>> ---------------------------
>>>> ID: 1
>>>> Encoding:
>>>> Content-Type: text/plain
>>>> Headers: {Content-Type=[text/plain]}
>>>> Payload: JAXBException occurred : 1 counts of
>>>> IllegalAnnotationExceptions
>>>> --------------------------------------
>>>>
>>>> Issue #2
>>>> ======
>>>> In my updatePilotLocations() - a POST, I am seeing null for
>>>> locations.getLocations():
>>>>
>>>> 2009-07-23 16:01:33,850 INFO [STDOUT] (TP-Processor2) 3050274
>>>> [TP-Processor2] ERROR STDERR - Jul 23, 2009 4:01:33 PM
>>>> org.apache.cxf.interceptor.LoggingInInterceptor logging
>>>> INFO: Inbound Message
>>>> ----------------------------
>>>> ID: 1
>>>> Address: /rest/locationservices/pilot/
>>>> Encoding: ISO-8859-1
>>>> Content-Type: text/xml; charset=ISO-8859-1
>>>> Headers: {content-length=[62], host=[test.apps.com],
>>>> user-agent=[Jakarta Commons-HttpClient/3.0], Content-Type=[text/xml;
>>>> charset=ISO-8859-1], content-type=[text/xml; charset=ISO-8859-1],
>>>> Accept=[text/xml]}
>>>> Payload: <Locations>
>>>> <Location>
>>>> <id>1</id>
>>>> </Location>
>>>> </Locations>
>>>> --------------------------------------
>>>> 2009-07-23 16:01:34,023 WARN [com.apps.service.rest.LocationServices]
>>>> (TP-Processor2) Received empty location list.
>>>> 2009-07-23 16:01:34,024 INFO [STDOUT] (TP-Processor2) 3050448
>>>> [TP-Processor2] WARN com.apps.service.rest.LocationServices - Received
>>>> empty location list.
>>>>
>>>> Could someone please shed some light on these issues? I would really
>>>> appreciate your help!
>>>> Thanks
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/CXF-2.2.2-handling-of-Collection-broken--tp24637431p24650537.html
Sent from the cxf-user mailing list archive at Nabble.com.