在我的RESTEasy应用程序中,我得到了一个java.lang.reflect.UndeclaredThrowableException,因为从一个未在throws子句中声明异常的方法抛出了一个已检查的异常.
所以我正在写一篇文章UndeclaredThrowableExceptionMapper.该UndeclaredThrowableException包装的实际除外; 我打电话e.getCause()来取回它.
我可以抛出它或以某种方式查找适当ExceptionMapper的处理它吗?
我是jersey/JAX-RS实施的新手.请在下面找到我的球衣客户代码下载文件:
Client client = Client.create();
WebResource wr = client.resource("http://localhost:7070/upload-0.0.1-SNAPSHOT/rest/files/download");
Builder wb=wr.accept("application/json,application/pdf,text/plain,image/jpeg,application/xml,application/vnd.ms-excel");
ClientResponse clientResponse= wr.get(ClientResponse.class);
System.out.println(clientResponse.getStatus());
File res= clientResponse.getEntity(File.class);
File downloadfile = new File("C://Data/test/downloaded/testnew.pdf");
res.renameTo(downloadfile);
FileWriter fr = new FileWriter(res);
fr.flush();
Run Code Online (Sandbox Code Playgroud)
我的服务器端代码是:
@Path("/download")
@GET
@Produces({"application/pdf","text/plain","image/jpeg","application/xml","application/vnd.ms-excel"})
public Response getFile()
{
File download = new File("C://Data/Test/downloaded/empty.pdf");
ResponseBuilder response = Response.ok((Object)download);
response.header("Content-Disposition", "attachment; filename=empty.pdf");
return response.build();
}
Run Code Online (Sandbox Code Playgroud)
在我的客户端代码中我得到响应200 OK,但我无法将我的文件保存在硬盘上在下面的行中我提到了文件需要保存的路径和位置.不知道这里出了什么问题,任何帮助都会受到赞赏.谢谢!
File downloadfile = new File("C://Data/test/downloaded/testnew.pdf");
Run Code Online (Sandbox Code Playgroud) 任何人都可以给我这些版本之间的差异吗?
在早期版本中我无法在第2版中做什么?
我使用PhantomJS来执行Selenium生成的代码.会有性能改进吗?
我一直在阅读的API文档Instance<T>和Provider<T>, but it isn't completely clear when they should be used.
以下方法之间有什么区别?
@Inject
MyBean bean;
Run Code Online (Sandbox Code Playgroud)
@Inject
Instance<MyBean> bean;
Run Code Online (Sandbox Code Playgroud)
@Inject
Provider<MyBean> bean;
Run Code Online (Sandbox Code Playgroud) 我想使用像一个URL http://www.example.com/rest/foo?bar,其中bar查询参数没有价值,它的单独存在应表示变量是否true或false.
目前,缺失值假定为""(空)并传递给new Boolean()它,将其视为false.
是否有更优雅的方式来定义它而不是将参数声明为String并自行转换它?
像一个类javax.rs.BooleanFlag或类似的?
我尝试使用如下代码:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Brand getBrand(@PathVariable Integer id) {
return brandService.getOne(id);
}
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
public List<Brand> getBrand(@PathVariable String name) {
return brandService.getSome(name);
}
Run Code Online (Sandbox Code Playgroud)
但我得到这样的错误,我该怎么办?
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/brand/1': {public java.util.List com.zangland.controller.BrandController.getBrand(java.lang.String), public com.zangland.entity.Brand com.zangland.controller.BrandController.getBrand(java.lang.Integer)}
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:375) ~[spring-webmvc-4.2.4.RELEASE.jar:4.2.4.RELEASE]
Run Code Online (Sandbox Code Playgroud) 我正在研究HttpURLConnection,自JDK 1.1,1997(现在差不多20年)以来存在,并且我非常惊讶它仍然是Java核心创建HTTP连接的官方方式.
自从它发布以来,许多库试图简化(/升级)HTTP连接的使用,比如Apache的HttpClient.
据我所知,没有HttpURLConnection向JDK添加包装器.
仍然是HttpURLConnection Java核心创建HTTP连接的官方方式吗?
如果没有,官方的方式是什么?
如标题中所述,哪些HTTP状态代码可以作为浏览器缓存?我做了一个快速搜索,没有找到权威的答案.
最初我认为它可能只是200好的回应,但我找不到任何支持这种想法的证据.
我有一个代码从用户获取数据并验证它是否有效.
验证是针对来自URL的数据和来自的数据JSON.
问题是,如果URL路径字段包含arg0并且它要求我从以下位置获取它message:
@ValidId (message = "The field is invalid")
private Long field;
Run Code Online (Sandbox Code Playgroud)
该领域的注释.
在这种情况下JSON,我只是可以从该领域获得path.substring(path.lastIndexOf('.') + 1).
即
protected String buildErrorMessage(ConstraintViolation<?> violation) {
String path = violation.getPropertyPath().toString();
String field = path.substring(path.lastIndexOf('.') + 1);
//field = `arg0` in case of url
//field = `field` in case of JSON
}
Run Code Online (Sandbox Code Playgroud)
如果我正面临ConstraintViolation - 如何判断违规是否来自JSON或GET?
编辑
这是我从中调用buildErrorMessage的地方 -
public class ValidationExceptionMapper implements ExceptionMapper<ValidationException> {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正在使用spring-boot开发后端服务。有一种方案可以比较2个bean(一个是DB对象,另一个是客户请求的对象),然后返回“新元素”,“修改后的元素”,如果没有变化,则返回false。2豆格式如下
"sampleList":{
"timeStamp":"Thu, 21 Jun 2018 07:57:00 +0000",
"id":"5b19441ac9e77c000189b991",
"sampleListTypeId":"type001",
"friendlyName":"sample",
"contacts":[
{
"id":"5b05329cc9e77c000189b950",
"priorityOrder":1,
"name":"sample1",
"relation":"Friend",
"sampleInfo":{
"countryCode":"91",
"numberType":"MOBILE",
"numberRegion":"IN"
}
},
{
"id":"5b05329cc9e77c000189b950",
"priorityOrder":1,
"name":"sample2",
"relation":"Friend",
"sampleInfo":{
"countryCode":"91",
"numberType":"MOBILE",
"numberRegion":"IN"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我已经在Java上浏览了有关此方案的bean比较的Internet,但是找不到任何更简单的解决方案,但是找到了一些很酷的JSON解决方案。我可以看到GSON的一些解决方案,但它不会返回包含“新元素”和“变更元素”的客户端对象。有什么方法可以用JSON或JAVA返回更新和修改的元素?您的帮助应该是可观的。对于我来说,即使是提示也将是一个很好的开始。