Gareth,

no problem at all, though it makes me wonder why it should work for
the samples and not for you.
I guess I'll have to dig into this one day.

So much to do and so less time :-)

regards, Achim

2011/7/27 Gareth Collins <[email protected]>:
> Hello Achim,
>
> Thank you very much again for responding. I wouldn't be so rude as to
> send off a question without
> looking up the documentation or the examples. A reason why I sent off
> this question is that I couldn't
> see anything different to what the whiteboard example was doing (just
> like I do, the whiteboard example registers the httpcontext, registers
> a servlet with this context, then registers another servlet without
> the context):
>
>    public void start( final BundleContext bundleContext )
>        throws Exception
>    {
>        Dictionary props;
>
>        // register a custom http context that forbids access
>        props = new Hashtable();
>        props.put( ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden" );
>        m_httpContextReg =
>            bundleContext.registerService(
> HttpContext.class.getName(), new WhiteboardContext(), props );
>        // and an servlet that cannot be accessed due to the above context
>        props = new Hashtable();
>        props.put( ExtenderConstants.PROPERTY_ALIAS, "/forbidden" );
>        props.put( ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "forbidden" );
>        m_forbiddenServletReg =
>            bundleContext.registerService( Servlet.class.getName(),
> new WhiteboardServlet( "/forbidden" ), props );
>
>        props = new Hashtable();
>        props.put( "alias", "/whiteboard" );
>        m_servletReg =
>            bundleContext.registerService( Servlet.class.getName(),
> new WhiteboardServlet( "/whiteboard" ), props );
>
> Anyway, as you saw by my other question on the Karaf forum, it appears
> that taking advantage of the Pax OSGi
> wab functionality is a better option than using the OSGi http service,
> so finding out why this doesn't work isn't so important to me anymore.
>
> Thanks again for your help.
>
> Gareth
>
>
> On Tue, Jul 26, 2011 at 6:55 PM, Achim Nierbeck <[email protected]> 
> wrote:
>> Hi Gareth,
>>
>> I'll try to answer your questions inline so see below.
>>
>> regards, Achim
>>
>> Am 26.07.2011 16:28, schrieb Gareth Collins:
>>>
>>> Hello Achim,
>>>
>>> Thank you very much! In couldn't figure out what I was doing wrong!
>>>
>>> I have a couple of follow-ups if you don't mind.
>>>
>>> When I set up two servlets (one with a HttpContext, one without ->  I
>>> wanted to see if I could forward a request from one servlet to another
>>> with filters using OSGi), I am getting the following exception:
>>
>> OK, well you are able to register Filters just like servlets.
>> To get a better understanding on how pax web works you
>> might take a look at the samples which are also used for the integration
>> tests.
>>
>>>
>>> 17:44:21,278 | DEBUG | lixDispatchQueue | pax-web-extender-whiteboard
>>>     | ?                                   ? | 106 -
>>> org.ops4j.pax.web.pax-web-extender-whiteboard - 1.0.4 | FrameworkEve
>>> nt ERRORjava.lang.IllegalStateException: Http context already used.
>>> Context params can be set only before first usage
>>>         at
>>> org.ops4j.pax.web.service.internal.HttpServiceStarted.setContextParam(HttpServiceStarted.java:353)[62:org.ops4j.pax.web.pax-web-runtime:1.0.4]
>>>
>>> What could cause this? Here is my code:
>>>
>>>        @Override
>>>        public void start(BundleContext context) throws Exception {
>>>                Hashtable<String,String>  props = new
>>> Hashtable<String,String>();
>>>
>>>            props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID,
>>> "myServiceContext");
>>>            this.contextRegistration =
>>> context.registerService(HttpContext.class.getName(), new
>>> MyHttpContext(), props);
>>>            props = new Hashtable<String,String>();
>>>            props.put(ExtenderConstants.PROPERTY_ALIAS, "/myservice");
>>>            props.put(ExtenderConstants.PROPERTY_SERVLET_NAMES,"My
>>> Servlet");
>>>            props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID,
>>> "myServiceContext");
>>>
>>>            this.registration =
>>> context.registerService(Servlet.class.getName(), new MyServlet(),
>>> props);
>>>
>>>            props = new Hashtable<String,String>();
>>>            props.put(ExtenderConstants.PROPERTY_SERVLET_NAMES,"Forward
>>> Servlet");
>>>            props.put(ExtenderConstants.PROPERTY_ALIAS, "/forwardservlet");
>>>>>
>>>>> Exception called here>> this.forwardRegistration =
>>>>> context.registerService(Servlet.class.getName(), new ForwardServlet(),
>>>>> props);
>>>
>>>        }
>>
>> Just giving it a quick glance right now, I'd think this is due to the fact
>> that you try to register a servlet instead of a filter.
>> Again take a look at the samples those might give you a better
>> understanding.
>> Another good resource for studying is the pax wicket project. There are also
>> Samples that use the HTTP-Service quite a lot.
>>
>>>
>>> Anything obvious I am doing wrong?
>>>
>>> As a final question on OSGi and http, I understand that in OSGi 4.2
>>> support for web application bundles (which I understand PAX implements
>>> for the major OSGi implementations?). Given this fact is there any
>>> advantage to not use wab and stick with the base OSGi Http Service (+
>>> PAX extensions)? From my research (I could be looking in the wrong
>>> place), it doesn't appear that the base OSGi Http Service is used
>>> widely (e.g. I haven't been able to find a serious security
>>> implementation done using the HttpContext, just very basic examples).
>>
>> As I already mentioned Pax Web is the reference Implementation of a wab
>> environment.
>> Again taking a look at the samples you might find what you need.
>>
>>> Again, thank you for very much for your help!
>>>
>>> regards,
>>> Gareth
>>>
>>>
>>>
>>> On Mon, Jul 25, 2011 at 5:38 PM, Achim Nierbeck<[email protected]>
>>>  wrote:
>>>>
>>>> Hi Gareth,
>>>>
>>>> sorry that it took me so long to answer.
>>>> But I also am making it short :-)
>>>>
>>>> You are absolutely right you need to register Servlet and Context
>>>> within the same bundle. The Whiteboard extension doesn't behave any
>>>> different
>>>> then the HTTP Service. The only difference and this really helps is
>>>> that you just register you're own Servlet-Service where the whiteboard
>>>> extension jumps in and does all the rest for you.
>>>> With the classical HTTP Service you have to do all the work by yourself.
>>>>
>>>> Regards, Achim
>>>>
>>>>
>>>> Am 23.07.2011 05:25, schrieb Gareth Collins:
>>>>>
>>>>> Hello,
>>>>> I am trying to understand how to use the PAX Web Whiteboard correctly.
>>>>> I was hoping, with the whiteboard pattern, I could completely separate
>>>>> my code for auth (HttpContext) from my Servlet. I am currently using
>>>>> PAX web 1.0.4 (which comes packaged with Karaf 2.2.2).
>>>>>
>>>>> So to test out the whiteboard pattern I created two bundles, each with
>>>>> two java files:
>>>>>
>>>>> - Bundle1
>>>>>     + Activator.java - The activator start method:
>>>>>
>>>>> @Override
>>>>> public void start(BundleContext context) throws Exception {
>>>>>     Hashtable<String,Object>    props = new Hashtable<String,Object>();
>>>>>     props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "myContext");
>>>>>     this.registration =
>>>>> context.registerService(HttpContext.class.getName(), new
>>>>> MyHttpContext(), props);
>>>>> }
>>>>>     + MyHttpContext.java
>>>>>
>>>>> - Bundle2
>>>>>     + Activator.java - The activator start method:
>>>>>
>>>>> @Override
>>>>> public void start(BundleContext context) throws Exception {
>>>>>     Hashtable<String,Object>    props = new Hashtable<String,Object>();
>>>>>     props.put(ExtenderConstants.PROPERTY_ALIAS, "/myservice");
>>>>>     props.put(ExtenderConstants.PROPERTY_SERVLET_NAMES,"My Great
>>>>> Servlet");
>>>>>     props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, "myContext");
>>>>>     this.registration =
>>>>> context.registerService(Servlet.class.getName(), new MyHttpServlet(),
>>>>> props);
>>>>> }
>>>>>
>>>>>     + MyHttpServlet.java
>>>>>
>>>>> When I try and run these two bundles in pax/karaf and access the web
>>>>> page (http://localhost:8181/myservice), it doesn't work. I see in the
>>>>> log the following:
>>>>>
>>>>> 15:51:56,778 | DEBUG |  /profileservice | ServerModel
>>>>>     | eb.service.spi.model.ServerModel  296 | 61 -
>>>>> org.ops4j.pax.web.pax-web-spi - 1.0.4 | Path [/myservice] does not
>>>>> match any context
>>>>>
>>>>> I went back to the pax web whiteboard example and noticed that in the
>>>>> example both the sample Servlet and sample HttpContext were defined in
>>>>> the one bundle, so I changed my code to register MyHttpServlet and
>>>>> MyHttpContext in one bundle...and it worked (the handleSecurity for
>>>>> the context was called before running service on the Servlet)!
>>>>>
>>>>> So, given my testing, it appears that I need to register the servlet
>>>>> and context together in the one bundle. Is that correct...or have I
>>>>> misunderstood something (which is very possible as I am new to this
>>>>> :))?
>>>>>
>>>>> If anyone could provide any guidance, it would be a big help.
>>>>>
>>>>> thanks in advance,
>>>>> Gareth
>>>>>
>>>>> _______________________________________________
>>>>> general mailing list
>>>>> [email protected]
>>>>> http://lists.ops4j.org/mailman/listinfo/general
>>>>
>>>> --
>>>> --
>>>> *Achim Nierbeck*
>>>>
>>>>
>>>> Apache Karaf<http://karaf.apache.org/>    Committer&    PMC
>>>> OPS4J Pax Web<http://wiki.ops4j.org/display/paxweb/Pax+Web/>
>>>>  Committer&
>>>>  Project Lead
>>>> blog<http://notizblog.nierbeck.de/>
>>>>
>>>>
>>>> _______________________________________________
>>>> general mailing list
>>>> [email protected]
>>>> http://lists.ops4j.org/mailman/listinfo/general
>>>>
>>> _______________________________________________
>>> general mailing list
>>> [email protected]
>>> http://lists.ops4j.org/mailman/listinfo/general
>>
>>
>> --
>> --
>> *Achim Nierbeck*
>>
>>
>> Apache Karaf<http://karaf.apache.org/>  Committer&  PMC
>> OPS4J Pax Web<http://wiki.ops4j.org/display/paxweb/Pax+Web/>    Committer&
>>  Project Lead
>> blog<http://notizblog.nierbeck.de/>
>>
>>
>> _______________________________________________
>> general mailing list
>> [email protected]
>> http://lists.ops4j.org/mailman/listinfo/general
>>
>
> _______________________________________________
> general mailing list
> [email protected]
> http://lists.ops4j.org/mailman/listinfo/general
>



-- 
--
*Achim Nierbeck*


Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
blog <http://notizblog.nierbeck.de/>

_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to