我在执行它时将它放在示例主类中我得到nullpointerexception.it并没有提供更多细节。
我的意图是我正在使用AWS lambda函数,它会在任何节点出现故障时触发上述代码 我在上面的代码中调用了一个帖子请求,但它没有用 你能不能请任何人指导我这个amazonhttpclient相关查询的写步骤或链接。
ClientConfiguration configuration = new ClientConfiguration();
configuration.setMaxErrorRetry(3);
configuration.setConnectionTimeout(501000);
configuration.setSocketTimeout(501000);
configuration.setProtocol(Protocol.HTTP);
AmazonHttpClient httpClient = new AmazonHttpClient(
configuration);
RequestExecutionBuilder httpRequestBuilder = httpClient.requestExecutionBuilder();
@SuppressWarnings("rawtypes")
String url = "http://localhost:8080/spring4upgrade/processFailureNode";
AmazonWebServiceRequest amazonWebServiceRequest = new AmazonWebServiceRequest() {
};
Request paramRequest = new DefaultRequest(amazonWebServiceRequest,"execute-api");
paramRequest.setEndpoint(URI.create(url));
paramRequest.setHttpMethod(HttpMethodName.POST);
paramRequest.addParameter("sgroup", "xyz");
paramRequest.addParameter("host", "localhost");
paramRequest.addParameter("port", "8080");
httpRequestBuilder.request(paramRequest);
httpRequestBuilder.execute();
答案 0 :(得分:0)
之前
httpRequestBuilder.execute();
在下面添加代码
httpRequestBuilder.errorResponseHandler(new ErrorResponseHandler());
ErrorResponseHandler的代码
public class ErrorResponseHandler implements HttpResponseHandler<SdkBaseException> {
@Override
public SdkBaseException handle(final HttpResponse response) throws Exception {
// TODO
return null;
}
@Override
public boolean needsConnectionLeftOpen() {
return false;
}
}