Hi Achim,

I made it work with a Pax Web Jetty fragment a change to the global SMX 
jetty.xml config file. Or almost…

The request handler gets registered and all requests are logged but the status 
code is always 200, even files are not found etc.

My guess is that my request handler intercepts the requests before the other 
handlers and therefore, when the respons object reaches my custom log it has 
not yet been treated by the other handlers. From what I can tell from the jetty 
documentation handlers are called in order and there does not seem to be a way 
of setting priorities or explicitly managing the handler process order.

Of course one way forward would be to somehow make sure that the handler of my 
custom request log is added last, but frankly I think this is going too far. 
Even if I succeed in this, it surely would be a brittle solution that would 
break with the next SMX/Jetty release or whatever.

I am now starting to think that the only realistic solution is to add support 
for custom RequestLogs in PAX Web Jetty. I imagine a simple setting in 
etc/org.ops4j.pax.web.cfg

        org.ops4j.pax.web.requestLog=<request-log-id>

… where <request-log-id> would be the id of a RequestLog object defined in the 
global jetty.xml. This assumes that it is indeed possible to reference objects 
created there from the Pax Web Jetty configuration, something that I do not at 
all take for granted. Another option would be to have a simple class name as 
the property value but that begs the question on how this class should be 
configured.

If the proposed setting is specified together with the NCSA configuration an 
error should be logged and jetty startup should fail.

A variation of the same theme would be that Pax Web checks if it can find a 
pre-existing RequestLogHandler using the getNestedHandlerByClass on the Server, 
if one is found it is used instead. Not convinced this is a good approach as 
there is no good way of knowing if any found request handlers really are 
applicable to Pax Web.

Would you think it is worth logging a feature request with the Pax Web 
community? In any case it bugs me that I cannot switch out the default NCSA 
RequestLog...

Cheers,

Chris

