Poco::RemotingNG::REST

class Listener

File Information

Library: RemotingNG/REST
Package: REST
Header: Poco/RemotingNG/REST/Listener.h

Description

The RemotingNG Listener implementation for the REST transport.

For more information, please see the Transport class.

Inheritance

Direct Base Classes: Poco::RemotingNG::Listener

All Base Classes: Poco::RefCountedObject, Poco::RemotingNG::Listener

Member Summary

Member Functions: areServiceExceptionsLogged, createURI, enableCORS, enableChunkedTransferEncoding, enableCompression, getCORSAllowedHeaders, getCORSAllowedOrigin, handlesURI, isCORSEnabled, isChunkedTransferEncodingEnabled, isCompressionEnabled, logServiceExceptions, protocol, registerObject, setCORSAllowedHeaders, setCORSAllowedOrigin, start, stop, unregisterObject

Inherited Functions: createURI, duplicate, endPoint, getAuthenticator, getAuthorizer, handlesURI, protocol, referenceCount, registerObject, release, setAuthenticator, setAuthorizer, start, stop, unregisterObject

Types Aliases

Ptr

using Ptr = Poco::AutoPtr < Listener >;

Enumerations

Protocol

PROTO_HTTP

PROTO_HTTPS

Constructors

Listener

Listener(
    const std::string & endPoint,
    Protocol proto
);

Creates a Listener for the given endpoint, which must be in <host>:<port> format.

The value specified for proto determines the URI scheme used by createURI().

Note that the Listener instance created by this constructor does not actually accept requests itself. It merely registers an endpoint in the ORB. A Poco::Net::HTTPServer must be created for accepting REST requests using a RESTRequestHandler.

Listener

Listener(
    const std::string & endPoint,
    Poco::Net::HTTPServerParams::Ptr pParams = new Poco::Net::HTTPServerParams
);

Creates a Listener for the given endpoint, which must be in <host>:<port> format.

This constructor will create a Poco::Net::HTTPServer instance for handling incoming REST requests, using a Poco::Net::ServerSocket bound to endPoint.

Listener

Listener(
    const std::string & endPoint,
    const Poco::Net::ServerSocket & socket,
    Poco::Net::HTTPServerParams::Ptr pParams = new Poco::Net::HTTPServerParams
);

Creates a Listener for the given endpoint, which must be in <host>:<port> format.

This constructor will create a Poco::Net::HTTPServer instance using the given server socket for handling incoming REST requests. The given server socket can be a Poco::Net::ServerSocket or a Poco::Net::SecureServerSocket which must be bound to a socket address corresponding to the given endPoint.

Destructor

~Listener virtual

~Listener();

Destroys the Listener.

Member Functions

areServiceExceptionsLogged inline

bool areServiceExceptionsLogged() const;

Returns true iff exceptions thrown by service methods are logged, otherwise false.

createURI

std::string createURI(
    const Poco::RemotingNG::Identifiable::TypeId & typeId,
    const Poco::RemotingNG::Identifiable::ObjectId & objectId
);

enableCORS

void enableCORS(
    bool enable = true
);

Enables or disables CORS (Cross Origin Resource Sharing). Default is disabled.

enableChunkedTransferEncoding

void enableChunkedTransferEncoding(
    bool enable = true
);

Enables or disables chunked transfer encoding for responses. Default is enabled.

enableCompression

void enableCompression(
    bool enable = true
);

Enables or disables GZIP compression for responses. Default is enabled.

Note that chunked transfer encoding must also be enabled in order to allow compression.

getCORSAllowedHeaders inline

const std::string & getCORSAllowedHeaders() const;

Returns the CORS allowed headers.

See setCORSAllowedHeaders() for more information.

getCORSAllowedOrigin inline

const std::string & getCORSAllowedOrigin() const;

Retuns the CORS allowed origin.

See setCORSAllowedOrigin() for more information.

handlesURI virtual

bool handlesURI(
    const std::string & uri
);

isCORSEnabled inline

bool isCORSEnabled() const;

Returns true iff CORS is enabled.

isChunkedTransferEncodingEnabled inline

bool isChunkedTransferEncodingEnabled() const;

Returns true iff chunked transfer encoding is enabled for responses.

isCompressionEnabled inline

bool isCompressionEnabled() const;

Returns true iff GZIP compression is enabled for responses.

logServiceExceptions

void logServiceExceptions(
    bool enable = true
);

Enable or disable logging of exceptions thrown by service methods.

If enabled, exceptions thrown by service methods are logged with the "RemotingNG.REST.RESTRequestHandler" logger.

protocol virtual

const std::string & protocol() const;

registerObject

void registerObject(
    Poco::RemotingNG::RemoteObject::Ptr pRemoteObject,
    Poco::RemotingNG::Skeleton::Ptr pSkeleton
);

setCORSAllowedHeaders

void setCORSAllowedHeaders(
    const std::string & headers
);

Sets the CORS allowed headers.

Must be a list of comma-separated header names. The default is "Accept, Content-Type".

Note that "Content-Type" should always be included in the list. Any custom headers used for passing parameters in REST methods must be included in this list.

setCORSAllowedOrigin

void setCORSAllowedOrigin(
    const std::string & origin
);

Sets the CORS allowed origin.

Can be empty (default), an asterisk ("*"), or a specific origin in the form of a complete http(s) URL ("http://domain.com").

In case of an empty origin specified here, all origins will be accepted and the origin specified by the client will simply be echoed back. If an asterisk is specified, again, all origins will be accepted, but the asterisk will be sent back to the client in the "Access-Control-Allow-Origin" header. If any other origin is given, the origin presented by the client must exactly match the specified origin for the request to be accepted.

start virtual

void start();

stop virtual

void stop();

unregisterObject

void unregisterObject(
    Poco::RemotingNG::RemoteObject::Ptr pRemoteObject
);

Variables

CORS_ALLOWED_HEADERS static

static const std::string CORS_ALLOWED_HEADERS;

Securely control IoT edge devices from anywhere   Connect a Device