mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 15:05:35 +02:00
initial import
This commit is contained in:
11
Net/samples/HTTPTimeServer/HTTPTimeServer.properties
Normal file
11
Net/samples/HTTPTimeServer/HTTPTimeServer.properties
Normal file
@@ -0,0 +1,11 @@
|
||||
# This is a sample configuration file for HTTPTimeServer
|
||||
|
||||
logging.loggers.root.channel.class = ConsoleChannel
|
||||
logging.loggers.app.name = Application
|
||||
logging.loggers.app.channel = c1
|
||||
logging.formatters.f1.class = PatternFormatter
|
||||
logging.formatters.f1.pattern = [%p] %t
|
||||
logging.channels.c1.class = ConsoleChannel
|
||||
logging.channels.c1.formatter = f1
|
||||
# HTTPTimeServer.format = %W, %e %b %y %H:%M:%S %Z
|
||||
# HTTPTimeServer.port = 9980
|
8
Net/samples/HTTPTimeServer/HTTPTimeServer.vmsbuild
Normal file
8
Net/samples/HTTPTimeServer/HTTPTimeServer.vmsbuild
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# sample.vmsbuild
|
||||
#
|
||||
# $Id: //poco/1.1.0/Net/samples/HTTPTimeServer/HTTPTimeServer.vmsbuild#1 $
|
||||
#
|
||||
EXE=HTTPTimeServer
|
||||
HTTPTimeServer
|
||||
<SourceFilesHere>
|
152
Net/samples/HTTPTimeServer/HTTPTimeServer_vs71.vcproj
Normal file
152
Net/samples/HTTPTimeServer/HTTPTimeServer_vs71.vcproj
Normal file
@@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="HTTPTimeServer"
|
||||
ProjectGUID="{7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
|
||||
OutputFile="bin/HTTPTimeServerd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/HTTPTimeServerd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
|
||||
OutputFile="bin/HTTPTimeServer.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Configuration Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\HTTPTimeServer.properties">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\HTTPTimeServer.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
217
Net/samples/HTTPTimeServer/HTTPTimeServer_vs80.vcproj
Normal file
217
Net/samples/HTTPTimeServer/HTTPTimeServer_vs80.vcproj
Normal file
@@ -0,0 +1,217 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="HTTPTimeServer"
|
||||
ProjectGUID="{7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
|
||||
OutputFile="bin/HTTPTimeServerd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/HTTPTimeServerd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
|
||||
OutputFile="bin/HTTPTimeServer.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Configuration Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\HTTPTimeServer.properties"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\HTTPTimeServer.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
17
Net/samples/HTTPTimeServer/Makefile
Normal file
17
Net/samples/HTTPTimeServer/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/1.1.0/Net/samples/HTTPTimeServer/Makefile#1 $
|
||||
#
|
||||
# Makefile for Poco HTTPTimeServer
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = HTTPTimeServer
|
||||
|
||||
target = HTTPTimeServer
|
||||
target_version = 1
|
||||
target_libs = PocoFoundation PocoXML PocoNet PocoUtil
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
227
Net/samples/HTTPTimeServer/src/HTTPTimeServer.cpp
Normal file
227
Net/samples/HTTPTimeServer/src/HTTPTimeServer.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
//
|
||||
// TimeServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/samples/HTTPTimeServer/src/HTTPTimeServer.cpp#2 $
|
||||
//
|
||||
// This sample demonstrates the HTTPServer and related classes.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Net/HTTPServer.h"
|
||||
#include "Net/HTTPRequestHandler.h"
|
||||
#include "Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Net/HTTPServerParams.h"
|
||||
#include "Net/HTTPServerRequest.h"
|
||||
#include "Net/HTTPServerResponse.h"
|
||||
#include "Net/HTTPServerParams.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Foundation/Timestamp.h"
|
||||
#include "Foundation/DateTimeFormatter.h"
|
||||
#include "Foundation/DateTimeFormat.h"
|
||||
#include "Foundation/Exception.h"
|
||||
#include "Util/ServerApplication.h"
|
||||
#include "Util/Option.h"
|
||||
#include "Util/OptionSet.h"
|
||||
#include "Util/HelpFormatter.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::ServerSocket;
|
||||
using Net::HTTPRequestHandler;
|
||||
using Net::HTTPRequestHandlerFactory;
|
||||
using Net::HTTPServer;
|
||||
using Net::HTTPServerRequest;
|
||||
using Net::HTTPServerResponse;
|
||||
using Net::HTTPServerParams;
|
||||
using Foundation::Timestamp;
|
||||
using Foundation::DateTimeFormatter;
|
||||
using Foundation::DateTimeFormat;
|
||||
using Util::ServerApplication;
|
||||
using Util::Application;
|
||||
using Util::Option;
|
||||
using Util::OptionSet;
|
||||
using Util::HelpFormatter;
|
||||
|
||||
|
||||
class TimeRequestHandler: public HTTPRequestHandler
|
||||
/// Return a HTML document with the current date and time.
|
||||
{
|
||||
public:
|
||||
TimeRequestHandler(const std::string& format):
|
||||
_format(format)
|
||||
{
|
||||
}
|
||||
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
Application& app = Application::instance();
|
||||
app.logger().information("Request from " + request.clientAddress().toString());
|
||||
|
||||
Timestamp now;
|
||||
std::string dt(DateTimeFormatter::format(now, _format));
|
||||
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType("text/html");
|
||||
|
||||
std::ostream& ostr = response.send();
|
||||
ostr << "<html><head><title>HTTPTimeServer powered by C++ Portable Components</title>";
|
||||
ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
|
||||
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
|
||||
ostr << dt;
|
||||
ostr << "</p></body></html>";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _format;
|
||||
};
|
||||
|
||||
|
||||
class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||
{
|
||||
public:
|
||||
TimeRequestHandlerFactory(const std::string& format):
|
||||
_format(format)
|
||||
{
|
||||
}
|
||||
|
||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||
{
|
||||
if (request.getURI() == "/")
|
||||
return new TimeRequestHandler(_format);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _format;
|
||||
};
|
||||
|
||||
|
||||
class HTTPTimeServer: public Util::ServerApplication
|
||||
/// The main application class.
|
||||
///
|
||||
/// This class handles command-line arguments and
|
||||
/// configuration files.
|
||||
/// Start the HTTPTimeServer executable with the help
|
||||
/// option (/help on Windows, --help on Unix) for
|
||||
/// the available command line options.
|
||||
///
|
||||
/// To use the sample configuration file (HTTPTimeServer.properties),
|
||||
/// copy the file to the directory where the HTTPTimeServer executable
|
||||
/// resides. If you start the debug version of the HTTPTimeServer
|
||||
/// (HTTPTimeServerd[.exe]), you must also create a copy of the configuration
|
||||
/// file named HTTPTimeServerd.properties. In the configuration file, you
|
||||
/// can specify the port on which the server is listening (default
|
||||
/// 9980) and the format of the date/time string sent back to the client.
|
||||
///
|
||||
/// To test the TimeServer you can use any web browser (http://localhost:9980/).
|
||||
{
|
||||
public:
|
||||
HTTPTimeServer(): _helpRequested(false)
|
||||
{
|
||||
}
|
||||
|
||||
~HTTPTimeServer()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void initialize(Application& self)
|
||||
{
|
||||
loadConfiguration(); // load default configuration files, if present
|
||||
ServerApplication::initialize(self);
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
ServerApplication::uninitialize();
|
||||
}
|
||||
|
||||
void defineOptions(OptionSet& options)
|
||||
{
|
||||
ServerApplication::defineOptions(options);
|
||||
|
||||
options.addOption(
|
||||
Option("help", "h", "display help information on command line arguments")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
}
|
||||
|
||||
void handleOption(const std::string& name, const std::string& value)
|
||||
{
|
||||
ServerApplication::handleOption(name, value);
|
||||
|
||||
if (name == "help")
|
||||
_helpRequested = true;
|
||||
}
|
||||
|
||||
void displayHelp()
|
||||
{
|
||||
HelpFormatter helpFormatter(options());
|
||||
helpFormatter.setCommand(commandName());
|
||||
helpFormatter.setUsage("OPTIONS");
|
||||
helpFormatter.setHeader("A web server that serves the current date and time.");
|
||||
helpFormatter.format(std::cout);
|
||||
}
|
||||
|
||||
int main(const std::vector<std::string>& args)
|
||||
{
|
||||
if (_helpRequested)
|
||||
{
|
||||
displayHelp();
|
||||
}
|
||||
else
|
||||
{
|
||||
// get parameters from configuration file
|
||||
unsigned short port = (unsigned short) config().getInt("HTTPTimeServer.port", 9980);
|
||||
std::string format(config().getString("HTTPTimeServer.format", DateTimeFormat::SORTABLE_FORMAT));
|
||||
|
||||
// set-up a server socket
|
||||
ServerSocket svs(port);
|
||||
// set-up a HTTPServer instance
|
||||
HTTPServer srv(new TimeRequestHandlerFactory(format), svs, new HTTPServerParams);
|
||||
// start the HTTPServer
|
||||
srv.start();
|
||||
// wait for CTRL-C or kill
|
||||
waitForTerminationRequest();
|
||||
// Stop the HTTPServer
|
||||
srv.stop();
|
||||
}
|
||||
return Application::EXIT_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _helpRequested;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
HTTPTimeServer app;
|
||||
return app.run(argc, argv);
|
||||
}
|
Reference in New Issue
Block a user