我有一个RESTful API,他的文档说某个查询参数是可选的,并且不提供默认参数.因此,我可以提供值,也可以不在GET请求中将其作为参数发送.
例:
queryA 是必须的queryB是可选的(GET没有它可以发送)这应该工作:
http://www.example.com/service/endpoint?queryA=foo&queryB=bar
Run Code Online (Sandbox Code Playgroud)
这应该也有效:
http://www.example.com/service/endpoint?queryA=foo
Run Code Online (Sandbox Code Playgroud)
如何为Jersey-Proxy创建一个可以执行此操作的客户端界面?我没有与服务器端代码进行交互,因此我使用org.glassfish.jersey.client.proxy.WebResourceFactoryJersey-Proxy来生成客户端以与服务器API进行交互.
样本界面:
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
@Path("/service")
@Produces("application/json")
public interface ServiceInterface {
@Path("/endpoint")
@GET
public Response getEndpoint(
@QueryParam("queryA") String first,
@QueryParam("queryB") String second);
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以制作另一种方法:
@Path("/endpoint")
@GET
public Response getEndpoint(
@QueryParam("queryA") String first);
Run Code Online (Sandbox Code Playgroud)
但是当你有多个可选字段时会发生什么?我不想让它们发生任何可能的变异!
我在Netty4中有一个问题,I/O事件由a ChannelInboundHandler或a 处理ChannelOutboundHandler
ChannelOutboundHandler?read()方法在fireChannelReadComplete()?什么是设计理念?@Override
public ChannelPipeline fireChannelReadComplete() {
head.fireChannelReadComplete();
if (channel.config().isAutoRead()) {
read();
}
return this;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP Simple HTML DOM Parser,它消耗了大量内存(使用memory_get_usage发现)!我尝试取消它但它没有做任何事情.
编辑:我解决了我的问题。(见下文。)
问题
我是 NetBeans 的新手,我遇到了一个问题,涉及将资源加载到我的 servlet 应用程序,该应用程序通过 NetBeans 运行,使用 Tomcat 作为服务器。一切都很好,直到我尝试使用 Mustache 模板库(在 Java 中)构建我的响应。此时,抛出异常:
com.github.mustachejava.MustacheException: File not under root: /opt/catalina/bin
Run Code Online (Sandbox Code Playgroud)
这个异常是在我尝试编译模板文件的代码中抛出的。我喂路径资源(模板文件)的compile方法MustacheFactory。我的代码如下所示:
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(getFormTemplatePath());
Run Code Online (Sandbox Code Playgroud)
我的研究
我查看了 Mustache 代码,尽我所知,这是发生了什么。Mustache 在加载资源时会进行安全检查,试图确保该资源位于文件系统中应用程序的根目录下。由于 NetBeans 使用某种魔法在 Tomcat 服务器上运行代码,而项目代码实际上位于文件系统的其他位置,Mustache 认为发生了一些可疑的事情。
换句话说,它可以找到文件;它只是不喜欢它在哪里找到它。似乎 Mustache/opt/catalina/bin作为应用程序的根,而模板文件实际上位于更像的路径:~/NetBeansProjects/MyProject/WEB-INF/template_file.mst.
Mustache 代码看起来像这样(这样你就可以检查我的推理):
try {
// Check to make sure that the file is under the file root or current directory.
// Without this check you might accidentally open a …Run Code Online (Sandbox Code Playgroud) 我的数据是-100o-30o lon和0o-80o lat。
我只想使用投影来显示该区域。
在我的脑海中,我想展示这样的情节:

但是,当我按以下方式尝试AlbersEqualArea投影时:
plt.figure(figsize=(5.12985642927, 3))
ax = plt.axes(projection=ccrs.AlbersEqualArea(central_longitude=-35, central_latitude=40, standard_parallels=(0, 80)))
ax.set_extent([lon180[0], lon180[-1], lat[0], lat[-1]], ccrs.Geodetic())
Run Code Online (Sandbox Code Playgroud)
我得到一张地图,显示:

显示我拥有数据的区域的最佳方法是什么?
干杯,雷