private VerifierResponse toVerifierResponse(ComponentVerifierExtension.Result result) { VerifierResponse.Builder builder = new VerifierResponse.Builder(result.getStatus().name(), result.getScope().name()); if (result.getErrors() != null) { for (ComponentVerifierExtension.VerificationError error : result.getErrors()) { builder.withError(error.getCode().getName()) .description(error.getDescription()) .parameters(error.getParameterKeys()) .attributes( error.getDetails().entrySet().stream().collect( Collectors.toMap( e -> e.getKey().name(), e -> e.getValue() ) ) ) .endError(); } } return builder.build(); }
private ComponentVerifierExtension getComponentVerifierExtension(CamelContext context, String scheme) { if (verifierExtension == null) { synchronized (this) { if (verifierExtension == null) { Component component = context.getComponent(scheme, true, false); if (component == null) { log.error("Component {} does not exist", scheme); } else { verifierExtension = component.getExtension(verifierExtensionClass).orElse(null); if (verifierExtension == null) { log.warn("Component {} does not support verifier extension", scheme); } } } } } return verifierExtension; }
public static void main(String[] args) throws Exception { ConnectorVerifier check = new ConnectorVerifier(); // Replace the stdout stream so that only we output to it.. PrintStream originalOut = System.out; System.setOut(System.err); Properties request = toProperties(System.in); ComponentVerifierExtension.Scope scope = ComponentVerifierExtension.Scope.valueOf(args[0]); String componentPrefix = args[1]; Properties response = check.verify(scope, componentPrefix, request); response.store(originalOut, null); System.exit(0); }
public void ping() throws Exception { // need to create Camel CamelContext camel = new DefaultCamelContext(); // get the connector to use Component mention = camel.getComponent("salesforce-upsert-contact-connector"); Optional<ComponentVerifierExtension> ext = mention.getExtension(ComponentVerifierExtension.class); // the connector must support ping check if its verifiable if (ext.isPresent()) { ComponentVerifierExtension verifier = ext.get(); Map<String, Object> parameters = loadParameters(); ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); System.out.println("============================================="); System.out.println(""); System.out.println("Ping check result: " + result.getStatus()); System.out.println(""); System.out.println("============================================="); } else { System.out.println("Component does not support ping check"); } }
public void ping() throws Exception { // need to create Camel CamelContext camel = new DefaultCamelContext(); // get the connector to use Component mention = camel.getComponent("twitter-mention-connector"); Optional<ComponentVerifierExtension> ext = mention.getExtension(ComponentVerifierExtension.class); // the connector must support ping check if its verifiable if (ext.isPresent()) { ComponentVerifierExtension verifier = ext.get(); Map<String, Object> parameters = loadParameters(); ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); System.out.println("============================================="); System.out.println(""); System.out.println("Ping check result: " + result.getStatus()); System.out.println(""); System.out.println("============================================="); } else { System.out.println("Component does not support ping check"); } }
public void ping() throws Exception { // need to create Camel CamelContext camel = new DefaultCamelContext(); // get the connector to use Component get = camel.getComponent("http-get-connector"); Optional<ComponentVerifierExtension> ext = get.getExtension(ComponentVerifierExtension.class); // the connector must support ping check if its verifiable if (ext.isPresent()) { ComponentVerifierExtension verifier = ext.get(); Map<String, Object> parameters = loadParameters(); ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); System.out.println("============================================="); System.out.println(""); System.out.println("Ping check result: " + result.getStatus()); System.out.println(""); System.out.println("============================================="); } else { System.out.println("Component does not support ping check"); } }
private ComponentVerifierExtension.Scope toComponentScope(Scope scope) { switch (scope) { case CONNECTIVITY: return ComponentVerifierExtension.Scope.CONNECTIVITY; case PARAMETERS: return ComponentVerifierExtension.Scope.PARAMETERS; default: throw new IllegalArgumentException("Unknown scope value " + scope); } }
private VerifierResponse toExceptionResponse(Exception exp, Scope scope, Set<String> params) { VerifierResponse.Builder builder = new VerifierResponse.Builder(Status.ERROR, scope); return builder .withError(ComponentVerifierExtension.VerificationError.StandardCode.EXCEPTION.name()) .description(exp.getMessage()) .parameters(params) .attributes(extractExceptionDetails(exp)) .endError() .build(); }
private Map<String, Object> extractExceptionDetails(Exception exp) { Map<String, Object> details = new HashMap<>(); details.put(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_CLASS.name(), exp.getClass().getName()); details.put(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE.name(), exp); return details; }
@SuppressWarnings("unchecked") @Override public <T extends ComponentExtension> Optional<T> getExtension(Class<T> extensionType) { Optional<T> extension = super.getExtension(extensionType); if (extension.isPresent()) { T ext = extension.get(); if (ComponentVerifierExtension.class.isInstance(ext)) { // hack to add custom parameters to the syndesis custom http // component final ComponentVerifierExtension verifier = (scope, map) -> { // build parameters into httpUri which is expected in the real String s = map.getOrDefault("scheme", "http").toString(); String h = map.getOrDefault("hostname", "").toString(); String p = map.getOrDefault("port", "").toString(); String c = map.getOrDefault("path", "").toString(); String url = buildUrl(s, h, p, c, null); map.put("httpUri", url); return ComponentVerifierExtension.class.cast(ext).verify(scope, map); }; return Optional.of((T)verifier); } } return extension; }
protected BaseVerifier() { this(ComponentVerifierExtension.class); }
protected BaseVerifier(Class<? extends ComponentVerifierExtension> verifierExtensionClass) { this.verifierExtensionClass = verifierExtensionClass; }
public ComponentVerifier() { this(null, ComponentVerifierExtension.class); }
public ComponentVerifier(String componentScheme) { this(componentScheme, ComponentVerifierExtension.class); }
public ComponentVerifier(Class<? extends ComponentVerifierExtension> verifierExtensionClass) { this(null, verifierExtensionClass); }
public ComponentVerifier(String componentScheme, Class<? extends ComponentVerifierExtension> verifierExtensionClass) { this.defaultComponentScheme = componentScheme; this.verifierExtensionClass = verifierExtensionClass; }
public void ping() throws Exception { // need to create Camel CamelContext camel = new DefaultCamelContext(); camel.start(); // get the connector to use Component sqlstored = camel.getComponent("sql-stored-connector"); // the connector must support ping check if its verifiable Optional<SqlStoredConnectorVerifierExtension> vce = sqlstored.getExtension(SqlStoredConnectorVerifierExtension.class); if (vce.isPresent()) { ComponentVerifierExtension verifier = vce.get(); Map<String, Object> parameters = loadParameters(); ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters); System.out.println("============================================="); System.out.println(""); System.out.println("Parameters check result: " + result.getStatus()); if (result.getStatus().equals(Result.Status.ERROR)) { System.out.println(result.getErrors()); } System.out.println(""); System.out.println("============================================="); ComponentVerifierExtension.Result result2 = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters); System.out.println("============================================="); System.out.println(""); System.out.println("Ping check result: " + result2.getStatus()); if (result2.getStatus().equals(Result.Status.ERROR)) { System.out.println(result2.getErrors()); } System.out.println(""); System.out.println("============================================="); } else { System.out.println("Component does not support ping check"); } camel.stop(); }