I need to use Wt::WApplication from a standalone function:

In Configuration.C in need to change docRoot based on the URL (see 
http://redmine.emweb.be/issues/3404):

void Configuration::readOptions(const po::variables_map& vm)
{
  if (vm.count("docroot"))
  {
    docRoot_ = vm["docroot"].as<std::string>();

 std::string myCDR;
 // Get host Name
 // const Wt::WEnvironment& env = new Wt::WEnvironment(); // is protected, so 
you can not do this
 Wt::WApplication *app = new Wt::WApplication(env);
 Wt::WApplication *app = Wt::WApplication::instance();

both of these cause segment fault
did not really get this far, since it crashed before even getting here

 MyApplication* myapp = boost::polymorphic_downcast(app);

I want to change the docRoot based on the URL
 std::string domainName = app->environment().hostName().c_str();
 // Remove Port if it exist
 unsigned pos = domainName.find(":");
 if (pos > 0)
   domainName = domainName.substr(0, pos);
 // Now do a look up
 if (!Wt::WApplication::readConfigurationProperty("customDocRoot-" + 
domainName, myCDR))
     Wt::log("error") << "WApplication::docRoot() readConfigurationProperty not 
found customDocRoot-" << domainName << " in wt_config.xml";
 if (!myCDR.empty())
   docRoot_ = myCDR.c_str();

Since all I really need is a way to get the domainName and read from wt_config, 
there might be other options.
***

Another example I never got to work is here
In BlogRSSFeed.C constructor, I need to change the messageResourceBundle, ever 
attempt I make crashes with segment fault:
  const Wt::WEnvironment& env = Wt::WApplication::instance()->environment(); // 
segment fault WEnvironment& WApplication::env()
  Wt::WApplication *app = new Wt::WApplication(env);
or
  Wt::WApplication* app = Wt::WApplication::instance(); // segment fault

  Wt::WApplication::UpdateLock lock(app);  // Wt::WApplication::instance() ~ 
segment fault in UpdateLock: impl_ = new UpdateLockImpl(app);
  if (lock) {
        app->messageResourceBundle().use(myDomainPath[domainName] + 
"app_root/ww-home", false);
  }

I actually thought that maybe I could something like this:
server.addResource(&rssFeed, "/" + rootPrefix + "en/blog/feed/");
server.addResource(&rssFeed, "/" + rootPrefix + "cn/blog/feed/");
server.addResource(&rssFeed, "/" + rootPrefix + "ru/blog/feed/");
then just change the links in the app, or use a cookie to read what language it 
is, not sure what is best, 
cookies are not so good, but I need a way to know what language they want, 
which is not necessarily the default browsers language.

I am sure that there is a way to do this, Boris gave me a good description of 
how to go about doing this, 
but he is making me feel stupid, because ever way I try it, it still crashes.

I am stuck, and I really need to find a way to do this, I need an example that 
does not produce a segment fault in these functions,
everyone says its easy, no problem just do this, well all I get is crashes, I 
am sure once I see the right way of doing it,
it will then click in, but until then, I am stuck.

Thanks
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to