Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTPRequestHandlerFactory and request.getURI()

Please post support and help requests here.

HTTPRequestHandlerFactory and request.getURI()

Postby GOTTMODUS » 22 Jan 2009, 03:46

Hello,

I copied the HTTPTimeServer Example to test the POCO Webserver functions. But if I hit http://localhost/ or http://localhost/test.html or something else the createRequestHandler(const HTTPServerRequest& request) only gives me an empty string. Here is my test code:

Code: Select all
HTTPRequestHandler* Server::createRequestHandler(const HTTPServerRequest& request) {
   std::cout << "Incoming request " << request.getURI() << std::endl;
   
   if (request.getURI() == "/")
      return new SurveyServer::SurveyRequestHandler();
   else {
      std::cout << "CRAB!!!" << std::endl;
      return new SurveyServer::SurveyRequestHandler();
   }
}


Is this a bug or is it my fault?

Greetings Kersten
GOTTMODUS
 
Posts: 3
Joined: 20 Jan 2009, 01:54

Re: HTTPRequestHandlerFactory and request.getURI()

Postby peter » 22 Jan 2009, 13:22

That depends :-)

I guess you are starting your HTTPServer on port 80? There is also no other webserver running (e.g. IIS).
You see that your requesthandlerfactory gets called? To debug, add some debugging output to the requesthandlerfactory
which simply prints the URI of the request. Then set a breakpoint in your requesthandler to see if it gets invoked and what it generates
as HTML response.

hope that helps,

Peter
peter
 
Posts: 67
Joined: 11 Jul 2006, 16:26
Location: Austria

Re: HTTPRequestHandlerFactory and request.getURI()

Postby guenter » 22 Jan 2009, 13:28

Request.getURI() does work from within the factory. Try adding the line

Code: Select all
std::cout << request.getURI() << std::endl;


at the beginning of FormRequestHandlerFactory::createRequestHandler() to verify that it works (it does for me).

Günter
guenter
 
Posts: 1117
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTPRequestHandlerFactory and request.getURI()

Postby GOTTMODUS » 23 Jan 2009, 02:11

This didn't work. I still get an empty string. I reigster the Factory with
Code: Select all
HTTPServer srv(new SurveyServer::SurveyRequestHandlerFactory(), svs, pParams);


SurveyRequestHandlerFactory.h
Code: Select all
#include <Poco/Util/Application.h>

#include <Poco/Net/HTTPRequestHandler.h>
#include <Poco/Net/HTTPRequestHandlerFactory.h>

#include <Poco/Net/HTTPServerRequest.h>

#include "SurveyRequestHandler.h"

using Poco::Util::Application;

using Poco::Net::HTTPRequestHandler;
using Poco::Net::HTTPRequestHandlerFactory;

using Poco::Net::HTTPServerRequest;

namespace SurveyServer {
   class SurveyRequestHandlerFactory: public HTTPRequestHandlerFactory {
   public:
      SurveyRequestHandlerFactory();
      
      HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request);
   };
};


SurveyRequestHandlerFactory.cpp
Code: Select all
#include "SurveyRequestHandlerFactory.h"
#include <iostream>

SurveyServer::SurveyRequestHandlerFactory::SurveyRequestHandlerFactory()
{
   std::cout << "FactoryStarted..." << std::endl;
}

HTTPRequestHandler* SurveyServer::SurveyRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request)
{
   //Application& app = Application::instance();
   //app.logger().information("incoming request ");
   std::cout << request.getURI() << std::endl;
   std::cout << "Incoming request " << request.getURI() << std::endl;
   
   if (request.getURI() == "/")
      return new SurveyServer::SurveyRequestHandler();
   else {
      std::cout << "CRAB!!!" << std::endl;
      return new SurveyServer::SurveyRequestHandler();
   }
}


And my output is:
Code: Select all
Incoming request
CRAB!!!
Request from 127.0.0.1:55182


I don't know why this is emtpy.

I Have a Intel Mac Pro with OS X 10.5.6 and gcc 4.0 but I don't think that is the problem.

** EDIT:

Wired, the sample HTTPTimeServer works like a charm. By the way the displayHelp and app.logger won't work too. Did i forgot something?
GOTTMODUS
 
Posts: 3
Joined: 20 Jan 2009, 01:54

Re: HTTPRequestHandlerFactory and request.getURI()

Postby guenter » 23 Jan 2009, 09:29

I also work on OS X 10.5 and don't have any issues. Maybe a clean rebuild of the POCO libraries and your application will help?
guenter
 
Posts: 1117
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron