Tomee 7.1.1: when there is an exception during JAXB marshaling, an incomplete response is sent with a 200 code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Tomee 7.1.1: when there is an exception during JAXB marshaling, an incomplete response is sent with a 200 code

kerickson
I would file this in JIRA but I'm having login troubles at the minute, I
want to put this here in case I forget because it definitely seems like a
bug, albeit one that only happens in a buggy usecase. The line "for (String
s : stuffs)" below creates an NPE, but the problem is that the response is
sent back with as a 200 and a clipped body.. which is simply "[{". It
stopped generating the response body when the property getter method was
hit.


My resource:


    @GET
    @ApiOperation(value = "Get stuff")
    @Produces(MediaType.APPLICATION_JSON)
    public List<TestDO> list(@Context HttpServletResponse response) {
        TestDO stuff = new TestDO();
        stuff.setId(1);

        List<TestDO> things = new ArrayList<>();
        things.add(stuff);
        return things;
    }

My data object:

@XmlRootElement(name = "Test")
@XmlAccessorType(XmlAccessType.FIELD)
@ApiModel(value = "Test", description = "Test object")
public class TestDO {

    private int id;
    private List<String> stuffs = null;

    /**
     * Empty constructor, required by JAXB.
     */
    public TestDO() {
    }

    public TestDO(int id, String stuffs) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<String> getStuffs() {
        for (String s : stuffs)
            System.out.println(s);
        return stuffs;
    }

    public void setStuffs(List<String> stuffs) {
        this.stuffs = null;
    }

}



This error is shown in log when this happens:

24-Sep-2019 16:42:53.779 SEVERE [ouc5]
org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem with
writing the data, class java.util.ArrayList, ContentType: application/json
Reply | Threaded
Open this post in threaded view
|

Re: Tomee 7.1.1: when there is an exception during JAXB marshaling, an incomplete response is sent with a 200 code

jgallimore
Hi

Thanks for reporting this. I haven't tried your code, and I'll give it a go
today - does this happen consistently or randomly when accessing this
endpoint?

Jon

On Wed, Sep 25, 2019 at 12:50 AM Kean Erickson <[hidden email]>
wrote:

> I would file this in JIRA but I'm having login troubles at the minute, I
> want to put this here in case I forget because it definitely seems like a
> bug, albeit one that only happens in a buggy usecase. The line "for (String
> s : stuffs)" below creates an NPE, but the problem is that the response is
> sent back with as a 200 and a clipped body.. which is simply "[{". It
> stopped generating the response body when the property getter method was
> hit.
>
>
> My resource:
>
>
>     @GET
>     @ApiOperation(value = "Get stuff")
>     @Produces(MediaType.APPLICATION_JSON)
>     public List<TestDO> list(@Context HttpServletResponse response) {
>         TestDO stuff = new TestDO();
>         stuff.setId(1);
>
>         List<TestDO> things = new ArrayList<>();
>         things.add(stuff);
>         return things;
>     }
>
> My data object:
>
> @XmlRootElement(name = "Test")
> @XmlAccessorType(XmlAccessType.FIELD)
> @ApiModel(value = "Test", description = "Test object")
> public class TestDO {
>
>     private int id;
>     private List<String> stuffs = null;
>
>     /**
>      * Empty constructor, required by JAXB.
>      */
>     public TestDO() {
>     }
>
>     public TestDO(int id, String stuffs) {
>         this.id = id;
>     }
>
>     public int getId() {
>         return id;
>     }
>
>     public void setId(int id) {
>         this.id = id;
>     }
>
>     public List<String> getStuffs() {
>         for (String s : stuffs)
>             System.out.println(s);
>         return stuffs;
>     }
>
>     public void setStuffs(List<String> stuffs) {
>         this.stuffs = null;
>     }
>
> }
>
>
>
> This error is shown in log when this happens:
>
> 24-Sep-2019 16:42:53.779 SEVERE [ouc5]
> org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem with
> writing the data, class java.util.ArrayList, ContentType: application/json
>
Reply | Threaded
Open this post in threaded view
|

Re: Tomee 7.1.1: when there is an exception during JAXB marshaling, an incomplete response is sent with a 200 code

kerickson
No problem. It seems to happen every time, workaround is just to fix the
NPE.

On Wed, Sep 25, 2019, 3:41 AM Jonathan Gallimore <
[hidden email]> wrote:

> Hi
>
> Thanks for reporting this. I haven't tried your code, and I'll give it a go
> today - does this happen consistently or randomly when accessing this
> endpoint?
>
> Jon
>
> On Wed, Sep 25, 2019 at 12:50 AM Kean Erickson <[hidden email]>
> wrote:
>
> > I would file this in JIRA but I'm having login troubles at the minute, I
> > want to put this here in case I forget because it definitely seems like a
> > bug, albeit one that only happens in a buggy usecase. The line "for
> (String
> > s : stuffs)" below creates an NPE, but the problem is that the response
> is
> > sent back with as a 200 and a clipped body.. which is simply "[{". It
> > stopped generating the response body when the property getter method was
> > hit.
> >
> >
> > My resource:
> >
> >
> >     @GET
> >     @ApiOperation(value = "Get stuff")
> >     @Produces(MediaType.APPLICATION_JSON)
> >     public List<TestDO> list(@Context HttpServletResponse response) {
> >         TestDO stuff = new TestDO();
> >         stuff.setId(1);
> >
> >         List<TestDO> things = new ArrayList<>();
> >         things.add(stuff);
> >         return things;
> >     }
> >
> > My data object:
> >
> > @XmlRootElement(name = "Test")
> > @XmlAccessorType(XmlAccessType.FIELD)
> > @ApiModel(value = "Test", description = "Test object")
> > public class TestDO {
> >
> >     private int id;
> >     private List<String> stuffs = null;
> >
> >     /**
> >      * Empty constructor, required by JAXB.
> >      */
> >     public TestDO() {
> >     }
> >
> >     public TestDO(int id, String stuffs) {
> >         this.id = id;
> >     }
> >
> >     public int getId() {
> >         return id;
> >     }
> >
> >     public void setId(int id) {
> >         this.id = id;
> >     }
> >
> >     public List<String> getStuffs() {
> >         for (String s : stuffs)
> >             System.out.println(s);
> >         return stuffs;
> >     }
> >
> >     public void setStuffs(List<String> stuffs) {
> >         this.stuffs = null;
> >     }
> >
> > }
> >
> >
> >
> > This error is shown in log when this happens:
> >
> > 24-Sep-2019 16:42:53.779 SEVERE [ouc5]
> > org.apache.cxf.jaxrs.utils.JAXRSUtils.logMessageHandlerProblem Problem
> with
> > writing the data, class java.util.ArrayList, ContentType:
> application/json
> >
>