You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Travis Romney <tr...@gmail.com> on 2014/02/22 02:06:44 UTC

Intermittent problems with JSONObjectEventResultProcessor and Response

I'm using Tapestry 5.3.7, and
I have a Tapestry component that makes an ajax call every 30 seconds.
Most of the requests succeed,
But every so often a request fails seemingly at random intervals.
I've tracked the problem down to the response object being null in
JSONObjectEventResultProcessor.processResultValue,
but, I cannot for the life of me figure out why the response
is null sometimes.

public void processResultValue(JSONObject value) throws IOException
{
    ContentType contentType = new
ContentType(InternalConstants.JSON_MIME_TYPE, outputEncoding);

    *PrintWriter pw = response.getPrintWriter(contentType.toString());  <-
The response is null!*

    value.print(pw, compactJSON);

    pw.close();
}

Here is the stacktrace:
Caused by: java.lang.NullPointerException: Unable to delegate method
invocation to property 'response' of <Proxy for
RequestGlobals(org.apache.tapestry5.services.RequestGlobals)>, because the
property is null.
 at $Response_aaab8be2d799.readProperty(Unknown Source)
at $Response_aaab8be2d799.getPrintWriter(Unknown Source)
 at $Response_aaab8be2d744.getPrintWriter(Unknown Source)
at
org.apache.tapestry5.internal.services.JSONObjectEventResultProcessor.processResultValue(JSONObjectEventResultProcessor.java:58)
 at
org.apache.tapestry5.internal.services.JSONObjectEventResultProcessor.processResultValue(JSONObjectEventResultProcessor.java:33)
at $ComponentEventResultProcessor_aaab8be2dd62.processResultValue(Unknown
Source)
 at $ComponentEventResultProcessor_aaab8be2dd15.processResultValue(Unknown
Source)
at
org.apache.tapestry5.internal.services.AjaxComponentEventRequestHandler$1.processResultValue(AjaxComponentEventRequestHandler.java:80)
 at
org.apache.tapestry5.internal.services.ComponentResultProcessorWrapper.handleResult(ComponentResultProcessorWrapper.java:47)
at
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$6.handleResult(ComponentPageElementImpl.java:1089)
 at
org.apache.tapestry5.internal.services.EventImpl$1.invoke(EventImpl.java:89)
at
org.apache.tapestry5.internal.services.EventImpl$1.invoke(EventImpl.java:86)
 at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Lance Java <la...@googlemail.com>.
It's pretty hacky what you're doing. I think you'll also need to call
Registry.cleanupThread() to give Tapestry a chance to cleanup any PerThread
values that are created during your quasi half arsed Tapestry request ;)

http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/ioc/Registry.html#cleanupThread()
On 24 Feb 2014 23:05, "Lance Java" <la...@googlemail.com> wrote:

> Hmm... This could well be the source of your problem. I think you'll also
> need to call ResponseGlobals. storeServletRequestResponse(...)
>
> I'm not sure I fully understand your non-tapestry flow. Why do you need
> Tapestry to be aware of the JSP requests?
>
> I'm assuming you have contributed to the ignore paths filter so that
> Tapestry ignores your JSP URL's?
>
>
>

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Travis Romney <tr...@gmail.com>.
I finally got to the bottom of this, turned out to be a rather complicated
problem on our end.
Thanks for all your help.



On Tue, Feb 25, 2014 at 12:44 AM, Lance Java <la...@googlemail.com>wrote:

> Hi Travis, a few Q's
>
> 1. Have you configured the ignored paths as documented here:
>
> http://tapestry.apache.org/configuration#Configuration-ConfiguringIgnoredPaths
>
> 2. If so, what's your config?
>
> 3. If not, how does this work?
>
> 4. Give an example t5 url?
>
> 5. Give an example t4 / JSP url
>
> 6. Give an example url that's failing.
>
> Thanks.
>

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Lance Java <la...@googlemail.com>.
Hi Travis, a few Q's

1. Have you configured the ignored paths as documented here:
http://tapestry.apache.org/configuration#Configuration-ConfiguringIgnoredPaths

2. If so, what's your config?

3. If not, how does this work?

4. Give an example t5 url?

5. Give an example t4 / JSP url

6. Give an example url that's failing.

Thanks.

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Travis Romney <tr...@gmail.com>.
It's actually the JSP that needs to be aware of the tapestry requests.
We are injecting tapestry 5 services that have dependencies on the tapestry
5 request into the
JSP or tapestry 4 pages.   Without this code it breaks.

Also we are calling cleanupThread().
I've tried storeServletRequestResponse but it doesn't seem to make any
difference whether it's called or not.



On Mon, Feb 24, 2014 at 4:05 PM, Lance Java <la...@googlemail.com>wrote:

> Hmm... This could well be the source of your problem. I think you'll also
> need to call ResponseGlobals. storeServletRequestResponse(...)
>
> I'm not sure I fully understand your non-tapestry flow. Why do you need
> Tapestry to be aware of the JSP requests?
>
> I'm assuming you have contributed to the ignore paths filter so that
> Tapestry ignores your JSP URL's?
>

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Lance Java <la...@googlemail.com>.
Hmm... This could well be the source of your problem. I think you'll also
need to call ResponseGlobals. storeServletRequestResponse(...)

I'm not sure I fully understand your non-tapestry flow. Why do you need
Tapestry to be aware of the JSP requests?

I'm assuming you have contributed to the ignore paths filter so that
Tapestry ignores your JSP URL's?

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Travis Romney <tr...@gmail.com>.
I've looked at the request/response traffic and nothing looks unusual.
In fact the JSONObject that is passed to
JSONObjectEventResultProcessor.processResultValue(JSONObject value)
looks perfectly fine.

We do have a custom filter, which enables tapestry injection in
non-tapestry 5 environments, (i.e JSP and tapestry 4 pages)
It's a bit of an ugly hack too, but we have not been able to find any
alternatives.

The main module contains this:
public static void contributeHttpServletRequestHandler(
        OrderedConfiguration<HttpServletRequestFilter> configuration) {

    configuration.addInstance("StoreRequestResponseIntoGlobals",
StoreRequestGlobalsFilter.class, "before:*");
}

Here is the filter code.
It's purpose is to provide request/response objects for legacy Tapestry 4
pages and JSPs.
Note that we are using the constructors for Request and Response objects.
If we try to inject these we get a StackOverflowException.

public class StoreRequestGlobalsFilter implements HttpServletRequestFilter {
...
@Override
public boolean service(HttpServletRequest servletRequest,
                       HttpServletResponse servletResponse,
                       HttpServletRequestHandler handler) throws
IOException {

    Request request =
            new RequestImpl(
                    servletRequest,
                    applicationCharset,
                    sessionFactory);

    Response response = new ResponseImpl(servletRequest, servletResponse);

    requestGlobals.storeRequestResponse(request, response);

    return handler.service(servletRequest, servletResponse);
}
}







On Sat, Feb 22, 2014 at 2:14 AM, Lance Java <la...@googlemail.com>wrote:

> Strange, do you have any custom request filters running? Any custom
> threads?
>
> Failing that, can you use the dev tools in your browser to inspect the
> requests / response traffic? Anything strange?
>

Re: Intermittent problems with JSONObjectEventResultProcessor and Response

Posted by Lance Java <la...@googlemail.com>.
Strange, do you have any custom request filters running? Any custom
threads?

Failing that, can you use the dev tools in your browser to inspect the
requests / response traffic? Anything strange?