> On 23 dec 2014, at 12:04, Achim Nierbeck <[email protected]> wrote:
> 
> Hi Chris,
> 
> Good point about the fragment bundle, though actually the jetty.xml found
> in the etc folder will always override one provided by a fragment bundle.
> You might still use this approach to add the logging class to the jetty
> bundle.
> Even though the filter might work I think adding a custom RequestHandler is
> better.
> 
> regards, Achim
> 
> 
> 2014-12-23 0:32 GMT+01:00 Christoffer Soop <[email protected] 
> <mailto:[email protected]>>:
>> 
>> Hi Achim,
>> 
>> Thanks a lot for the (very) rapid feedback! Good to hear that I am headed
>> in the right direction.
>> 
>> Yes, I know about the jetty.xml in the etc folder but I hesitate to change
>> the default one as I still need to provide the implementation class in a
>> lib/bundle somewhere that has to be available when the PAX Web Jetty bundle
>> is configured/started. Doing it with a fragment seems... more self
>> contained and is also the intended way of configuring Jetty in PAX Web from
>> what I can tell.
>> 
>> There is another solution that I have thought about that would achieve
>> much of the same effect and that is to use a Servlet Filter. The big
>> advantage I guess is that we are more in a standard usecase so there is no
>> “hacking” of the SMX distribution. On the other hand I guess I am not able
>> to chop _all_ requests handled by Jetty (which is what I want to do) and
>> also I don’t have access to some of the Jetty specific methods on the
>> request/response objects. Using a custom RequestLog implementation seems
>> like the right way to do it.
>> 
>> Best regards and again thanks,
>> 
>> Chris
>> 
>>> On 23 dec 2014, at 00:09, Achim Nierbeck <[email protected]>
>> wrote:
>>> 
>>> Hi Chris,
>>> 
>>> the NCSA logger is not configured by means of a jetty.xml, it's
>> configured
>>> through the pax web properties configuration / configuration admin.
>>> Never the less you did choose the right approach to add another
>>> RequestLogger. Though you don't need use a fragment bundle.
>>> ServiceMix/Karaf uses a file based jetty.xml which is placed in the etc
>>> folder, you just need to alter that one.
>>> 
>>> The jetty.xml seems to be correct.
>>> A simpler approach by using a service might be an interesting idea,
>> though
>>> it's not supported yet.
>>> 
>>> regards, Achim
>>> 
>>> 
>>> 
>>> 2014-12-22 23:49 GMT+01:00 Christoffer Soop <[email protected]
>> <mailto:[email protected] <mailto:[email protected]>>>:
>>>> 
>>>> Hi,
>>>> 
>>>> I am trying to replace the NCSA log with a custom RequestLog
>>>> implementation in ServiceMix 4.5.3. I started out by lookging at
>>>> 
>>>>              https://wiki.eclipse.org/Jetty/Tutorial/RequestLog 
>>>> <https://wiki.eclipse.org/Jetty/Tutorial/RequestLog> <
>> https://wiki.eclipse.org/Jetty/Tutorial/RequestLog 
>> <https://wiki.eclipse.org/Jetty/Tutorial/RequestLog>> <
>>>> https://wiki.eclipse.org/Jetty/Tutorial/RequestLog 
>>>> <https://wiki.eclipse.org/Jetty/Tutorial/RequestLog> <
>> https://wiki.eclipse.org/Jetty/Tutorial/RequestLog 
>> <https://wiki.eclipse.org/Jetty/Tutorial/RequestLog>>>
>>>> 
>>>> ... but quickly realized I should probably not replace the OPS4J Pax Web
>>>> configuration. Instead I should extend it following the tutorial at
>>>> 
>>>> 
>>>> 
>> https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration 
>> <https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration> <
>> https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration 
>> <https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration>>
>> <
>>>> 
>> https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration 
>> <https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration> <
>> https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration 
>> <https://ops4j1.jira.com/wiki/display/paxweb/Advanced+Jetty+Configuration>>>
>>>> 
>>>> I have thus created a Jetty configuration fragment like so:
>>>> 
>>>> <?xml version="1.0"?>
>>>> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//
>>>> DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd 
>>>> <http://jetty.mortbay.org/configure.dtd> <
>> http://jetty.mortbay.org/configure.dtd 
>> <http://jetty.mortbay.org/configure.dtd>> <
>>>> http://jetty.mortbay.org/configure.dtd 
>>>> <http://jetty.mortbay.org/configure.dtd> <
>> http://jetty.mortbay.org/configure.dtd 
>> <http://jetty.mortbay.org/configure.dtd>>>">
>>>> <Configure class="org.eclipse.jetty.server.Server">
>>>>              <Get name="handler">
>>>>                             <Call name="addHandler">
>>>>                                            <Arg>
>>>>                                                           <New
>>>> id="RequestLog"
>> class="org.eclipse.jetty.server.handler.RequestLogHandler">
>>>> 
>>>> <Set name="requestLog">
>>>> 
>>>>               <New id="RequestLogImpl"
>>>> class="edu.loopback.jetty.CustomJettyRequestLog" />
>>>> 
>>>> </Set>
>>>>                                                           </New>
>>>>                                            </Arg>
>>>>                             </Call>
>>>>              </Get>
>>>> </Configure>
>>>> 
>>>> This I hope will a) fetch the Server configuration and b) add my
>>>> CustomJettyRequestLog to a new RequestLogHandler, assuming it can
>> co-exist
>>>> peacfully with the existing NCSA RequestLogHandler. Replacing the
>> default
>>>> handler would seem like a better option but I have no clue on how to go
>>>> about this…
>>>> 
>>>> Just installing my fragment does not seem to make a difference and when
>> I
>>>> refresh the OPS4J Pax Web - Jetty bundle I get the following error:
>>>> 
>>>> 23:04:39,477 | ERROR | g.ops4j.pax.web) | configadmin
>>>> | 5 - org.apache.felix.configadmin - 1.2.8 | Configuration for
>>>> org.ops4j.pax.web has already been used for service
>>>> [org.osgi.service.cm.ManagedService, id=85, bundle=138] and will now
>> also
>>>> be given to [org.osgi.service.cm.ManagedService, id=293, bundle=138]
>>>> 
>>>> This I take to meet that instead of merging my configuration, a new
>> Jetty
>>>> configuration is added.
>>>> 
>>>> My guess is that I need to make sure that my bundle is loaded before the
>>>> Fragment-Host org.ops4j.pax.web.pax-web-jetty in order to make it the
>> merge
>>>> with the Fragement-Host when starting the Pax Jetty bundle. From what I
>> can
>>>> tell this means I should
>>>> create a feature
>>>> add the service to the startup.properties with a start level below
>>>> (similar to?) the OPS4J Pax Web Jetty bundle
>>>> add the feature and feature repository to org.apache.karaf.features.cfg
>>>> add my bundle to the system repository folder
>>>> As I am already swimming in deep water I would much appreciate any
>>>> feedback on this - in particular if somebody could please validate the
>>>> approach confirming that
>>>> Changing the default NCSA RequestLog implementation requires a Pax Web
>>>> Jetty fragment
>>>> The fragment needs to start before Pax Web Jetty
>>>> The jetty.xml is correct
>>>> Of course, if there is a simpler way to switch to my custom RequestLog I
>>>> am all ears… One could dream of a simple property with a class name
>>>> somewhere...
>>>> 
>>>> Best regards,
>>>> 
>>>> Chris
>>> 
>>> 
>>> 
>>> --
>>> 
>>> Apache Member
>>> Apache Karaf <http://karaf.apache.org/ <http://karaf.apache.org/> 
>>> <http://karaf.apache.org/ <http://karaf.apache.org/>>>
>> Committer & PMC
>>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/ 
>>> <http://wiki.ops4j.org/display/paxweb/Pax+Web/> <
>> http://wiki.ops4j.org/display/paxweb/Pax+Web/ 
>> <http://wiki.ops4j.org/display/paxweb/Pax+Web/>>> Committer &
>>> Project Lead
>>> blog <http://notizblog.nierbeck.de/ <http://notizblog.nierbeck.de/> 
>>> <http://notizblog.nierbeck.de/ <http://notizblog.nierbeck.de/>>>
>>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS 
>>> <http://bit.ly/1ps9rkS> <
>> http://bit.ly/1ps9rkS <http://bit.ly/1ps9rkS>>>
>>> 
>>> Software Architect / Project Manager / Scrum Master
>> 
>> 
> 
> -- 
> 
> Apache Member
> Apache Karaf <http://karaf.apache.org/ <http://karaf.apache.org/>> Committer 
> & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/ 
> <http://wiki.ops4j.org/display/paxweb/Pax+Web/>> Committer &
> Project Lead
> blog <http://notizblog.nierbeck.de/ <http://notizblog.nierbeck.de/>>
> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS 
> <http://bit.ly/1ps9rkS>>
> 
> Software Architect / Project Manager / Scrum Master

Reply via email to