我想用groovy做一个小ftp脚本,发现这篇文章http://www.hhhhq.org/blog/2009/05/01/ftp-using-groovy-and-ant/ 因为有几个依赖我想要用葡萄.所有依赖项都已解析并存在于缓存中.但我无法让Ant在其他库中找到可选任务.它总是说
Caught: : Problem: failed to create task or type ftp
Cause: the class org.apache.tools.ant.taskdefs.optional.net.FTP was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-ANT_HOME\lib
-the IDE Ant configuration dialogs
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
at GrabTest.runMe(GrabTest.groovy:15)
at GrabTest.run(GrabTest.groovy:26)
Run Code Online (Sandbox Code Playgroud)
Groovy版本:1.6.5 JVM:1.6.0_15
这是我的源代码
@Grab(group='ant', module='ant', version='[1.6.5,)')
@Grab(group='ant', module='ant-nodeps', …Run Code Online (Sandbox Code Playgroud) groovy eclipse插件版本:1.7.5.xx-20101020-1000-e36-release.
import com.jidesoft.swing.JideSplitButton
@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class TestClassAnnotation {
public static String testMethod () {
return JideSplitButton.class.name
}
}
new TestClassAnnotation().testMethod()
Run Code Online (Sandbox Code Playgroud)
第一行错误:Groovy:无法解析类com.jidesoft.swing.JideSplitButton
它可以作为groovy shell运行,但错误警告已经完成
我正在使用RestSharp在客户端进行开发.我也在服务器端使用Ruby Grape gem作为我的自定义API.Grape gem可以通过设置Accept HTTP header fe来进行版本控制application/vnd.twitter-v1+json
通过控制台测试命令工作完美
curl -H Accept=application/vnd.twitter-v1+json /statuses/public_timeline
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试为RestRequest设置标头时,我正在error 404服务器上.
我不知道为什么会这样.我发现了服务器返回的另一个问题406 error- 但在我的情况下是404.
如何为Accept标头添加自定义值?
我有一个使用grape-gem的工作rails应用程序作为应用程序中某些API的终点.我需要为请求者获取远程ip并在响应中将其返回.我可以在常规控制器上使用
request.remote_ip
Run Code Online (Sandbox Code Playgroud)
但是,在葡萄调用中,"请求"不是定义的变量.
如何才能访问葡萄上的远程ip?
更新 8/6:
增强的日志记录显示,从缓存中删除旧 jar 存在问题,这会导致致命的“未找到”错误。还有其他类似的线程,但只有当有人用他们的 IDE 锁定文件时。我们正在运行来自 Jenkins 的单个 groovy 脚本,并且没有人登录到此框。
我们在失败后立即运行进程浏览器,并且没有锁定。然后我使用 Jenkins 用来运行脚本的用户登录,并且删除文件没有错误。
此外,IVY 2.1 中似乎有一个修复程序,当无法删除 jar 时不会失败,而我使用的是 Ivy 2.2(Groovy 1.8.4)。是什么赋予了?
Couldn't delete outdated artifact from cache: C:\Users\myUser\.groovy\grapes\com.a.b.c\x-y-z\jars\x-y-z-1.496.jar
Run Code Online (Sandbox Code Playgroud)
然后是假(?)错误:
Caught: java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: com.a.b.c#x-y-z;1.+: not found]
at smokeTestSuccess.<clinit>(smokeTestSuccess.groovy)
Run Code Online (Sandbox Code Playgroud)
有趣的是,每天早上 5 点之后脚本第一次运行时都会发生这种情况。我猜缓存会在凌晨 5 点通过某些默认配置失效?这是某种线索吗??
原帖:
在运行许多共享相同 @Grab 声明的不同 Groovy 脚本时,我间歇性地收到错误消息。(更改文件名以保护无辜者)。首先是完整的 Grab 声明:
@GrabResolver(name = 'libs.release', root = 'http://myserver:8081/artifactory/libs-release', m2compatible = 'true') @Grapes([
@Grab(group = 'com.a.b.c, module = 'x-y-z', version = '1.+', changing …Run Code Online (Sandbox Code Playgroud) 我正在编写一个带有葡萄的API服务器,我选择使用葡萄实体,因为它能够自动生成swagger的文档.但是,当我根据需要设置一个参数时,我有一个问题.因为葡萄不能证实参数存在.看起来葡萄忽略required: true了实体的参数.
app.rb
module Smart
module Version1
class App < BaseApi
resource :app do
# POST /app
desc 'Creates a new app' do
detail 'It is used to re gister a new app on the server and get the app_id'
params Entities::OSEntity.documentation
success Entities::AppEntity
failure [[401, 'Unauthorized', Entities::ErrorEntity]]
named 'My named route'
end
post do
app = ::App.create params
present app, with: Entities::AppEntity
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
os_entity.rb
module Smart
module Entities
class OSEntity < Grape::Entity
expose …Run Code Online (Sandbox Code Playgroud) 假设我有基类"Attachment <ActiveRecord :: Base"和2个子类"Attachment :: Video <Attachment","Attachment :: Image <Attachment".
present Attachment.all, with: API::Entities::AttachmentEntity
Run Code Online (Sandbox Code Playgroud)
但我想为不同的子类使用不同的实体.附件::视频应与API :: Entities :: AttachmentEntity :: Video等一起出现
葡萄有可能吗?
我有一个要求xpp3,我表达的是:
// TestScript.groovy
@Grab(group='xpp3', module='xpp3', version='1.1.3.4.O')
import org.xmlpull.v1.XmlPullParserFactory;
println "Created: " + XmlPullParserFactory.newInstance()
Run Code Online (Sandbox Code Playgroud)
运行$ groovy TestScript.groovy失败
捕获:org.xmlpull.v1.XmlPullParserException:由:org.xmlpull.v1.XmlPullParserException引起:
但是,如果我手动将Grape提取的.jar添加到我的Groovy类路径中:
$ groovy -cp ~/.groovy/grapes/xpp3/xpp3/jars/xpp3-1.1.3.4.O.jar \
TestScript.groovy
Run Code Online (Sandbox Code Playgroud)
......然后一切正常.
第一:
我正在使用grape来构建我的API(Rails 4).当有人发送无效的JSON正文(例如忘记了最后一个})时,会出现以下错误:
ActionDispatch::ParamsParser::ParseError (795: unexpected token at '{"foobar": 1234
')
Run Code Online (Sandbox Code Playgroud)
我尝试用葡萄rescue_from :all选项,但这不起作用.在堆栈跟踪中,我看不到涉及的葡萄宝石.似乎这个错误是从actionpack抛出的:
.gems/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.rb:53:in `rescue in parse_formatted_parameters'
.gems/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.rb:32:in `parse_formatted_parameters'
.gems/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.rb:23:in `call'
Run Code Online (Sandbox Code Playgroud)
但是,捕获这些错误,返回400: Bad Request错误以及unexpected token at '{"foobar": 1234在json响应中包含消息的最佳方法是什么?
第二:
我尝试用RSpec测试这个,但是在发送带有无效JSON的原始请求时没有任何运气.我试过了
post "/my_route", '{some invalid json'
Run Code Online (Sandbox Code Playgroud)
但这不会从上面抛出错误.我认为自Rails 4以来,作为字符串传递的第二个参数被视为原始体?
我正在使用 Grape 构建 API。
我创建了一个ActiveSupport::Concern让我们说的名字Authentication,我在过滤器之前应用了一些,所以我的担忧看起来像:
module Authentication
extend ActiveSupport::Concern
included do
before do
error!('401 Unauthorized', 401) unless authenticated?
end
....
end
end
Run Code Online (Sandbox Code Playgroud)
现在让我们说在我的 UserController 中,我只想将这个问题应用于特定的操作。我怎样才能做到这一点?
class SocialMessagesController < Grape::API
include Authentication
get '/action_one' do
end
get '/action_two' do
end
end
Run Code Online (Sandbox Code Playgroud)
任何简单的方法来指定特定方法的关注点,就像before_filter在带有only选项的rails 中一样?
ruby-grape ×10
ruby ×5
groovy ×4
grape-entity ×2
ant ×1
api ×1
artifactory ×1
c# ×1
classloader ×1
classpath ×1
dependencies ×1
eclipse ×1
ftp ×1
grape-api ×1
http ×1
inheritance ×1
ip ×1
json ×1
restsharp ×1
rspec ×1