Library: OSP/Web
Package: Web
Header: Poco/OSP/Web/WebServerDispatcher.h
A WebServerDispatcher is some sort of meta HTTPRequestHandlerFactory. It groups together several other HTTPRequestHandlerFactory instances and distributes requests to them according to the registered request handler extension points (see the WebServerExtensionPoint class).
Direct Base Classes: Poco::OSP::Service
All Base Classes: Poco::OSP::Service, Poco::RefCountedObject
Member Functions: addVirtualPath, authService, authorize, cleanPath, findResource, formatMessage, handleRequest, htmlize, isA, listVirtualPaths, mapPath, normalizePath, onBundleStopping, removeBundle, removeVirtualPath, sendBadRequest, sendForbidden, sendFound, sendInternalError, sendNotAuthorized, sendNotFound, sendResponse, shouldCompressMediaType, type, virtualPathMappings
Inherited Functions: duplicate, isA, referenceCount, release, type
Security attributes for a registered path.
A VirtualPath struct is used to specify a path mapping for a bundle.
typedef std::map < std::string, PathInfo > PathInfoMap;
typedef std::map < std::string, VirtualPath > PathMap;
typedef Poco::SharedPtr < Poco::Net::HTTPRequestHandlerFactory > RequestHandlerFactoryPtr;
A bundle that registers a resource mapping or request handler for a certain path can specify whether other bundles can register subdirectories of this directory.
SM_NONE = 0
No one can register subdirectories
SM_OWNER = 1
Only the owner bundle can register subdirectories
SM_ALL = 2
Everyone can register subdirectories
WebServerDispatcher(
BundleContext::Ptr pContext,
MediaTypeMapper::Ptr pMediaTypeMapper,
const std::string & authServiceName,
bool compressResponses,
const std::set < std::string > & compressedMediaTypes
);
Creates the WebServerDispatcher.
virtual ~WebServerDispatcher();
Destroys the WebServerDispatcher.
void addVirtualPath(
const VirtualPath & virtualPath
);
Adds the given VirtualPath to the path mapping table.
Throws an ExistsException if a mapping for the given path already exists.
void handleRequest(
Poco::Net::HTTPServerRequest & request,
Poco::Net::HTTPServerResponse & response,
bool secure
);
Handles the given request. Secure specifies whether the request has been sent over a secure (HTTPS) connection.
virtual bool isA(
const std::type_info & otherType
) const;
See also: Poco::OSP::Service::isA()
void listVirtualPaths(
PathInfoMap & paths
) const;
Returns a map containing all virtual paths (key) not marked as hidden and their descriptions (value).
void removeBundle(
Bundle::ConstPtr pBundle
);
Removes all mappings from the given bundle.
void removeVirtualPath(
const std::string & virtualPath
);
Removes a path mapping from the path mapping table.
Throws a NotFoundException if the given path does not exist.
virtual const std::type_info & type() const;
See also: Poco::OSP::Service::type()
void virtualPathMappings(
PathMap & mappings
) const;
Returns all path mappings. This member function creates a full copy of the internal path map.
Poco::OSP::Auth::AuthService::Ptr authService() const;
Returns a pointer to the auth service, if it is available, or null otherwise.
bool authorize(
Poco::Net::HTTPServerRequest & request,
const VirtualPath & vPath
) const;
Authorizes the request.
static bool cleanPath(
std::string & path
);
Removes unnecessary characters (such as trailing dots) from the path and checks for illegal or dangerous characters.
Returns true if the path is okay, false otherwise.
std::istream * findResource(
Bundle::ConstPtr pBundle,
const std::string & base,
const std::string & res,
const std::string & index,
std::string & mediaType
) const;
Returns a resource stream for the given path, or a null pointer if no matching resource exists.
std::string formatMessage(
const std::string & messageId,
const std::string & arg1 = std::string (),
const std::string & arg2 = std::string ()
);
Reads a message from the bundle.properties resource and replaces placeholders $1 and $2 with arg1 and arg2, respectively.
static std::string htmlize(
const std::string & str
);
Returns a HTML-ized version of the given string.
const VirtualPath & mapPath(
const std::string & path
) const;
Maps a URI to a VirtualPath.
Throws a NotFoundException if no suitable mapping can be found.
static std::string normalizePath(
const std::string & path
);
Creates normalized path for internal storage. The normalized path always starts and ends with a slash.
void onBundleStopping(
const void * pSender,
BundleEvent & ev
);
When a bundle is stopped, all of its request handlers and mappings are automatically disabled.
void sendBadRequest(
Poco::Net::HTTPServerRequest & request,
const std::string & message
);
Sends a 404 Not Found error response.
void sendForbidden(
Poco::Net::HTTPServerRequest & request,
const std::string & path
);
Sends a 403 Forbidden error response.
void sendFound(
Poco::Net::HTTPServerRequest & request,
const std::string & path
);
Sends a 302 Found response.
void sendInternalError(
Poco::Net::HTTPServerRequest & request,
const std::string & message
);
Sends a 500 Internal Server Error response.
void sendNotAuthorized(
Poco::Net::HTTPServerRequest & request,
const std::string & path
);
Sends a 401 Unauthorized error response.
void sendNotFound(
Poco::Net::HTTPServerRequest & request,
const std::string & path
);
Sends a 404 Not Found error response.
void sendResponse(
Poco::Net::HTTPServerRequest & request,
Poco::Net::HTTPResponse::HTTPStatus status,
const std::string & message
);
Sends a standard status/error response.
bool shouldCompressMediaType(
const std::string & mediaType
) const;
Returns true if and only if content with the given media type should be compressed.
static const std::string SERVICE_NAME;