4 Replies Latest reply on Jan 14, 2012 10:28 AM by 909336

    An adapter to listen and accept Http requests.

      Hi guys
      I am new to this great technology, what I want to do is simply create an adapter that will listen for HTTP requests, clients will connect to the server send some data like a ordinary web browser and server. It is along the ideas covered in this forum.
      Re: How to build HTTP Adapter in CEP?

      I have created my adapter extending from HttpServlet implementing StreamSource. I cannot figure out which url on my localhost should i connect to, as i am getting

      HTTP ERROR 404
      Problem accessing /ForexRates/ticks. Reason:

      Application name is: ForexRates.
      My adapter code:
      public class HttpServletAdapter extends HttpServlet implements StreamSource{
           private HttpService httpService=null;
           private StreamSender eventSender;
           public void init(ServletConfig config) throws ServletException {
                try {
                     config.getServletContext().log("Initialising HTTP Servlet Adapter....");
                     httpService.registerServlet("/ticks", this, null, null);
                } catch (NamespaceException nex) {
                     throw new ServletException(nex);
           public void setHttpService(HttpService httpService) {
                this.httpService = httpService;
      my context xml file
      <osgi:reference id="jetty" interface="org.osgi.service.http.HttpService"/>

      <!-- Incoming Forex Rates Adapter -->
      <wlevs:adapter id="ratesFeedAdapter" class="com.....HttpServletAdapter" advertise="true">
      <wlevs:instance-property name="httpService" ref="jetty"/>


      it got me thinking, isn't there a service/adapter out of the box that I can use, configure the server context path, add a converter for requests received or simply assign a java class to grab the request where name/value pairs match the bean properties. If there is such an adapter how do i configure it?
        • 1. Re: An adapter to listen and accept Http requests.
          Your code looks OK to me. Have you tried connecting without including the "ForexRates" app name in the URL:


          Also make sure the port you're using in the URL is the one configured for Jetty/Netio in the server config.xml (the default is usually 9002). If this still doesn't work let us know and we can look further.

          As far as an out of the box adapter for this type of HTTP connectivity, I'm afraid there's nothing in the current product but we're looking at that for a future release.

          • 2. Re: An adapter to listen and accept Http requests.
            I have tried using localhost:9002/ticks without the application name, and I am still getting the same exception: HTTP ERROR 404 NOT_FOUND.
            How are other developers doing it? At this moment i can settle even for a direct tcp/ip socket connection. But i would prefer some Http requests.

            Edited by: 906333 on Jan 11, 2012 6:46 PM
            • 3. Re: An adapter to listen and accept Http requests.
              I think the problem is that you're trying to register the servlet inside the servlet init() method, and the servlet init() method won't be called until after the servlet has been successfully registered with the HTTP service. I'd suggest doing the servlet registration in one of the bean lifecycle methods. For example if you have the adapter implement InitializingBean:


              and then do the servlet registration in the afterPropertiesSet method, I think it will work and you should be able to connect at localhost:9002/ticks.
                   public void afterPropertiesSet() throws Exception {
                        try {
                             httpService.registerServlet("/ticks", this, null, null);
                        } catch (Exception ex) {
                             throw new ServletException(ex);
              • 4. Re: An adapter to listen and accept Http requests.
                Of course yes it works now thanks.