小编Mar*_*cin的帖子

在Spring中为RestTemplate客户端抛出ResourceAccessException和HttpClientErrorException

在Apache Tomcat 8.5上使用Spring 4.3.1,我们实现了一个处理GET,POST和PUT请求的REST服务器.POST请求以以下形式处理:

@POST
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Transactional
public Response postMethod(final MyDomain object) {
     domainHandler.createDomain(object);
     return Response.status(201).entity(object).build();
}
Run Code Online (Sandbox Code Playgroud)

在服务器端处理POST请求期间,抛出WebApplicationException,其处理方式为:

@Provider
public class WebExceptionMapper implements ExceptionMapper<WebApplicationException> {
     @Override
     public Response toResponse(WebApplicationException exception) {
          int httpStatus = exception.getResponse().getStatus();
          ErrorMessage em = new WebErrorMessage(exception.getMessage());
          return Response.status(httpStatus).entity(em).build();
     }
}
Run Code Online (Sandbox Code Playgroud)

在客户端:

response = rest.exchange(requestURL, method, requestEntity, MyDomain.class);
Run Code Online (Sandbox Code Playgroud)

抛出ResourceAccessException:

2017-07-25 15:46:41,489 ERROR [com.my.code.web.presentation.ManagementController:63] (http-nio-8080-exec-7#34): Internal exception occured with cause:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8080/": Server returned HTTP response code: 500 for URL: http://localhost:8080/; …
Run Code Online (Sandbox Code Playgroud)

java rest spring web

12
推荐指数
1
解决办法
8620
查看次数

使用声纳 checkstyle 插件纪念 @SuppressWarnings

是否有可能使用 Checkstyle 插件配置 SonarQube 5.1 以遵守@SuppressWarnings("deprecation")注释。我不想关闭“避免使用不推荐使用的方法”规则,我只想让 SonarQube 尊重@SuppressWarnings注释。

我有一个 Java 代码,我需要在其中使用不推荐使用的createValidator()方法,如下所示:

@SuppressWarnings("deprecation")
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {
    return contextDelegate.createValidator();
}
Run Code Online (Sandbox Code Playgroud)

Java 编译器在编译代码时不会发出警告,但不幸的是,带有 CheckStyle 插件的 SonarQube 出现了一个问题:

squid:CallToDeprecatedMethod
Avoid use of deprecated methods
Run Code Online (Sandbox Code Playgroud)

checkstyle suppress-warnings sonarqube

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

checkstyle ×1

java ×1

rest ×1

sonarqube ×1

spring ×1

suppress-warnings ×1

web ×1