Package org.restheart.exchange
Class MongoRequest
java.lang.Object
org.restheart.exchange.Exchange<org.bson.BsonValue>
org.restheart.exchange.Request<org.bson.BsonValue>
org.restheart.exchange.ServiceRequest<org.bson.BsonValue>
org.restheart.exchange.BsonRequest
org.restheart.exchange.MongoRequest
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 <andrea@softinstigate.com>
-
Field Summary
Fields inherited from class org.restheart.exchange.ServiceRequest
content, CONTENT_INJECTEDFields inherited from class org.restheart.exchange.Request
PATCH, PIPELINE_INFO_KEY, SLASH, UNDERSCOREFields inherited from class org.restheart.exchange.Exchange
APPLICATION_PDF_TYPE, FORM_URLENCODED, HAL_JSON_MEDIA_TYPE, IN_ERROR_KEY, JSON_MEDIA_TYPE, MAX_BUFFERS, MAX_CONTENT_SIZE, MULTIPART, TEXT_PLAIN_CONTENT_TYPE, wrapped -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMongoRequest(io.undertow.server.HttpServerExchange exchange, String requestUri, String resourceUri) -
Method Summary
Modifier and TypeMethodDescriptionorg.bson.BsonDocumentorg.bson.BsonDocumentorg.bson.BsonDocumentorg.bson.BsonValuegetETag()org.bson.BsonDocumentgetHint()org.bson.BsonDocumentorg.bson.json.JsonModegetKeys()The mapped uri is the exchange request uri.intgetPage()intif mongo-mounts specifies a path template (i.e.org.bson.BsonDocumentlongorg.bson.BsonDocumentgetSid()org.bson.BsonDocumentgetTxnId()getType()The unmapped uri is the cononical uri of a mongodb resource (e.g.getUri()static MongoRequestbooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanisCache()booleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanSeehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictionsbooleanisCollectionNameInvalid(String collectionName) booleanhelper method to check request resource typebooleanisCount()booleanisDb()helper method to check request resource typebooleanisDbMeta()helper method to check request resource typebooleanSeehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictionsbooleanisDbNameInvalid(String dbName) booleanSeehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictionsbooleanisDbNameInvalidOnWindows(String dbName) booleanisDbSize()helper method to check request resource typebooleanhelper method to check request resource typebooleanbooleanisFile()helper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanbooleanbooleanisIndex()helper method to check request resource typebooleanbooleanbooleancheck 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) booleanbooleanisRoot()helper method to check request resource typebooleanhelper method to check request resource typebooleanisSchema()helper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanhelper method to check request resource typebooleanisTxn()helper method to check request resource typebooleanisTxns()helper method to check request resource typebooleanhelper method to check if a request writes a document or a file or a schemagiven a canonical uri (/db/coll) returns the mapped uri (/some/mapping/uri) relative to this context.static MongoRequestof(io.undertow.server.HttpServerExchange exchange) org.bson.BsonValueParses the content from the exchange and converts it into an instance of the specified typeT.rsOps()ReplicaSet connection otpionsvoidsetAggregationVars(org.bson.BsonDocument aggregationVars) voidsetCache(boolean cache) voidsetClientSession(ClientSessionImpl clientSession) voidsetCollectionProps(org.bson.BsonDocument collectionProps) voidsetCount(boolean count) voidsetDbProps(org.bson.BsonDocument dbProps) voidsetDocIdType(ExchangeKeys.DOC_ID_TYPE docIdType) voidsetDocumentId(org.bson.BsonValue documentId) voidsetETagCheckRequired(boolean etagCheckRequired) voidsetFileInputStream(InputStream fileInputStream) voidvoidsetHalMode(ExchangeKeys.HAL_MODE halMode) voidvoidvoidsetNoProps(boolean noProps) voidsetPage(int page) voidsetPagesize(int pagesize) voidsetRepresentationFormat(ExchangeKeys.REPRESENTATION_FORMAT representationFormat) sets representationFormatvoidsetShardKey(org.bson.BsonDocument shardKey) voidvoidsetWriteMode(ExchangeKeys.WRITE_MODE writeMode) Methods inherited from class org.restheart.exchange.BsonRequest
initMethods inherited from class org.restheart.exchange.ServiceRequest
getContent, isContentInjected, isHandledBy, of, setContent, setContentInjectedMethods inherited from class org.restheart.exchange.Request
addXForwardedHeader, blockForTooManyRequests, getAuthenticatedAccount, getContentType, getContentType, getCookie, getHeader, getHeaders, getMethod, getPath, getPathParam, getPathParams, getPipelineInfo, getPipelineInfo, getQueryParameterOfDefault, getQueryParameterOrDefault, getQueryParameters, getQueryString, getRequestContentLength, getStartTime, getURL, getXForwardedHeaders, isAuthenticated, isBlockForTooManyRequests, isDelete, isGet, isOptions, isPatch, isPost, isPut, pipelineInfo, setContentLength, setContentType, setContentTypeAsJson, setHeader, setHeader, setPipelineInfo, setPipelineInfo, setStartTimeMethods inherited from class org.restheart.exchange.Exchange
getExchange, getWrappedExchange, isAccountInRole, isAuthenticated, isContentTypeFormOrMultipart, isContentTypeFormOrMultipart, isContentTypeJson, isContentTypeJson, isContentTypeText, isContentTypeXml, isInError, isInError, responseInterceptorsExecuted, setInError, setInError, setResponseInterceptorsExecuted, updateBufferSize
-
Constructor Details
-
MongoRequest
-
-
Method Details
-
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
-
isReservedDbName
- Parameters:
dbName-- Returns:
- true if the dbName is a reserved resource
-
isReservedCollectionName
- Parameters:
collectionName-- Returns:
- true if the collectionName is a reserved resource
-
isReservedDocumentId
- Parameters:
type-documentId-- Returns:
- true if the documentIdRaw is a reserved resource
-
getType
- Returns:
- type
-
mapUri
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
- Returns:
- DB Name
-
getCollectionName
- Returns:
- collection name
-
getDocumentIdRaw
- Returns:
- document id
-
getIndexId
- Returns:
- index id
-
getSid
- Returns:
- the txn id or null if request type is not SESSIONS, TRANSACTIONS or TRANSACTION
-
getTxnId
- Returns:
- the txn id or null if request type is not TRANSACTION
-
getAggregationOperation
- Returns:
- collection name
-
getChangeStreamOperation
- Returns:
- change stream operation name
-
getUri
- Returns:
- URI
- Throws:
URISyntaxException
-
isReservedResource
public boolean isReservedResource()- Returns:
- isReservedResource
-
getUriPrefix
- Returns:
- the whereUri
-
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
- Returns:
- the representationFormat
-
setRepresentationFormat
sets representationFormat- Parameters:
representationFormat-
-
isCount
public boolean isCount()- Returns:
- the count
-
setCount
public void setCount(boolean count) - Parameters:
count- the count to set
-
getFilter
- Returns:
- the filter
-
setFilter
- Parameters:
filter- the filter to set
-
getHint
- Returns:
- the hint
-
setHint
- Parameters:
hint- the hint 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 JsonParseException
- Throws:
org.bson.json.JsonParseException
-
getHintDocument
public org.bson.BsonDocument getHintDocument() throws org.bson.json.JsonParseException- Returns:
- @throws JsonParseException
- Throws:
org.bson.json.JsonParseException
-
getProjectionDocument
public org.bson.BsonDocument getProjectionDocument() throws org.bson.json.JsonParseException- Returns:
- @throws JsonParseException
- Throws:
org.bson.json.JsonParseException
-
getAggregationVars
public org.bson.BsonDocument getAggregationVars()- Returns:
- the aggregationVars
-
setAggregationVars
public void setAggregationVars(org.bson.BsonDocument aggregationVars) - Parameters:
aggregationVars- the aggregationVars to set
-
getSortBy
- Returns:
- the sortBy
-
setSortBy
- Parameters:
sortBy- the sortBy 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
The unmapped uri is the cononical uri of a mongodb resource (e.g. /db/coll).- Returns:
- the unmappedUri
-
getMappedRequestUri
The mapped uri is the exchange request uri. This is "mapped" by the mongo-mounts mapping paramenters.- Returns:
- the mappedUri
-
getPathTemplateParamenters
if mongo-mounts specifies a path template (i.e. /{foo}/*) this returns the request template parameters (/x/y => foo=x, *=y)- Returns:
-
isCache
public boolean isCache()- Returns:
- the cache
-
setCache
public void setCache(boolean cache) - Parameters:
cache- true to use caching
-
getDocIdType
- Returns:
- the docIdType
-
setDocIdType
- 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
- Returns:
- the clientSession
-
setClientSession
- Parameters:
clientSession- the clientSession to set
-
getJsonMode
public org.bson.json.JsonMode getJsonMode()- Returns:
- the jsonMode as specified by jsonMode query paramter
-
parseContent
Description copied from class:ServiceRequestParses the content from the exchange and converts it into an instance of the specified typeT. This method retrieves data from the exchange, interprets it according to the expected format, and attempts to convert this data into an object of typeT.- Overrides:
parseContentin classBsonRequest- Returns:
- an instance of
Trepresenting the parsed content - Throws:
BadRequestException- if the content does not match the expected format for typeTIOException- if an IO error occurs
-
getFileInputStream
- Returns:
- the fileInputStream in case of a file resouces the fileInputStream, null othewise
- Throws:
BadRequestExceptionIOException
-
setFileInputStream
- Parameters:
fileInputStream- the fileInputStream to set
-
getKeys
- Returns:
- keys
-
setKeys
- Parameters:
keys- keys to set
-
getHalMode
- Returns:
- the halMode
-
isFullHalMode
public boolean isFullHalMode()- Returns:
-
setHalMode
- Parameters:
halMode- the halMode to set
-
isDbNameInvalid
public boolean isDbNameInvalid()Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
getRequestStartTime
public long getRequestStartTime()- Returns:
-
isDbNameInvalid
- Parameters:
dbName- Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
isDbNameInvalidOnWindows
public boolean isDbNameInvalidOnWindows()Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
isDbNameInvalidOnWindows
- Parameters:
dbName- Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
isCollectionNameInvalid
public boolean isCollectionNameInvalid()Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
isCollectionNameInvalid
- Parameters:
collectionName- Seehttps://docs.mongodb.org/v3.2/reference/limits/#naming-restrictions- Returns:
-
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
-
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.SESSIONS
-
isSession
public boolean isSession()helper method to check request resource type- Returns:
- true if type is TYPE.SESSION
-
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
-
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-
-
getWriteMode
- Returns:
- the write mode
-
setWriteMode
- Parameters:
writeMode- the write mode to set
-
isForceEtagCheck
public boolean isForceEtagCheck()- Returns:
- the forceEtagCheck
-
isNoCache
public boolean isNoCache()- Returns:
- the noCache
-
rsOps
ReplicaSet connection otpions- Returns:
- the _rsOps
-