Quantcast

Blueprint and Pax-Web

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Blueprint and Pax-Web

Castor
Hello, i'm trying to create a servlet using Blueprint and register it to Pax-web using the whiteboard pattern but i'm having some trouble.

I've followed the sample at https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard-blueprint/src/main/resources/OSGI-INF/blueprint/blueprint.xml , but it seems that the pax-web is failing to register the context.

Here's the logs:

2017-04-04 16:09:28,135 | INFO  | nsole user karaf | RotinaServlet                    | 102 - br.com.pcsist.winthor.core.winthor-core-servico - 1.3.0.SNAPSHOT | Servlet registrado no contexto '/852'
2017-04-04 16:09:28,136 | INFO  | nsole user karaf | HttpServiceFactoryImpl           | 64 - org.ops4j.pax.web.pax-web-runtime - 4.3.0 | Binding bundle: [br.com.pcsist.winthor.rotina.winthor-fer-0852 [180]] to http service
2017-04-04 16:09:28,142 | INFO  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | will add org.apache.jasper.servlet.JasperInitializer to ServletContainerInitializers
2017-04-04 16:09:28,142 | INFO  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | Skipt org.apache.jasper.servlet.JasperInitializer, because specialized handler will be present
2017-04-04 16:09:28,142 | INFO  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | will add org.springframework.web.SpringServletContainerInitializer to ServletContainerInitializers
2017-04-04 16:09:28,143 | WARN  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | failed to parse and instantiate of javax.servlet.ServletContainerInitializer in classpath
2017-04-04 16:09:28,143 | INFO  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | will add org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer to ServletContainerInitializers
2017-04-04 16:09:28,161 | INFO  | nsole user karaf | JettyServerWrapper               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | added ServletContainerInitializer: org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer
2017-04-04 16:09:28,162 | INFO  | nsole user karaf | HttpServiceContext               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | registering context DefaultHttpContext [bundle=br.com.pcsist.winthor.rotina.winthor-fer-0852 [180], contextID=default], with context-name:
2017-04-04 16:09:28,163 | INFO  | nsole user karaf | HttpServiceContext               | 63 - org.ops4j.pax.web.pax-web-jetty - 4.3.0 | registering JasperInitializer
2017-04-04 16:09:28,184 | INFO  | nsole user karaf | ContextHandler                   | 50 - org.eclipse.jetty.util - 9.2.19.v20160908 | Started HttpServiceContext{httpContext=DefaultHttpContext [bundle=br.com.pcsist.winthor.rotina.winthor-fer-0852 [180], contextID=default]}

And my blueprint.xml

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

  <bean id="rotinaServlet" class="br.com.pcsist.winthor.core.servico.RotinaServlet">
    <argument type="java.lang.String" value="/852" />
  </bean>

  <service id="rotinaServletService" ref="rotinaServlet" interface="javax.servlet.Servlet">
    <service-properties>
      <entry key="alias" value="/852" />
      <entry key="servlet-name" value="Rotina 852" />
    </service-properties>
  </service>

</blueprint>

The servlet is getting instantiated, without any problem, but it seems that the context is not getting mapped to /852 , since i can't see it in web:list

And here: org.ops4j.pax.web.pax-web-jetty - 4.3.0 | registering context DefaultHttpContext [bundle=br.com.pcsist.winthor.rotina.winthor-fer-0852 [180], contextID=default], with context-name:

i don't see my context in contextName.

What i am doing wrong?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Blueprint and Pax-Web

Castor
Just updating, when i navigate to http://localhost/852 the servlet is called, but i can't see the context registered when a run a web:list, not sure if it's a bug.

Anyway, what i'm trying to do is to use a shared filter in a WAB with pure html/css files, but i'm not being able to find a nice way to share it through the bundles, right now my WABs are using the Web-ContextPath MANIFEST header, which works like a charm, i've exported the filter as an osgi service, but i'm having trouble to use it in my WABs, how can i do that using blueprint?  
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Blueprint and Pax-Web

Castor
I got it!

For future references if someone needs to solve the same problem, i solved it retrieving the OSGI service inside the filter using JNDI, it worked like a charm.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Blueprint and Pax-Web

Achim Nierbeck
Hi, 

glad you found a solution. 
But I think what you actually should be using is more like what is in this sample/integration-test [1]
Registering a Servlet in one Bundle and re-using a filter from another bundle
This is handled by a shared context. 
In your case you just need a resource servlet, which can also be done with DS (reduces the footprint compared to blueprint) [2]
and combine it with the filter in a shared context. 

regards, Achim 



2017-04-05 14:52 GMT+02:00 Castor <[hidden email]>:
I got it!

For future references if someone needs to solve the same problem, i solved
it retrieving the OSGI service inside the filter using JNDI, it worked like
a charm.



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-and-Pax-Web-tp4050033p4050040.html
Sent from the Karaf - User mailing list archive at Nabble.com.



--

Apache Member
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/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master 

Loading...