// Path: src/main/java/org/jembi/openhim/RestfulHttpRequest.java
// public static enum Scheme { HTTP, HTTPS }
// 
// Path: src/main/java/org/jembi/openhim/exception/DefaultChannelInvalidConfigException.java
// public class DefaultChannelInvalidConfigException extends Exception {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public DefaultChannelInvalidConfigException() {}
// 
// 	public DefaultChannelInvalidConfigException(String message) {
// 		super(message);
// 	}
// 
// 	public DefaultChannelInvalidConfigException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	public DefaultChannelInvalidConfigException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// }


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jembi.openhim.RestfulHttpRequest.Scheme;
import org.jembi.openhim.exception.DefaultChannelInvalidConfigException;
import org.jembi.openhim.exception.URLMappingNotFoundException;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
import org.mule.api.transport.PropertyScope;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;
		}
		
		String path = null;
		
		if (mapping.getPathTransform()!=null) {
			path = transformPath(request.getPath(), mapping.getPathTransform());
		} else {
			path = mapping.getPath();
		}

		request.setPath(path);
	}
	
	private String transformPath(String path, String sPattern) throws DefaultChannelInvalidConfigException {
		//replace all \/'s with a temporary ~ so that we don't split on those
		String pattern = sPattern.replaceAll("\\\\/", "~");
		String[] sub = pattern.split("/");

		if (sub.length<2 || !sub[0].equals("s")) {
			throw new DefaultChannelInvalidConfigException("Malformed pathTransform expression. Expected \"s/from/to\"");
		}
			
		String from = sub[1].replaceAll("~", "/");
		String to = (sub.length>2) ? sub[2] : "";
		to = to.replaceAll("~", "/");

		return path.replaceAll(from, to);
	}
		

// Path: src/main/java/org/jembi/openhim/RestfulHttpRequest.java
// public static enum Scheme { HTTP, HTTPS }
// 
// Path: src/main/java/org/jembi/openhim/exception/DefaultChannelInvalidConfigException.java
// public class DefaultChannelInvalidConfigException extends Exception {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	public DefaultChannelInvalidConfigException() {}
// 
// 	public DefaultChannelInvalidConfigException(String message) {
// 		super(message);
// 	}
// 
// 	public DefaultChannelInvalidConfigException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	public DefaultChannelInvalidConfigException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// }


// Path: src/main/java/org/jembi/openhim/DefaultChannelComponent.java
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jembi.openhim.RestfulHttpRequest.Scheme;
import org.jembi.openhim.exception.DefaultChannelInvalidConfigException;
import org.jembi.openhim.exception.URLMappingNotFoundException;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
import org.mule.api.transport.PropertyScope;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.binary.Base64;

		}
		
		String path = null;
		
		if (mapping.getPathTransform()!=null) {
			path = transformPath(request.getPath(), mapping.getPathTransform());
		} else {
			path = mapping.getPath();
		}

		request.setPath(path);
	}
	
	private String transformPath(String path, String sPattern) throws DefaultChannelInvalidConfigException {
		//replace all \/'s with a temporary ~ so that we don't split on those
		String pattern = sPattern.replaceAll("\\\\/", "~");
		String[] sub = pattern.split("/");

		if (sub.length<2 || !sub[0].equals("s")) {
			throw new DefaultChannelInvalidConfigException("Malformed pathTransform expression. Expected \"s/from/to\"");
		}
			
		String from = sub[1].replaceAll("~", "/");
		String to = (sub.length>2) ? sub[2] : "";
		to = to.replaceAll("~", "/");

		return path.replaceAll(from, to);
	}
		

	protected URLMapping findURLMapping(Scheme scheme, String actualPath) {