package com.boundary.sdk;

import java.util.Map;
import java.util.Set;

import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.Processor;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http.AuthMethod;
import org.apache.camel.component.http.HttpComponent;
import org.apache.camel.component.http.HttpConfiguration;
import org.apache.camel.component.syslog.SyslogMessage;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * {@link RouteBuilder} for sending events to Boundary.
 * @author davidg
 *
 */
public class BoundaryEventRouteBuilder extends BoundaryRouteBuilder {
	
	private static Logger LOG = LoggerFactory.getLogger(BoundaryEventRouteBuilder.class);

	private String apiHost;
	private String orgId;
	private String apiKey;

	
	public BoundaryEventRouteBuilder() {
		this.apiHost = "api.boundary.com";
		this.orgId = "";
		this.apiKey = "";
		this.fromUri = "direct:boundary-event";
	}
		
	/**
	 * Set the Boundary Organization ID to use by default
	 * 
	 * @param orgId Organizationa Id from the Boundary console.
	 */
	
	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}
	
	/**
	 * Set the Boundary authentication key
	 * 
	 * @param apiKey API key from the Boundary Console
	 */
	public void setApiKey(String apiKey) {
		this.apiKey = apiKey;
	}
	
	/**
	 * Current value of the API key
	 * 
	 * @return String
	 */
	public String getApiKey() {
		return this.apiKey;
	}
		
	/**
	 * Set the host to use for sending Boundary API requests
	 * 
	 * @param apiHost
	 */
	public void setApiHost(String apiHost) {
		this.apiHost = apiHost;
	}
	
	/**
	 * Return the current Boundary API host
	 * 
	 * @return
	 */
	public String getApiHost() {
		return this.apiHost;
	}
		
	
	/**
	 * Configures the Camel route that receives {@link RawEvents}
	 * and then sends to the Boundary API
	 * 
	 */
	@Override
	public void configure() {
		
		// Create the URL used to send events
		String url = "https://" + apiHost + "/" + orgId + "/" + "events";
		
		// Configure our HTTP connection to use BASIC authentication
		HttpConfiguration config = new HttpConfiguration();
		config.setAuthMethod(AuthMethod.Basic);
		config.setAuthUsername(this.apiKey);
		config.setAuthPassword("");
		
		HttpComponent http = this.getContext().getComponent("https",HttpComponent.class);
		http.setHttpConfiguration(config);
		
		from(fromUri)
			.startupOrder(startUpOrder)
			.routeId(routeId)
			.unmarshal().serialization()
			.marshal().json(JsonLibrary.Jackson)
			.to("log:com.boundary.sdk.BoundaryEventRoute?level=DEBUG&showBody=true")
			.setHeader(Exchange.ACCEPT_CONTENT_TYPE, constant("application/json"))
			.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
			.setHeader(Exchange.HTTP_METHOD, constant("POST"))
			.to("log:com.boundary.sdk.BoundaryEventRoute?level=DEBUG&groupInterval=10000&groupDelay=60000&groupActiveOnly=false")
			.to(url.toString())
			.to("log:com.boundary.sdk.BoundaryEventRoute?level=INFO&showHeaders=true&multiline=true")
			;
	}
}

@@ -31,182 +31,31 @@
 ort 
-java.util.Map;%0Aimport java.util.Set;%0A%0Aimport org.apache.camel.Exchange;%0Aimport org.apache.camel.LoggingLevel;%0Aimport org.apache.camel.Processor;%0Aimport org.apache.camel.Messa
+org.apache.camel.Exchan
 ge;%0A
@@ -205,16 +205,16 @@
 ponent;%0A
+
 import o
@@ -267,64 +267,8 @@
 on;%0A
-import org.apache.camel.component.syslog.SyslogMessage;%0A
 impo
@@ -1914,24 +1914,73 @@
 events%22;%0A%09%09%0A
+%09%09LOG.info(%22boundary event api url: %22 + url);%0A%09%09%0A
 %09%09// Configu

Add log statement that shows the boundary event api url ; remove unused imports