title: Configuring hessian service in karaf with spring dm
body: <p>With the environment:</p>
  
  <ul>
  <li>Karaf 3.0.1 </li>
  <li>Spring 3.2.4 </li>
  <li>Hessian 4.0.33</li>
  </ul>
  
  <p>I have already exposed a service via CXF and now I'm trying to expose the same service as a Hessian Service.</p>
  
  <p>There is no war or web.xml, just plain beans + pax-http and I have tried the following:</p>
  
  <pre><code>&lt;bean name="/hessian" class="org.springframework.remoting.caucho.HessianServiceExporter"&gt;
      &lt;property name="service" ref="promocionalOnLineWebServiceBean"/&gt;
      &lt;property name="serviceInterface" value="org.fideliapos.promos.webservice.PromocionalOnLineFacade"/&gt;
  &lt;/bean&gt; 
  ...
  &lt;bean id="hessianServlet" class="org.springframework.web.context.support.HttpRequestHandlerServlet"/&gt;
  ...
  &lt;osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet"&gt;
      &lt;service-properties&gt;
          &lt;entry key="alias" value="/hessian"/&gt;
      &lt;/service-properties&gt;         
  &lt;/osgi:service&gt;
  </code></pre>
  
  <p>The idea is to register a servlet (a HttpRequestHandlerServlet) whose target is a HessianServiceExporter but I'm getting a <strong>No WebApplicationContext found: no ContextLoaderListener registered?</strong>.</p>
  
  <p>I have traced the spring code and the internal jetty is recognizing the servlet and calling its init method:</p>
  
  <pre><code>@Override
  public void init() throws ServletException {
      WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
      this.target = wac.getBean(getServletName(), HttpRequestHandler.class);
  }
  </code></pre>
  
  <p>and here lies the problem, since there is no spring WebApplicationContext and the target property cannot be inyected.</p>
  
  <p>Am I missing something? or it is not possible to make it work like this.</p>
  
  <p>As a workaround I'm considering extending the Servlet with my own implementation (setTarget and so) but I'd rather not to do it.</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>After trying to create and add my own HttpContext there is still something missing:</p>
  
  <p>I implemented my own HttpContext:</p>
  
  <pre><code>public class HessianContext implements HttpContext{
  ...
  }
  </code></pre>
  
  <p>added the bean </p>
  
  <pre><code>&lt;bean id="hessianContext" class="org.fideliapos.promos.hessian.HessianContext"/&gt;
  </code></pre>
  
  <p>the service:</p>
  
  <pre><code>&lt;osgi:service id="hessianContextService" ref="hessianContext" interface="org.osgi.service.http.HttpContext"&gt;
      &lt;service-properties&gt;
          &lt;entry key="httpContext.id" value="hessian"/&gt; &lt;!-- also tried with contextId--&gt;
      &lt;/service-properties&gt;
  &lt;/osgi:service&gt;     
  </code></pre>
  
  <p>and finally the servlet as a service:</p>
  
  <pre><code>&lt;osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet"&gt;
      &lt;service-properties&gt;
          &lt;entry key="alias" value="/hessian"/&gt;
          &lt;entry key="httpContext.id" value="hessian"/&gt; &lt;!-- also tried with contextId--&gt;      
      &lt;/service-properties&gt;         
  &lt;/osgi:service&gt;
  </code></pre>
  
  <p>Since the <strong>init method</strong> is looking for a WebApplicationContext it looks like I should declare and <strong>explicit GenericWebApplicationContext bean</strong> but I dont know how to 'join' this bean with the required HttpContext for OSGi.</p>