Author: supun
Date: Wed May 5 05:43:27 2010
New Revision: 941154
URL: http://svn.apache.org/viewvc?rev=941154&view=rev
Log:
Adding support for retrieving resources like WSDL over HTTP proxy servers
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
synapse/trunk/java/repository/conf/synapse.properties
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=941154&r1=941153&r2=941154&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
Wed May 5 05:43:27 2010
@@ -335,7 +335,16 @@ public final class SynapseConstants {
public static final String SYNAPSE_STARTUP_TASK_SCHEDULER =
"synapse.startup.taskscheduler";
- public static final String SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY =
"synapse.startup.taskdescriptions.repository";
+ public static final String SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY =
+ "synapse.startup.taskdescriptions.repository";
+
+ /** proxy server configurations used for retrieving configuration
resources over a HTTP proxy */
+ public static final String SYNPASE_HTTP_PROXY_HOST =
"synapse.http.proxy.host";
+ public static final String SYNPASE_HTTP_PROXY_PORT =
"synapse.http.proxy.port";
+ public static final String SYNPASE_HTTP_PROXY_USER =
"synapse.http.proxy.user";
+ public static final String SYNPASE_HTTP_PROXY_PASSWORD =
"synapse.http.proxy.password";
+ public static final String SYNAPSE_HTTP_PROXY_EXCLUDED_HOSTS =
+ "synapse.http.proxy.excluded.hosts";
// host and ip synapse is running
public static final String SERVER_HOST = "SERVER_HOST";
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=941154&r1=941153&r2=941154&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
Wed May 5 05:43:27 2010
@@ -25,6 +25,7 @@ import org.apache.axiom.om.impl.builder.
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.codec.binary.Base64;
import org.apache.synapse.*;
import org.apache.synapse.aspects.AspectConfiguration;
import org.apache.synapse.aspects.statistics.StatisticsCollector;
@@ -53,6 +54,8 @@ import java.net.*;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
public class SynapseConfigUtils {
@@ -337,17 +340,16 @@ public class SynapseConfigUtils {
* @param url Https URL
* @return
*/
- private static HttpsURLConnection getHttpsURLConnection(URL url) {
+ private static HttpsURLConnection getHttpsURLConnection(
+ URL url, Properties synapseProperties, Proxy proxy) {
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("Creating a HttpsURL Connection from given URL : " +
url);
}
KeyManager[] keyManagers = null;
TrustManager[] trustManagers = null;
- Properties synapseProperties =
SynapsePropertiesLoader.loadSynapseProperties();
-
IdentityKeyStoreInformation identityInformation =
KeyStoreInformationFactory.createIdentityKeyStoreInformation(synapseProperties);
@@ -382,7 +384,12 @@ public class SynapseConfigUtils {
}
try {
- HttpsURLConnection connection = (HttpsURLConnection)
url.openConnection();
+ HttpsURLConnection connection;
+ if (proxy != null) {
+ connection = (HttpsURLConnection) url.openConnection(proxy);
+ } else {
+ connection = (HttpsURLConnection) url.openConnection();
+ }
//Create a SSLContext
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers,
@@ -452,19 +459,62 @@ public class SynapseConfigUtils {
*/
public static URLConnection getURLConnection(URL url) {
- try {
+ try {
if (url == null) {
if (log.isDebugEnabled()) {
log.debug("Provided URL is null");
}
return null;
}
+
URLConnection connection;
- if (url.getProtocol().equalsIgnoreCase("https")) {
- connection = getHttpsURLConnection(url);
+ if (url.getProtocol().equalsIgnoreCase("http") ||
+ url.getProtocol().equalsIgnoreCase("https")) {
+
+ Properties synapseProperties =
SynapsePropertiesLoader.loadSynapseProperties();
+
+ String proxyHost = synapseProperties.getProperty(
+ SynapseConstants.SYNPASE_HTTP_PROXY_HOST);
+ String proxyPort = synapseProperties.getProperty(
+ SynapseConstants.SYNPASE_HTTP_PROXY_PORT);
+
+ // get the list of excluded hosts for proxy
+ List<String> excludedHosts =
getExcludedHostsForProxy(synapseProperties);
+
+ if (proxyHost != null && proxyPort != null &&
!excludedHosts.contains(proxyHost)) {
+ SocketAddress sockaddr = new InetSocketAddress(
+ proxyHost, Integer.parseInt(proxyPort));
+ Proxy proxy = new Proxy(Proxy.Type.HTTP, sockaddr);
+
+ if (url.getProtocol().equalsIgnoreCase("https")) {
+ connection = getHttpsURLConnection(url,
synapseProperties, proxy);
+ } else {
+ connection = url.openConnection(proxy);
+ }
+ } else {
+ if (url.getProtocol().equalsIgnoreCase("https")) {
+ connection = getHttpsURLConnection(url,
synapseProperties, null);
+ } else {
+ connection = url.openConnection();
+ }
+ }
+
+ // try to see weather authentication is required
+ String userName = synapseProperties.getProperty(
+ SynapseConstants.SYNPASE_HTTP_PROXY_USER);
+ String password = synapseProperties.getProperty(
+ SynapseConstants.SYNPASE_HTTP_PROXY_PASSWORD);
+ if (userName != null && password != null) {
+ String header = userName + ":" + password;
+ byte[] encodedHeaderBytes = new
Base64().encode(header.getBytes());
+ String encodedHeader = new String(encodedHeaderBytes);
+
+ connection.setRequestProperty("Proxy-Authorization",
"Basic " + encodedHeader);
+ }
} else {
connection = url.openConnection();
}
+
connection.setReadTimeout(getReadTimeout());
connection.setConnectTimeout(getConnectTimeout());
connection.setRequestProperty("Connection", "close"); // if http
is being used
@@ -475,6 +525,27 @@ public class SynapseConfigUtils {
return null;
}
+ /**
+ * Get the exclued host list for proxy server. When a connection is made
for these hosts it will
+ * not go through the proxy server
+ * @param synapseProperties properties from the synapse.properties file
+ * @return list of excluded hosts
+ */
+ private static List<String> getExcludedHostsForProxy(Properties
synapseProperties) {
+ List<String> excludedHosts = new ArrayList<String>();
+ String excludedHostsConfig = synapseProperties.
+
getProperty(SynapseConstants.SYNAPSE_HTTP_PROXY_EXCLUDED_HOSTS);
+ if (excludedHostsConfig != null) {
+ String [] list = excludedHostsConfig.split(",");
+
+ for (String host : list) {
+ excludedHosts.add(host.trim());
+ }
+ }
+
+ return excludedHosts;
+ }
+
private static void handleException(String msg) {
log.warn(msg);
throw new SynapseException(msg);
Modified: synapse/trunk/java/repository/conf/synapse.properties
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/synapse.properties?rev=941154&r1=941153&r2=941154&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/synapse.properties (original)
+++ synapse/trunk/java/repository/conf/synapse.properties Wed May 5 05:43:27
2010
@@ -128,3 +128,17 @@ synapse.jmx.jndiPort=0
# Optionally you may want to specify the location of an remote access file to
restrict access
#synapse.jmx.remote.access.file=
+#################################################################################################
+# Proxy Settings For URL Connections, these are used when synpase retrieves
resources from URLs
+# i.e. Creating proxy services from WSDL URLs, endpoints using WSDL urls etc.
+#################################################################################################
+# Proxy server
+#synapse.http.proxy.host=
+# Proxy server port
+#synapse.http.proxy.port=
+# Proxy server user name, this is used for HTTP basic authentication
+#synapse.http.proxy.user=
+# Proxy server user password, this is used for HTTP basic authentication
+#synapse.http.proxy.password=
+#list of host address exclueded from going through the proxy, list is comma
seperated
+#synapse.http.proxy.excluded.hosts=localhost, 127.0.0.1
\ No newline at end of file