给出Coldfusion休息服务的最小示例(名为“FileStore”):
> agg_splits
$`1.a`
sp area point abund
1 cat 1 a 13
2 dog 1 a 13
$`2.a`
sp area point abund
1 bird 2 a 8
2 dog 2 a 2
$`1.b`
sp area point abund
1 cat 1 b 13
$`2.b`
sp area point abund
1 rabb 2 b 18
这将匹配路径:
component
restpath = ""
rest = true
{
remote void function getFile(
required string path restargsource = "Path"
)
httpmethod = "GET"
restpath = "{path}"
{
var file = FileReadBinary( "/some/path/to/local/files/#path#" );
var mimetype = customFunctionToGetMimeType( getFileFromPath( path ) );
cfcontent( variable = file, type = mimetype );
}
}
但是如果你尝试子目录 - 即
/rest/FileStore/file1.pdf
/rest/FileStore/file2.jpg
它返回HTTP状态/rest/FileStore/subdir1/file3.xml
/rest/FileStore/subdir2/subsubdir1/file4.raw
(因为,我假设它无法找到匹配的REST服务)。
有没有办法让剩余路径匹配所有子路径?
答案 0 :(得分:0)
使用URI重写执行重定向从路径中删除斜杠。
Apache中的一个例子(取自this answer)将是:
RewriteEngine on
RewriteRule ^(/rest/FileStore/[^/]*)/([^/]*/.*)$ $1__$2 [N]
RewriteRule ^(/rest/FileStore/[^/]*)/([^/]*)$ $1__$2 [R=302]
如果路径中有多个斜杠(并重复),则第一个规则将替换第一个斜杠(使用__
);第二条规则将替换最终斜杠并执行(临时)重定向。
在服务中,您可以重新重写路径以包含斜杠。
remote void function getFile(
required string path restargsource = "Path"
)
httpmethod = "GET"
restpath = "{path}"
{
var actual_path = Replace( path, "__", "/", "ALL" );
var file = FileReadBinary( "/some/path/to/local/files/#actual_path#" );
var filename = getFileFromPath( actual_path );
var mimetype = customFunctionToGetMimeType( filename );
cfheader( name = "content-disposition", value = "inline; filename=#filename#" );
cfcontent( variable = file, type = mimetype );
}
这有几个问题:
答案 1 :(得分:0)
为子目录的每个级别编写REST服务,并在内部将其指回原始服务。
Formal class 'DataFrame' [package "SparkR"] with 2 slots
..@ env: <environment: 0x000000000xxxxxxx>
..@ sdf:Class 'jobj' <environment: 0x000000000xxxxxx>
重复恶心,直至达到足够的深度,使用率达到99.9999%/足够用。
答案 2 :(得分:0)
Jersey(JAX-RS),这就是ColdFusion似乎在其服务的底层使用的,它允许regular expressions in its @PATH
notation。
使用正则表达式匹配所有字符(restpath = "{path:.*}"
),然后您可以简单地匹配所有子路径:
component
restpath = ""
rest = true
{
remote void function getFile(
required string path restargsource = "Path"
)
httpmethod = "GET"
restpath = "{path:.*}"
{
var file = FileReadBinary( "/some/path/to/local/files/#path#" );
var mimetype = customFunctionToGetMimeType( getFileFromPath( path ) );
cfcontent( variable = file, type = mimetype );
}
}
感谢this answer的灵感