如何通过 okHttp 重用 http 保持活动连接?
我的代码示例:
public class MainWithOkHttp {
static OkHttpClient _client = new OkHttpClient();
public static void main(String[] args) {
...
query1();
...
// in this request
Request _request = new Request.Builder()
.url("...")
.addHeader("connection", "keep-alive")
.addHeader("cookie", _cookie)
.post(postParams)
.build();
// in this request my previous session is closed, why?
// my previous session = session created in query1 method
Response _response = _client.newCall(_request).execute();
...
}
...
private static void query1() {
...
Request request = new Request.Builder()
.url("...") …Run Code Online (Sandbox Code Playgroud) 我有以下简单的spring-boot应用程序,它使用apache camel:
DemoApplication.java:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Component
class MySampleRoute extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
from("file://data/input")
.bean(SampleProcessor1.class)
.to("file://data/output");
}
}
Run Code Online (Sandbox Code Playgroud)
我的豆子:
SampleProcessor1.java:
public class SampleProcessor1 {
private SampleProcessor2 sampleProcessor2;
@Autowired
public SampleProcessor1(SampleProcessor2 sampleProcessor2) {
this.sampleProcessor2 = sampleProcessor2;
}
@Handler
public void handle(
@Body GenericFile<String> file
) {
}
}
Run Code Online (Sandbox Code Playgroud)
SampleProcessor2.java:
@Component
public class SampleProcessor2 { }
Run Code Online (Sandbox Code Playgroud)
当我运行这个应用程序并将一些文件放在data/input目录中时 - 我得到以下NPE: …
我有以下两个结构:
func main() {
type A struct {
v int
}
type B struct {
v int
}
var b B = A{}
}
Run Code Online (Sandbox Code Playgroud)
分配var b B = A{}失败并显示错误消息:
不能使用“A{}”(类型 A)作为类型 B
但是在golang spec:Type identity 中它说:
如果两个结构类型具有相同的字段序列,并且对应的字段具有相同的名称、相同的类型和相同的标签,则它们是相同的。来自不同包的非导出字段名称总是不同的。
所以,我希望类型A和B是相同的。在规范:可分配性中它说:
如果满足以下条件之一,则值 x 可分配给 T 类型的变量(“x 可分配给 T”):
- x 的类型与 T 相同。
鉴于所有这些信息,我倾向于认为分配应该成功,因为 的类型与A{}相同B,但显然我遗漏了一些东西。
那么,我在这里缺少什么来了解错误消息的根本原因?
java ×2
apache-camel ×1
go ×1
keep-alive ×1
okhttp ×1
session ×1
spring-boot ×1
struct ×1
types ×1