private HttpClient createHttpClient(ResultBuilder builder, Map<String, Object> parameters) throws Exception { HttpClientParams clientParams = setProperties(new HttpClientParams(), "httpClient.", parameters); HttpClient client = new HttpClient(clientParams); CompositeHttpConfigurer configurer = new CompositeHttpConfigurer(); configureProxy(builder, parameters).ifPresent(configurer::addConfigurer); configureAuthentication(builder, parameters).ifPresent(configurer::addConfigurer); configurer.configureHttpClient(client); return client; } }
private Optional<HttpClientConfigurer> configureAuthentication(ResultBuilder builder, Map<String, Object> parameters) { Optional<String> authMethod = getOption(parameters, "authMethod", String.class); Optional<String> authUsername = getOption(parameters, "authUsername", String.class); Optional<String> authPassword = getOption(parameters, "authPassword", String.class); AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get()); if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) { return Optional.of( ); } else if (auth == AuthMethod.NTLM) { Optional<String> authDomain = getOption(parameters, "authDomain", String.class); Optional<String> authHost = getOption(parameters, "authHost", String.class);
private void verifyHttpConnectivity(ResultBuilder builder, Map<String, Object> parameters) throws Exception { Optional<String> uri = getOption(parameters, "httpUri", String.class); HttpClient httpclient = createHttpClient(builder, parameters); HttpMethod method = new GetMethod(uri.get()); String okCodes = getOption(parameters, "okStatusCodeRange", String.class).orElse("200-299");
@Override protected Result verifyConnectivity(Map<String, Object> parameters) { // Default is success ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); Optional<String> uri = getOption(parameters, "httpUri", String.class); if (!uri.isPresent()) { // lack of httpUri is a blocking issue builder.error(ResultErrorHelper.requiresOption("httpUri", parameters)); } else { builder.error(parameters, this::verifyHttpConnectivity); } return builder.build(); }
Optional<String> proxyHost = getOption(parameters, "proxyAuthHost", String.class); if (!proxyHost.isPresent()) { proxyHost = getOption(parameters, "proxyHost", String.class); Optional<Integer> proxyPort = getOption(parameters, "proxyAuthPort", Integer.class); if (!proxyPort.isPresent()) { proxyPort = getOption(parameters, "proxyPort", Integer.class); Optional<String> authMethod = getOption(parameters, "proxyAuthMethod", String.class); if (authMethod.isPresent()) { Optional<String> authUsername = getOption(parameters, "proxyAuthUsername", String.class); Optional<String> authPassword = getOption(parameters, "proxyAuthPassword", String.class); AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod); if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) { configurer.addConfigurer( ); } else if (auth == AuthMethod.NTLM) { Optional<String> authDomain = getOption(parameters, "proxyAuthDomain", String.class); Optional<String> authHost = getOption(parameters, "proxyAuthHost", String.class);
@Override protected Result verifyParameters(Map<String, Object> parameters) { // The default is success ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS); // Validate using the catalog super.verifyParametersAgainstCatalog(builder, parameters); // Validate if the auth/proxy combination is properly set-up Optional<String> authMethod = getOption(parameters, "authMethod", String.class); if (authMethod.isPresent()) { // If auth method is set, username and password must be provided builder.error(ResultErrorHelper.requiresOption("authUsername", parameters)); builder.error(ResultErrorHelper.requiresOption("authPassword", parameters)); // Check if the AuthMethod is known AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get()); if (auth != AuthMethod.Basic && auth != AuthMethod.Digest && auth != AuthMethod.NTLM) { builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build()); } // If auth method is NTLM, authDomain is mandatory if (auth == AuthMethod.NTLM) { builder.error(ResultErrorHelper.requiresOption("authDomain", parameters)); } } return builder.build(); }