You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ilya Obshadko <il...@gmail.com> on 2014/01/24 13:07:04 UTC

Re: Problems with accessing my SSO from the service layer. request related NPE.

Just run into this thread with a similar problem. I'm implementing REST
service (using tapestry-resteasy) for mobile clients.

I've already found a solution:

    public void contributeHttpServletRequestHandler (
OrderedConfiguration<HttpServletRequestFilter> configuration,

            @Inject @Symbol(SymbolConstants.CHARSET) final String
applicationCharset,

            @Primary final SessionPersistedObjectAnalyzer<?> analyzer,

            final RequestGlobals requestGlobals ) {


        HttpServletRequestFilter storeRequestResponse =
newHttpServletRequestFilter () {

            public boolean service ( HttpServletRequest servletRequest,
HttpServletResponse servletResponse,

                    HttpServletRequestHandler handler ) throws IOException {



                Request request = new RequestImpl ( servletRequest,
applicationCharset, new TapestrySessionFactoryImpl ( false, analyzer,
servletRequest ) );

                Response response = new ResponseImpl ( servletRequest,
servletResponse );

                requestGlobals.storeRequestResponse ( request, response );

                return handler.service ( servletRequest, servletResponse );

            }

        };


        configuration.add("StoreRequestResponse", storeRequestResponse,
"before:*");

    }

But it doesn't look very elegant. Is there any better way to expose
ApplicationStateManager to RestEasy service?



On Fri, Jun 28, 2013 at 12:04 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Thu, 27 Jun 2013 19:46:20 -0300, Jon Williams <
> williams.jonathan@gmail.com> wrote:
>
>  Hi,
>>
>
> Hi!
>
>  My problem has gone away.
>> A short FYI on how I got past this problem...
>>
>> First I tried adding a new request Builder method in QaModule using the
>> shadowbuilder service that would build my TestRequest. But that didn't
>> work because of a Request service implementation collision with predeclared
>> (in TapModule) service Request.class interface implementation. Only 1
>> Request
>> interface implementation is allowed, and TapModule beats me to the punch.
>>
>
> You've already found a very good solution, but I'd like to mention you
> could also use service overriding, so your Request implementation is used
> and not Tapestry's.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Ilya Obshadko

Re: Problems with accessing my SSO from the service layer. request related NPE.

Posted by Ilya Obshadko <il...@gmail.com>.
So I've ended up with the following implementation:

    @Contribute(HttpServletRequestHandler.class)

    public void contributeHttpServletRequestHandler (
OrderedConfiguration<HttpServletRequestFilter> configuration,

            @Inject @Symbol(ResteasySymbols.MAPPING_PREFIX) final String
restFilterPath,

            @Inject @Symbol(SymbolConstants.CHARSET) final String
applicationCharset,

            @Primary final SessionPersistedObjectAnalyzer<?> analyzer,

            final RequestGlobals requestGlobals ) {


        HttpServletRequestFilter storeRestSession =
newHttpServletRequestFilter () {

            public boolean service ( HttpServletRequest servletRequest,
HttpServletResponse servletResponse,

                    HttpServletRequestHandler handler ) throws IOException {



                if ( servletRequest.getServletPath ().startsWith (
restFilterPath + "/" ) ) {

                    Request request = new RequestImpl ( servletRequest,
applicationCharset, new TapestrySessionFactoryImpl ( false, analyzer,
servletRequest ) );

                    Response response = new ResponseImpl ( servletRequest,
servletResponse );

                    requestGlobals.storeRequestResponse ( request, response
);

                }



                return handler.service ( servletRequest, servletResponse );

            }

        };


        configuration.add("StoreRestSession", storeRestSession,
"before:ResteasyRequestFilter");

    }

Probably it's possible to achieve the same goal by overriding RestEasy
request filter.



On Fri, Jan 24, 2014 at 11:07 PM, Ilya Obshadko <il...@gmail.com>wrote:

> Just run into this thread with a similar problem. I'm implementing REST
> service (using tapestry-resteasy) for mobile clients.
>
> I've already found a solution:
>
>     public void contributeHttpServletRequestHandler (
> OrderedConfiguration<HttpServletRequestFilter> configuration,
>
>             @Inject @Symbol(SymbolConstants.CHARSET) final String
> applicationCharset,
>
>             @Primary final SessionPersistedObjectAnalyzer<?> analyzer,
>
>             final RequestGlobals requestGlobals ) {
>
>
>         HttpServletRequestFilter storeRequestResponse = newHttpServletRequestFilter () {
>
>             public boolean service ( HttpServletRequest servletRequest,
> HttpServletResponse servletResponse,
>
>                     HttpServletRequestHandler handler ) throwsIOException {
>
>
>
>                 Request request = new RequestImpl ( servletRequest,
> applicationCharset, new TapestrySessionFactoryImpl ( false, analyzer,
> servletRequest ) );
>
>                 Response response = new ResponseImpl ( servletRequest,
> servletResponse );
>
>                 requestGlobals.storeRequestResponse ( request, response );
>
>                 return handler.service ( servletRequest, servletResponse
> );
>
>             }
>
>         };
>
>
>         configuration.add("StoreRequestResponse", storeRequestResponse,
> "before:*");
>
>     }
>
> But it doesn't look very elegant. Is there any better way to expose
> ApplicationStateManager to RestEasy service?
>
>
>
> On Fri, Jun 28, 2013 at 12:04 PM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Thu, 27 Jun 2013 19:46:20 -0300, Jon Williams <
>> williams.jonathan@gmail.com> wrote:
>>
>>  Hi,
>>>
>>
>> Hi!
>>
>>  My problem has gone away.
>>> A short FYI on how I got past this problem...
>>>
>>> First I tried adding a new request Builder method in QaModule using the
>>> shadowbuilder service that would build my TestRequest. But that didn't
>>> work because of a Request service implementation collision with predeclared
>>> (in TapModule) service Request.class interface implementation. Only 1
>>> Request
>>> interface implementation is allowed, and TapModule beats me to the punch.
>>>
>>
>> You've already found a very good solution, but I'd like to mention you
>> could also use service overriding, so your Request implementation is used
>> and not Tapestry's.
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Ilya Obshadko
>
>


-- 
Ilya Obshadko