Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.http;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.camel.component.extension.ComponentVerifierExtension;
import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
import org.apache.camel.component.extension.verifier.ResultBuilder;
import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
import org.apache.camel.http.base.HttpHelper;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
final class HttpComponentVerifierExtension extends DefaultComponentVerifierExtension {
HttpComponentVerifierExtension() {
super("http");
}
// *********************************
// Parameters validation
// *********************************
@Override
protected Result verifyParameters(Map parameters) {
// Default is success
final ResultBuilder builder
= ResultBuilder.withStatusAndScope(Result.Status.OK, ComponentVerifierExtension.Scope.PARAMETERS);
// Make a copy to avoid clashing with parent validation
final HashMap verifyParams = new HashMap<>(parameters);
// Check if validation is rest-related
restRelatedSetup(parameters, verifyParams);
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, verifyParams);
return builder.build();
}
// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map parameters) {
// Default is success
final ResultBuilder builder
= ResultBuilder.withStatusAndScope(Result.Status.OK, ComponentVerifierExtension.Scope.CONNECTIVITY);
// Make a copy to avoid clashing with parent validation
final HashMap verifyParams = new HashMap<>(parameters);
final boolean isRest = restRelatedSetup(parameters, verifyParams);
String httpUri = getOption(verifyParams, "httpUri", String.class).orElse(null);
if (ObjectHelper.isEmpty(httpUri)) {
builder.error(
ResultErrorBuilder.withMissingOption("httpUri")
.detail("rest", isRest)
.build());
}
try (CloseableHttpClient httpclient = createHttpClient(verifyParams)) {
httpclient.execute(
new HttpGet(httpUri),
createObjectHttpClientResponseHandler(verifyParams, builder));
} catch (UnknownHostException e) {
builder.error(
ResultErrorBuilder.withException(e)
.parameterKey("httpUri")
.build());
} catch (Exception e) {
builder.error(ResultErrorBuilder.withException(e).build());
}
return builder.build();
}
private HttpClientResponseHandler