我试图将一个错误消息从grails控制器传递给grails错误控制器,以便在HTTP响应中显示错误消息,但我不确定哪个参数在错误控制器中保存错误消息.
URLMappings.groovy
所有500个错误都映射到ErrorsController
"500"(controller: "errors", action: "serverError")
Run Code Online (Sandbox Code Playgroud)
GenericController
def {
try{
//do some work
}catch(Exception e){
response.sendError(500, e.getMessage())
}
}
Run Code Online (Sandbox Code Playgroud)
ErrorsController
def serverError = {
render( how can I access the exception details here?? )
}
Run Code Online (Sandbox Code Playgroud)
我需要在ErrorsController中访问异常,以便将其输出到HTTP响应.
我有一个简单的Grails应用程序与以下RESTful uri ...
http://localhost:8080/kennis-api/funds/test/700
Run Code Online (Sandbox Code Playgroud)
我的URIMappings中的映射是
"/funds/test/$fcode" (controller: "fundCache"){
action = [GET: "show"]
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我需要提取请求URI,在本例中为"/ funds/test/700",但是调用request.uri或request.getRequestUri不起作用.我尝试使用request.requestURL,但这给了我
HTTP://本地主机:8080/KENNIS-API/Grails的/ fundCache/show.dispatch
是否有特殊的成员或功能来获取请求uri?
使用Grails 2.0.4,我正在尝试rest-client-builder:1.0.2使用这个...
grails install-plugin rest-client-builder
Run Code Online (Sandbox Code Playgroud)
...但Grails返回以下错误; 我已经尝试过清理,刷新依赖关系等等,继续得到同样的错误......
:: #rest-client-builder;1.0.2: java.text.ParseException: inconsistent module descriptor file found in 'http://plugins.grails.org/grails-rest-client-builder/tags/RELEASE_1_0_2/rest-client-builder-1.0.2.pom': bad organisation: expected='' found='org.grails.plugins';
Run Code Online (Sandbox Code Playgroud)
还尝试将插件作为依赖项链接BuildConfig.groovy,但是我得到了类似的错误......
compile (":rest-client-builder:1.0.2"){ export = false}
grailsCentral: bad organisation found in http://plugins.grails.org/grails-rest-client-builder/tags/RELEASE_1_0_2/rest-client-builder-1.0.2.pom: expected='' found='org.grails.plugins'
Run Code Online (Sandbox Code Playgroud) 我正在构建一个利用 ZeroMQ N 到 N 发布/订阅模型的 POC。从我们的应用服务器,当一个 http 请求被服务时,如果线程从数据库中提取数据,它会用该数据更新本地 memcache 实例。要应用服务器集群中同步其他内存缓存的情况下,请求线程发送与使用ZMQ发行该数据的消息......这样的问题是:战略是什么最有效的关于减少套接字创建/ destory开销当应用程序有许多线程依赖套接字发送消息?我们是否共享套接字池,我们是否为每个线程创建/销毁套接字等?
策略 1 - 线程管理的发布者套接字
在这种方法中,每个线程 , T1,T2和T3管理套接字对象(发布者)的生命周期,方法是创建它、建立连接、发送消息,最后关闭套接字。基于此,这当然是最安全的方法,但是我们担心重复创建、连接和销毁套接字时的开销;如果开销对性能产生负面影响,我们希望避免它。

策略 2 - 发布者套接字对象池
在这种方法中,父进程(应用服务器)在启动时初始化一个 ZMQ 发布者池。当一个线程需要一个发布者时,它从对象池中获取一个发布者,发送它的消息,然后将发布者返回给对象池;对于使用发布者的线程,消除了创建、连接和销毁套接字的过程,但对池的访问是同步的,以避免任何两个线程同时使用相同的发布者对象,这就是死锁和并发问题的地方可能会出现。
我们没有对任何一种方法进行分析,因为想先对 SO 测试做一个试金石。关于数量,我们的应用程序不会发布“大量”消息,但可能有 100-150 个线程(每个应用服务器)同时需要发布消息。

因此,重申一下:当应用程序有许多依赖于发布者发送消息的线程时,在最小化开销同时强调性能方面,哪种策略最有效?
今天遇到了这个奇怪的结果,试图在Grails 2.0.4中将对象列表呈现为JSON ...(我知道我会后悔因为我的鼻子下的东西而问这个... 更新 5/26,我的预测是正确的,见下文:-))
这很好用; JSON在浏览器中正确呈现...
def products = [] //ArrayList of Product objects from service
def model = (products) ? [products:products] : [products:"No products found"]
render model as JSON
Run Code Online (Sandbox Code Playgroud)
..那为什么没有这个缩短版本没有model工作?
def products = []
render ((products) ? [products:products] : [products:"No products found"]) as JSON
Run Code Online (Sandbox Code Playgroud)
上面代码生成的JSON作为单行文本输出,所以我怀疑它没有提升as JSON,但是它的括号是正确的,那么交易是什么?
['products':[com.test.domain.Product:null,com.test.domain.Product ...]
我正在csharp(.net 4.0)中构建一个消息传递应用程序,我的类具有发送/接收消息的基本方法:
void sendMessage( string msgBody, string properties);
object getNextMessage();
object getMessageById( string msgId);
Run Code Online (Sandbox Code Playgroud)
这些方法中的每一种都取决于底层连接; 如果连接是陈旧的,我使用try/catch和一些重试逻辑来进行额外的尝试,如下所示:
public object getNextMessage(){
object nextMessage = null;
int retryAttempts = 0;
int MAX_ATTEMPTS = 3;
while( retryAttempts < MAX_ATTEMPTS){
retryAttempts++;
try{
nextMessage = connection.getMessage("queueName");
}catch(Exception e){
}
}
return nextMessage;
}
Run Code Online (Sandbox Code Playgroud)
由于重试逻辑是通用的,我想避免在每个方法中重复相同的代码.我想创建一个通用的重试功能,并执行以下操作:
public object makeAttempt( CodeBlock codeBlock){
while( retryAttempts < MAX_ATTEMPTS){
retryAttempts++;
try{
return codeBlock.invoke()
}catch(Exception e){
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
..我想像这样使用makeAttempt,或类似的东西:
public object getNextMessage(){
makeAttempt() => {
return connection.getMessage("queueName");
} …Run Code Online (Sandbox Code Playgroud) Groovy 中的 null 安全运算符非常适合减少代码并使代码更具可读性。我们可以从这里开始:
def customer = getCustomer(custNo)
if(!customer)
throw new Exception("Invalid customer: ${custNo}")
def policy = customer.getPolicy(policyNo)
if(!policy)
throw new Exception("Invalid policy: ${policyNo}")
def claim = policy.getClaim(claimNo)
if(!claim)
throw new Exception("Invalid claim: ${claimNo}")
Run Code Online (Sandbox Code Playgroud)
..对此...
def claim = getCustomer(custNo)?.getPolicy(policyNo)?.getClaim(claimNo)
Run Code Online (Sandbox Code Playgroud)
但没有什么是免费的;使用 null/安全导航,如果claim为 null,则不会立即明显看出导致它的原因:custNo、policyNo或claimNo可能无效。
我们可以返回并开始检查什么是 null,但这会适得其反,实际上,这是不可能的,因为中间对象不存储在变量中。
所以问题是:当使用 null/安全导航链接方法调用时是否可以识别什么是 null?
我使用动态方法调用再次尝试了这一点。它需要一个 init 目标(通常是一个 dao)来初始化对象(在本例中为 customer),以及一个包含方法名称作为字符串(参数作为值)的映射。使用迭代器,invokeChain简单地遍历映射(链);如果链中的任何内容返回 null,那么识别导致它的方法就变得微不足道。
def invokeChain = { initTarget, chain ->
def obj
chain.eachWithIndex{ it, idx …Run Code Online (Sandbox Code Playgroud) 在Grails 2.3.7上,假设以下url映射..
"/foo/$number?" (controller:'test', action:'actionOne')
"/foo/$number?/bar" (controller:'test', action:'actionTwo')
Run Code Online (Sandbox Code Playgroud)
..和控制器:
class TestController {
def actionOne(){ render "Action_ONE: ${params.number}" }
def actionTwo(){ render "Action_TWO: ${params.number}" }
}
Run Code Online (Sandbox Code Playgroud)
都好...
/foo/1 //prints 'Action_ONE: 1'
/foo/2/bar //prints 'Action_TWO: 2'
/foo//bar //prints 'Action_TWO: null'
/foo// //prints 'Action_ONE: null'
Run Code Online (Sandbox Code Playgroud)
...但
/foo //prints 'Action_TWO: null'
/foo/ //prints 'Action_TWO: null'
Run Code Online (Sandbox Code Playgroud)
如果number是可选的/foo/$number?,为什么/foo和/foo/映射到actionTwo()?
寻找帮助实现Stacks新文档站点上显示的小蓝点,它非常适合动画我正在构建的显示服务运行状况/指标的仪表板.我使用Chrome的检查员抓住了html/css,但我对这些东西很糟糕,我甚至无法得到一个点,更不用说是一个发光的蓝色点;-D
https://jsfiddle.net/raffinyc/3trup2c1/
.help-bubble:after {
content: "";
background-color: #3af;
width: 12px;
height: 12px;
border-radius: 50%;
position: absolute;
display: block;
top: 1px;
left: 1px;
}
<span class="help-bubble-outer-dot">
<span class="help-bubble-inner-dot"></span>
</span>
Run Code Online (Sandbox Code Playgroud)
我想从嵌入式数组中提取特定项目...假设以下mongo文档....
db.test.find()
{
id:1,
comments :
[
{ cid: 1 },
{ cid: 2 },
{ cid: 3 },
{ cid: 4 },
{ cid: 5 }
]
}
Run Code Online (Sandbox Code Playgroud)
我想从comments数组中删除一个项目cid,而不是按位置.我已经尝试了所有这些,但它们似乎都不起作用.我尝试过使用点符号,但这似乎没有任何效果.我尝试了如何从数组中删除第n个元素的最后一篇帖子建议,但没有运气......
db.test.update({ 'comments.cid' : 5}, {"$pull" :{"comments":{"cid":"3"}}} )
db.test.update( {id: 1}, {"$pull" : {"comments" : { "cid" : "3"}}},false,false)
db.test.update( {id: 1}, {"$pull" :{"comments.cid" :3}})
Run Code Online (Sandbox Code Playgroud)