从头开始没有任何以前的Jersey 1.x知识,我很难理解如何在我的Jersey 2.0项目中设置依赖注入.
我也明白HK2可用于Jersey 2.0,但我似乎无法找到有助于Jersey 2.0集成的文档.
@ManagedBean
@Path("myresource")
public class MyResource {
@Inject
MyService myService;
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/getit")
public String getIt() {
return "Got it {" + myService + "}";
}
}
@Resource
@ManagedBean
public class MyService {
void serviceCall() {
System.out.print("Service calls");
}
}
Run Code Online (Sandbox Code Playgroud)
的pom.xml …
如何ad-hoc解码/解压缩nock记录器产生的输出,以便我们可以看到响应为文本?我想我们不明白响应是否被压缩和/或编码
当我们将它加载到nock中时,该对象可以找到,并且我们的测试表现得像我们期望的那样.要查看API生成的内容,我们必须将日志语句放在实现文件中.
我们正在录制并保存JSON响应:
nock.recorder.rec({output_objects: true, dont_print: true});
JSON.stringify(nock.recorder.play())
Run Code Online (Sandbox Code Playgroud)
我们的文件看起来像:
[
{
"scope": "https://some.api.com:443",
"method": "POST",
"path": "/auth?key=some_key",
"body": {
"logonId": "user@api.com",
"logonPassword": "secret"
},
"status": 400,
"response": [
"1f8b0800000000000000458cbd6ac34010067b3fc5c735691263bb741344ec42f827420a492916692d1d9cb461f71c218cdf3d97266e6786b92d00c7aaa205290d1c59cd6d71bb3fff8b376939a1cd6abd7ac003cf89b97a5f96757efecc8ef9aede9fb2fc586455f5f55eeedca33db119757f0f5704266334a2ca4d44ec19170941263f76f06657b62dd6cb2af919ec9357cc7255f0cb403e4014df643689b6687d3b3e450c149b1e534f1113a3a71f868cb8f8c04b7ca48b8fa08efcf8ea16f75fa1776d91ee000000"
],
"headers": {
"cache-control": "no-store, no-cache, must-revalidate",
"content-encoding": "gzip",
"content-type": "application/json",
"transfer-encoding": "chunked",
"connection": "Close"
}
}
]
为什么 Javascript 语法不支持具有可变属性的内联对象文字?例如:
const f = function (arg) {
console.log(arg);
}
f({}['some key'] = 1) // 1
f({ 'some key' : 1}) // [object Object] { some key: 1 }
Run Code Online (Sandbox Code Playgroud)
除了这两个步骤还有其他选择吗?
var o = {}
o['some key'] = 1
f(o)
Run Code Online (Sandbox Code Playgroud)
谢谢!