Package org.restheart.exchange
Class MongoRequest
- java.lang.Object
-
- org.restheart.exchange.Exchange<T>
-
- org.restheart.exchange.Request<T>
-
- org.restheart.exchange.ServiceRequest<org.bson.BsonValue>
-
- org.restheart.exchange.BsonRequest
-
- org.restheart.exchange.MongoRequest
-
public class MongoRequest extends BsonRequest
Request implementation used by MongoService and backed by BsonValue that provides simplified methods to deal with headers and query parameters specific to mongo requests- Author:
- Andrea Di Cesare
-
-
Field Summary
-
Fields inherited from class org.restheart.exchange.ServiceRequest
content
-
Fields inherited from class org.restheart.exchange.Request
FORM_URLENCODED, MULTIPART, PATCH, SLASH, UNDERSCORE
-
Fields inherited from class org.restheart.exchange.Exchange
APP_FORM_URLENCODED_TYPE, APPLICATION_PDF_TYPE, HAL_JSON_MEDIA_TYPE, IN_ERROR_KEY, JSON_MEDIA_TYPE, LOGGER, MAX_BUFFERS, MAX_CONTENT_SIZE, MULTIPART_FORM_DATA_TYPE, wrapped
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMongoRequest(io.undertow.server.HttpServerExchange exchange, String requestUri, String resourceUri)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bson.BsonDocumentgetAggreationVars()StringgetAggregationOperation()io.undertow.security.idm.AccountgetAuthenticatedAccount()StringgetChangeStreamIdentifier()StringgetChangeStreamOperation()ClientSessionImplgetClientSession()StringgetCollectionName()org.bson.BsonDocumentgetCollectionProps()ExchangeKeys.EAGER_CURSOR_ALLOCATION_POLICYgetCursorAllocationPolicy()StringgetDBName()org.bson.BsonDocumentgetDbProps()ExchangeKeys.DOC_ID_TYPEgetDocIdType()org.bson.BsonValuegetDocumentId()StringgetDocumentIdRaw()StringgetETag()PathgetFilePath()Deque<String>getFilter()org.bson.BsonDocumentgetFiltersDocument()ExchangeKeys.HAL_MODEgetHalMode()Deque<String>getHint()org.bson.BsonDocumentgetHintDocument()StringgetIndexId()org.bson.json.JsonModegetJsonMode()Deque<String>getKeys()StringgetMappedRequestUri()The mapped uri is the exchange request uri.StringgetMappingUri()intgetPage()intgetPagesize()Map<String,String>getPathTemplateParamenters()if mongo-mounts specifies a path template (i.e.org.bson.BsonDocumentgetProjectionDocument()ExchangeKeys.REPRESENTATION_FORMATgetRepresentationFormat()longgetRequestStartTime()org.bson.BsonDocumentgetShardKey()StringgetSid()Deque<String>getSortBy()org.bson.BsonDocumentgetSortByDocument()longgetTxnId()ExchangeKeys.TYPEgetType()StringgetUnmappedRequestUri()The unmapped uri is the cononical uri of a mongodb resource (e.g.URIgetUri()StringgetUriPrefix()static MongoRequestinit(io.undertow.server.HttpServerExchange exchange, String requestUri, String resourceUri)booleanisAggregation()helper method to check request resource typebooleanisBulkDocuments()helper method to check request resource typebooleanisCollection()helper method to check request resource typebooleanisCollectionIndexes()helper method to check request resource typebooleanisCollectionMeta()helper method to check request resource typebooleanisCollectionNameInvalid()booleanisCollectionNameInvalid(String collectionName)booleanisCollectionSize()helper method to check request resource typebooleanisCount()booleanisDb()helper method to check request resource typebooleanisDbMeta()helper method to check request resource typebooleanisDbNameInvalid()booleanisDbNameInvalid(String dbName)booleanisDbNameInvalidOnWindows()booleanisDbNameInvalidOnWindows(String dbName)booleanisDbSize()helper method to check request resource typebooleanisDocument()helper method to check request resource typebooleanisETagCheckRequired()booleanisFile()helper method to check request resource typebooleanisFileBinary()helper method to check request resource typebooleanisFilesBucket()helper method to check request resource typebooleanisFilesBucketMeta()helper method to check request resource typebooleanisFilesBucketSize()helper method to check request resource typebooleanisForceEtagCheck()booleanisFullHalMode()booleanisIndex()helper method to check request resource typebooleanisMetrics()helper method to check request resource typebooleanisNoProps()booleanisParentAccessible()check if the parent of the requested resource is accessible in this request context for instance if /db/mycollection is mapped to /coll then: the db is accessible from the collection the root is not accessible from the collection (since / is actually mapped to the db)static booleanisReservedCollectionName(String collectionName)static booleanisReservedDbName(String dbName)static booleanisReservedDocumentId(ExchangeKeys.TYPE type, org.bson.BsonValue documentId)booleanisReservedResource()booleanisRoot()helper method to check request resource typebooleanisRootSize()helper method to check request resource typebooleanisSchema()helper method to check request resource typebooleanisSchemaStore()helper method to check request resource typebooleanisSchemaStoreMeta()helper method to check request resource typebooleanisSchemaStoreSize()helper method to check request resource typebooleanisSessions()helper method to check request resource typebooleanisTxn()helper method to check request resource typebooleanisTxns()helper method to check request resource typebooleanisWriteDocument()helper method to check if a request writes a document or a file or a schemaStringmapUri(String unmappedUri)given a canonical uri (/db/coll) returns the mapped uri (/some/mapping/uri) relative to this context.static MongoRequestof(io.undertow.server.HttpServerExchange exchange)voidsetAggregationVars(org.bson.BsonDocument aggregationVars)voidsetAuthenticatedAccount(io.undertow.security.idm.Account authenticatedAccount)voidsetClientSession(ClientSessionImpl clientSession)voidsetCollectionProps(org.bson.BsonDocument collectionProps)voidsetCount(boolean count)voidsetCursorAllocationPolicy(ExchangeKeys.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy)voidsetDbProps(org.bson.BsonDocument dbProps)voidsetDocIdType(ExchangeKeys.DOC_ID_TYPE docIdType)voidsetDocumentId(org.bson.BsonValue documentId)voidsetETagCheckRequired(boolean etagCheckRequired)voidsetFilePath(Path filePath)voidsetFilter(Deque<String> filter)voidsetHalMode(ExchangeKeys.HAL_MODE halMode)voidsetHint(Deque<String> hint)voidsetKeys(Deque<String> keys)voidsetNoProps(boolean noProps)voidsetPage(int page)voidsetPagesize(int pagesize)voidsetRepresentationFormat(ExchangeKeys.REPRESENTATION_FORMAT representationFormat)sets representationFormatvoidsetShardKey(org.bson.BsonDocument shardKey)voidsetSortBy(Deque<String> sortBy)static Typetype()-
Methods inherited from class org.restheart.exchange.BsonRequest
init, injectContent
-
Methods inherited from class org.restheart.exchange.ServiceRequest
getContent, isHandledBy, of, setContent
-
Methods inherited from class org.restheart.exchange.Request
addXForwardedHeader, getContentType, getContentType, getMethod, getPath, getPipelineInfo, getStartTime, getXForwardedHeaders, isContentTypeFormOrMultipart, isContentTypeFormOrMultipart, isContentTypeJson, isDelete, isGet, isOptions, isPatch, isPost, isPut, setContentLength, setContentType, setContentTypeAsJson, setPipelineInfo, setStartTime
-
Methods inherited from class org.restheart.exchange.Exchange
getExchange, getWrappedExchange, isAccountInRole, isAuthenticated, isAuthenticated, isContentTypeJson, isContentTypeText, isContentTypeXml, isInError, isInError, responseInterceptorsExecuted, setInError, setInError, setResponseInterceptorsExecuted, updateBufferSize
-
-
-
-
Method Detail
-
init
public static MongoRequest init(io.undertow.server.HttpServerExchange exchange, String requestUri, String resourceUri)
- Parameters:
exchange- the exchange request path (mapped uri) is rewritten replacing the resourceUri with the requestUri the special resourceUri value * means any resource: the requestUri is mapped to the root resource / example 1 resourceUri = /db/mycollection requestUri = / then the requestPath / is rewritten to /db/mycollection example 2 resourceUri = * requestUri = /data then the requestPath /data is rewritten to /requestUri- the request URI to map to the resource URIresourceUri- the resource URI identifying a resource in the DB- Returns:
- the MongoRequest
-
of
public static MongoRequest of(io.undertow.server.HttpServerExchange exchange)
-
type
public static Type type()
-
isReservedDbName
public static boolean isReservedDbName(String dbName)
- Parameters:
dbName-- Returns:
- true if the dbName is a reserved resource
-
isReservedCollectionName
public static boolean isReservedCollectionName(String collectionName)
- Parameters:
collectionName-- Returns:
- true if the collectionName is a reserved resource
-
isReservedDocumentId
public static boolean isReservedDocumentId(ExchangeKeys.TYPE type, org.bson.BsonValue documentId)
- Parameters:
type-documentId-- Returns:
- true if the documentIdRaw is a reserved resource
-
getType
public ExchangeKeys.TYPE getType()
- Returns:
- type
-
mapUri
public String mapUri(String unmappedUri)
given a canonical uri (/db/coll) returns the mapped uri (/some/mapping/uri) relative to this context. URLs are mapped to mongodb resources via the mongo-mounts configuration properties- Parameters:
unmappedUri-- Returns:
-
isParentAccessible
public boolean isParentAccessible()
check if the parent of the requested resource is accessible in this request context for instance if /db/mycollection is mapped to /coll then: the db is accessible from the collection the root is not accessible from the collection (since / is actually mapped to the db)- Returns:
- true if parent of the requested resource is accessible
-
getDBName
public String getDBName()
- Returns:
- DB Name
-
getCollectionName
public String getCollectionName()
- Returns:
- collection name
-
getDocumentIdRaw
public String getDocumentIdRaw()
- Returns:
- document id
-
getIndexId
public String getIndexId()
- Returns:
- index id
-
getSid
public String getSid()
- Returns:
- the txn id or null if request type is not SESSIONS, TRANSACTIONS or TRANSACTION
-
getTxnId
public long getTxnId()
- Returns:
- the txn id or null if request type is not TRANSACTION
-
getAggregationOperation
public String getAggregationOperation()
- Returns:
- collection name
-
getChangeStreamOperation
public String getChangeStreamOperation()
- Returns:
- change stream operation name
-
getChangeStreamIdentifier
public String getChangeStreamIdentifier()
- Returns:
-
getUri
public URI getUri() throws URISyntaxException
- Returns:
- URI
- Throws:
URISyntaxException
-
isReservedResource
public boolean isReservedResource()
- Returns:
- isReservedResource
-
getUriPrefix
public String getUriPrefix()
- Returns:
- the whereUri
-
getMappingUri
public String getMappingUri()
- Returns:
- the whatUri
-
getPage
public int getPage()
- Returns:
- the page
-
setPage
public void setPage(int page)
- Parameters:
page- the page to set
-
getPagesize
public int getPagesize()
- Returns:
- the pagesize
-
setPagesize
public void setPagesize(int pagesize)
- Parameters:
pagesize- the pagesize to set
-
getRepresentationFormat
public ExchangeKeys.REPRESENTATION_FORMAT getRepresentationFormat()
- Returns:
- the representationFormat
-
setRepresentationFormat
public void setRepresentationFormat(ExchangeKeys.REPRESENTATION_FORMAT representationFormat)
sets representationFormat- Parameters:
representationFormat-
-
isCount
public boolean isCount()
- Returns:
- the count
-
setCount
public void setCount(boolean count)
- Parameters:
count- the count to set
-
getFiltersDocument
public org.bson.BsonDocument getFiltersDocument() throws org.bson.json.JsonParseException- Returns:
- the $and composed filter qparam values
- Throws:
org.bson.json.JsonParseException
-
getSortByDocument
public org.bson.BsonDocument getSortByDocument() throws org.bson.json.JsonParseException- Returns:
- Throws:
org.bson.json.JsonParseException
-
getHintDocument
public org.bson.BsonDocument getHintDocument() throws org.bson.json.JsonParseException- Returns:
- Throws:
org.bson.json.JsonParseException
-
getProjectionDocument
public org.bson.BsonDocument getProjectionDocument() throws org.bson.json.JsonParseException- Returns:
- Throws:
org.bson.json.JsonParseException
-
getAggreationVars
public org.bson.BsonDocument getAggreationVars()
- Returns:
- the aggregationVars
-
setAggregationVars
public void setAggregationVars(org.bson.BsonDocument aggregationVars)
- Parameters:
aggregationVars- the aggregationVars to set
-
getCollectionProps
public org.bson.BsonDocument getCollectionProps()
- Returns:
- the collectionProps
-
setCollectionProps
public void setCollectionProps(org.bson.BsonDocument collectionProps)
- Parameters:
collectionProps- the collectionProps to set
-
getDbProps
public org.bson.BsonDocument getDbProps()
- Returns:
- the dbProps
-
setDbProps
public void setDbProps(org.bson.BsonDocument dbProps)
- Parameters:
dbProps- the dbProps to set
-
getUnmappedRequestUri
public String getUnmappedRequestUri()
The unmapped uri is the cononical uri of a mongodb resource (e.g. /db/coll).- Returns:
- the unmappedUri
-
getMappedRequestUri
public String getMappedRequestUri()
The mapped uri is the exchange request uri. This is "mapped" by the mongo-mounts mapping paramenters.- Returns:
- the mappedUri
-
getPathTemplateParamenters
public Map<String,String> getPathTemplateParamenters()
if mongo-mounts specifies a path template (i.e. /{foo}/*) this returns the request template parameters (/x/y => foo=x, *=y)- Returns:
-
getCursorAllocationPolicy
public ExchangeKeys.EAGER_CURSOR_ALLOCATION_POLICY getCursorAllocationPolicy()
- Returns:
- the cursorAllocationPolicy
-
setCursorAllocationPolicy
public void setCursorAllocationPolicy(ExchangeKeys.EAGER_CURSOR_ALLOCATION_POLICY cursorAllocationPolicy)
- Parameters:
cursorAllocationPolicy- the cursorAllocationPolicy to set
-
getDocIdType
public ExchangeKeys.DOC_ID_TYPE getDocIdType()
- Returns:
- the docIdType
-
setDocIdType
public void setDocIdType(ExchangeKeys.DOC_ID_TYPE docIdType)
- Parameters:
docIdType- the docIdType to set
-
setDocumentId
public void setDocumentId(org.bson.BsonValue documentId)
- Parameters:
documentId- the documentId to set
-
getDocumentId
public org.bson.BsonValue getDocumentId()
- Returns:
- the documentId
-
getClientSession
public ClientSessionImpl getClientSession()
- Returns:
- the clientSession
-
setClientSession
public void setClientSession(ClientSessionImpl clientSession)
- Parameters:
clientSession- the clientSession to set
-
getJsonMode
public org.bson.json.JsonMode getJsonMode()
- Returns:
- the jsonMode as specified by jsonMode query paramter
-
getFilePath
public Path getFilePath()
- Returns:
- the filePath
-
setFilePath
public void setFilePath(Path filePath)
- Parameters:
filePath- the filePath to set
-
getHalMode
public ExchangeKeys.HAL_MODE getHalMode()
- Returns:
- the halMode
-
isFullHalMode
public boolean isFullHalMode()
- Returns:
-
setHalMode
public void setHalMode(ExchangeKeys.HAL_MODE halMode)
- Parameters:
halMode- the halMode to set
-
isDbNameInvalid
public boolean isDbNameInvalid()
- Returns:
-
getRequestStartTime
public long getRequestStartTime()
- Returns:
-
isDbNameInvalid
public boolean isDbNameInvalid(String dbName)
- Parameters:
dbName-- Returns:
-
isDbNameInvalidOnWindows
public boolean isDbNameInvalidOnWindows()
- Returns:
-
isDbNameInvalidOnWindows
public boolean isDbNameInvalidOnWindows(String dbName)
- Parameters:
dbName-- Returns:
-
isCollectionNameInvalid
public boolean isCollectionNameInvalid()
- Returns:
-
isCollectionNameInvalid
public boolean isCollectionNameInvalid(String collectionName)
- Parameters:
collectionName-- Returns:
-
getETag
public String getETag()
- Returns:
-
getShardKey
public org.bson.BsonDocument getShardKey()
- Returns:
- the shardKey
-
setShardKey
public void setShardKey(org.bson.BsonDocument shardKey)
- Parameters:
shardKey- the shardKey to set
-
isNoProps
public boolean isNoProps()
- Returns:
- the noProps
-
setNoProps
public void setNoProps(boolean noProps)
- Parameters:
noProps- the noProps to set
-
getAuthenticatedAccount
public io.undertow.security.idm.Account getAuthenticatedAccount()
- Overrides:
getAuthenticatedAccountin classRequest<org.bson.BsonValue>- Returns:
- the authenticatedAccount
-
setAuthenticatedAccount
public void setAuthenticatedAccount(io.undertow.security.idm.Account authenticatedAccount)
- Parameters:
authenticatedAccount- the authenticatedAccount to set
-
isAggregation
public boolean isAggregation()
helper method to check request resource type- Returns:
- true if type is TYPE.AGGREGATION
-
isBulkDocuments
public boolean isBulkDocuments()
helper method to check request resource type- Returns:
- true if type is TYPE.BULK_DOCUMENTS
-
isCollection
public boolean isCollection()
helper method to check request resource type- Returns:
- true if type is TYPE.COLLECTION
-
isCollectionIndexes
public boolean isCollectionIndexes()
helper method to check request resource type- Returns:
- true if type is TYPE.COLLECTION_INDEXES
-
isDb
public boolean isDb()
helper method to check request resource type- Returns:
- true if type is TYPE.DB
-
isDocument
public boolean isDocument()
helper method to check request resource type- Returns:
- true if type is TYPE.DOCUMENT
-
isFile
public boolean isFile()
helper method to check request resource type- Returns:
- true if type is TYPE.FILE
-
isFilesBucket
public boolean isFilesBucket()
helper method to check request resource type- Returns:
- true if type is TYPE.FILES_BUCKET
-
isFileBinary
public boolean isFileBinary()
helper method to check request resource type- Returns:
- true if type is TYPE.FILE_BINARY
-
isIndex
public boolean isIndex()
helper method to check request resource type- Returns:
- true if type is TYPE.INDEX
-
isRoot
public boolean isRoot()
helper method to check request resource type- Returns:
- true if type is TYPE.ROOT
-
isSessions
public boolean isSessions()
helper method to check request resource type- Returns:
- true if type is TYPE.TRANSACTIONS
-
isTxns
public boolean isTxns()
helper method to check request resource type- Returns:
- true if type is TYPE.TRANSACTIONS
-
isTxn
public boolean isTxn()
helper method to check request resource type- Returns:
- true if type is TYPE.TRANSACTION
-
isSchema
public boolean isSchema()
helper method to check request resource type- Returns:
- true if type is TYPE.SCHEMA
-
isSchemaStore
public boolean isSchemaStore()
helper method to check request resource type- Returns:
- true if type is TYPE.SCHEMA_STORE
-
isRootSize
public boolean isRootSize()
helper method to check request resource type- Returns:
- true if type is TYPE.ROOT_SIZE
-
isDbSize
public boolean isDbSize()
helper method to check request resource type- Returns:
- true if type is TYPE.DB_SIZE
-
isDbMeta
public boolean isDbMeta()
helper method to check request resource type- Returns:
- true if type is TYPE.DB_META
-
isCollectionSize
public boolean isCollectionSize()
helper method to check request resource type- Returns:
- true if type is TYPE.COLLECTION_SIZE
-
isCollectionMeta
public boolean isCollectionMeta()
helper method to check request resource type- Returns:
- true if type is TYPE.COLLECTION_META
-
isFilesBucketSize
public boolean isFilesBucketSize()
helper method to check request resource type- Returns:
- true if type is TYPE.FILES_BUCKET_SIZE
-
isFilesBucketMeta
public boolean isFilesBucketMeta()
helper method to check request resource type- Returns:
- true if type is TYPE.FILES_BUCKET_META
-
isSchemaStoreSize
public boolean isSchemaStoreSize()
helper method to check request resource type- Returns:
- true if type is TYPE.SCHEMA_STORE_SIZE
-
isSchemaStoreMeta
public boolean isSchemaStoreMeta()
helper method to check request resource type- Returns:
- true if type is TYPE.SCHEMA_STORE_SIZE
-
isMetrics
public boolean isMetrics()
helper method to check request resource type- Returns:
- true if type is TYPE.METRICS
-
isWriteDocument
public boolean isWriteDocument()
helper method to check if a request writes a document or a file or a schema- Returns:
- true if the request writes a document or a file or a schema
-
isETagCheckRequired
public boolean isETagCheckRequired()
- Returns:
- the isETagCheckRequired
-
setETagCheckRequired
public void setETagCheckRequired(boolean etagCheckRequired)
- Parameters:
etagCheckRequired-
-
isForceEtagCheck
public boolean isForceEtagCheck()
- Returns:
- the forceEtagCheck
-
-