cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: AW: How to forward requests to a JSP page when using CXFNonSpringJaxrsServlet
Date Wed, 08 Apr 2015 11:02:40 GMT
Hi Marko

This is one way to do it, yes, does not even has to be on the same line, 
example,
org.apache.cxf.jaxrs.provider.RequestDispatcherProvider
(
resource.Status.JSP1=/hello.jsp
resource.Status.JSP2=/foo.jsp
)

Perhaps another alternative is to wrap an enum value into a bean class 
and redirect to a single JSP resource, which will get the bean, check 
the enum, delegate to specific JSPs...

Cheers, Sergey

On 08/04/15 06:47, Voss, Marko wrote:
> Hello Sergey,
>
> variant 2 was just an idea but is not really helpful, because of we need to do some logic
in order to decide, which JSP to call. So we have to execute some code.
>
> So the idea I got is the following: The servlet does execute the code and returns an
enum value. Based on the enum value, the RequestDispatcher decides, which JSP to call. This
might look like this:
>
> org.apache.cxf.jaxrs.provider.RequestDispatcherProvider(resource.Status.JSP1=/hello.jsp
> resource.Status.JSP2=/foo.jsp)
>
> The Response object gets the enum value as its entity.
>
> Is this correct?
>
>
> Thank you very much and best regards,
>
> Marko
>
> -----Urspr√ľngliche Nachricht-----
> Von: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> Gesendet: Dienstag, 7. April 2015 17:40
> An: users@cxf.apache.org
> Betreff: Re: How to forward requests to a JSP page when using CXFNonSpringJaxrsServlet
>
> Hi,
>
> Please see comments below
> On 07/04/15 14:42, Voss, Marko wrote:
>> Hello,
>>
>> I do have the following situation:
>>
>> We have to use the CXFNonSpringJaxrsServlet for implementing the REST endpoints.
>>
>> The main servlet (old code to be replaced by the new REST endpoints)
>> of the application does implement internal forwarding to JSP pages.
>> (for example to a login page)
>>
>>
>> 1.      I tried to implement the forwarding as it was already done by the old servlet
using:
>>
>> @Context
>> private ServletContext context;
>>
>> context.getRequestDispatcher(url).forward(request, response);
>>
>> But this does not work, because of a ClassCastException happening. The
>> exception message was like: The ThreadLocal instance for
>> ServletContext could not be casted to the RequestDispatcher instance,
>> which is provided by the server. (NetWeaver)
>>
>> The ThreadLocal object is provided by CXF and the RequestDispatcher implementation
is provided by NetWeaver. Of course, this will not work.
> Hmm, interesting, may make sense supporting this variation, I'll have a look...
>
>>
>>
>> 2.       I was trying to use the RequestDispatcherProvider of CXF, but how can you
configure this provider using the CXFNonSpringJaxrsServlet?
>>
>> <servlet>
>>                <servlet-name>RestfulApp</servlet-name>
>>                <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
>>                <init-param>
>>                       <param-name>jaxrs.serviceClasses</param-name>
>>                       <param-value>
>>                       ...
>>                       </param-value>
>>                </init-param>
>>                <init-param>
>>                       <param-name>jaxrs.providers</param-name>
>>                       <param-value>
>>                       org.apache.cxf.jaxrs.provider.RequestDispatcherProvider
>>                       <!-- How to configure this one here??? -->
>>                       </param-value>
>>                </init-param>
>>                <load-on-startup>1</load-on-startup>
>>          </servlet>
>>
>
> The simplest way to do at a servlet level is to use redirect parameters, see
>
> https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml;h=a2212337bd6a9ed7a212b21a6826850581601121;hb=HEAD
>
> or indeed you can directly configure this provider (and other providers) as a parameter,
do something like
>
> org.apache.cxf.jaxrs.provider.RequestDispatcherProvider(resourcePath=/WEB-INF/jsp/test.jsp
> someotherproperty=somevalue)
>
>
>>
>> 3.       I was trying to implement a RequestHandler, which worked but when the forwarding
happens, I get spammed by error messages on server side, that the OutputStreams of the servlets
are already taken by a getWriter() method. This spam should be avoided. Example Spam:
>>
>> WARNING: Interceptor for {http://impl.jaxrs.web.foo.bar/}MyServiceImpl has thrown
exception, unwinding now
>> com.sap.engine.services.servlets_jsp.server.exceptions.WebIllegalStateException:
The stream has already been taken by method [getWriter()].
>> at com.sap.engine.services.servlets_jsp.server.runtime.client.HttpServletResponseFacade.getOutputStream(HttpServletResponseFacade.java:244)
>>
>> This servlet is not in use at all at this point of the request and not after the
request as well. So I wonder in general, why this exception occurs on this servlet. It is
maybe a NetWeaver thing.
>>
>>
>> 4.       I was trying to implement an equivalent to the RequestDispatcherProvider,
doing things here by code. But even when this works, I still get the spam from above.
>>
> In both cases the outbound CXF JAX-RS interceptor and Http transport
> need to know the request has been redirected, this can be done by
> setting an "http.request.redirected" property on the current message,
>
> message.put("http.request.redirected", true)
>
> But the option 2 is simpler, can you try it and let me know if it works
> for you ?
>
> Thanks, Sergey
>
>>
>> Any help is much appreciated.
>>
>>
>> Best regards,
>>
>> Marko
>>
>


Mime
View raw message