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