Author: gnodet
Date: Wed Dec 13 07:19:32 2006
New Revision: 486681
URL: http://svn.apache.org/viewvc?view=rev&rev=486681
Log:
SM-690: add ability to setup a proxy for provider endpoints
SM-773: Ability to change the retryCount on provider endpoints
Patch provided by Fabrice Dewasmes
Added:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
(with props)
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpBootstrap.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
Wed Dec 13 07:19:32 2006
@@ -64,16 +64,27 @@
public void setPassword(String password) {
this.password = password;
}
-
- /**
- * Applies this authentication to the given method.
- * @param method The method to receive authentication headers.
- */
- public void applyCredentials( HttpClient client )
- {
- AuthScope scope = new AuthScope( AuthScope.ANY_HOST,
AuthScope.ANY_PORT );
- Credentials credentials = new UsernamePasswordCredentials(
this.username, this.password );
- client.getState().setCredentials( scope, credentials );
- }
-
+
+ /**
+ * Applies this authentication to the given method.
+ * @param method The method to receive authentication headers.
+ */
+ public void applyCredentials( HttpClient client )
+ {
+ AuthScope scope = new AuthScope( AuthScope.ANY_HOST,
AuthScope.ANY_PORT );
+ Credentials credentials = new UsernamePasswordCredentials(
this.username, this.password );
+ client.getState().setCredentials( scope, credentials );
+ }
+
+ /**
+ * Applies this authentication to the given method.
+ * @param method The method to receive authentication headers.
+ */
+ public void applyProxyCredentials( HttpClient client )
+ {
+ AuthScope scope = new AuthScope( AuthScope.ANY_HOST,
AuthScope.ANY_PORT );
+ Credentials credentials = new UsernamePasswordCredentials(
this.username, this.password );
+ client.getState().setProxyCredentials( scope, credentials );
+ }
+
}
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpBootstrap.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpBootstrap.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpBootstrap.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpBootstrap.java
Wed Dec 13 07:19:32 2006
@@ -60,6 +60,7 @@
configuration = new HttpConfiguration();
configuration.setRootDir(this.context.getInstallRoot());
configuration.setComponentName(this.context.getComponentName());
+ configuration.load();
mbeanName =
this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap");
MBeanServer server = this.context.getContext().getMBeanServer();
if (server == null) {
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
Wed Dec 13 07:19:32 2006
@@ -102,7 +102,25 @@
private int consumerProcessorSuspendTime = 60000;
/**
+ * Number of times a given HTTP request will be tried
+ * until successful. If streaming is enabled, the value
+ * will always be 0.
+ */
+ private int retryCount = 3;
+
+ /**
+ * Proxy hostname. Component wide configuration, used either for http or
https connections. Can be overriden on a endpoint basis.
+ */
+ private String proxyHost;
+
+ /**
+ * Proxy listening port. Component wide configuration, used either for
http or https connections. Can be overriden on a endpoint basis.
+ */
+ private int proxyPort;
+
+ /**
* @return Returns the rootDir.
+ * @org.apache.xbean.Property hidden="true"
*/
public String getRootDir() {
return rootDir;
@@ -117,6 +135,7 @@
/**
* @return Returns the componentName.
+ * @org.apache.xbean.Property hidden="true"
*/
public String getComponentName() {
return componentName;
@@ -294,22 +313,69 @@
}
public void setConsumerProcessorSuspendTime(int
consumerProcessorSuspendTime) {
- this.consumerProcessorSuspendTime = consumerProcessorSuspendTime;
+ this.consumerProcessorSuspendTime = consumerProcessorSuspendTime;
save();
}
+ /**
+ * @return the retryCount
+ */
+ public int getRetryCount() {
+ return retryCount;
+ }
+
+ /**
+ * @param retryCount the retryCount to set
+ */
+ public void setRetryCount(int retryCount) {
+ this.retryCount = retryCount;
+ save();
+ }
+
+ /**
+ * @return Returns the proxyHost.
+ */
+ public String getProxyHost() {
+ return this.proxyHost;
+ }
+
+ /**
+ * @param proxyHost The proxyHost to set.
+ */
+ public void setProxyHost(String proxyHost) {
+ this.proxyHost = proxyHost;
+ save();
+ }
+
+ /**
+ * @return Returns the proxyPort.
+ */
+ public int getProxyPort() {
+ return this.proxyPort;
+ }
+
+ /**
+ * @param proxyPort The proxyPort to set.
+ */
+ public void setProxyPort(int proxyPort) {
+ this.proxyPort = proxyPort;
+ save();
+ }
public void save() {
- properties.setProperty(componentName + ".jettyThreadPoolSize",
Integer.toString(jettyThreadPoolSize));
- properties.setProperty(componentName + ".jettyConnectorClassName",
jettyConnectorClassName);
- properties.setProperty(componentName + ".streamingEnabled",
Boolean.toString(streamingEnabled));
- properties.setProperty(componentName + ".maxConnectionsPerHost",
Integer.toString(maxConnectionsPerHost));
- properties.setProperty(componentName + ".maxTotalConnections",
Integer.toString(maxTotalConnections));
- properties.setProperty(componentName + ".keystoreManagerName",
keystoreManagerName);
- properties.setProperty(componentName + ".authenticationServiceName",
authenticationServiceName);
- properties.setProperty(componentName + ".jettyManagement",
Boolean.toString(jettyManagement));
- properties.setProperty(componentName + ".connectorMaxIdleTime",
Integer.toString(connectorMaxIdleTime));
- properties.setProperty(componentName +
".consumerProcessorSuspendTime",
Integer.toString(consumerProcessorSuspendTime));
+ setProperty(componentName + ".jettyThreadPoolSize",
Integer.toString(jettyThreadPoolSize));
+ setProperty(componentName + ".jettyConnectorClassName",
jettyConnectorClassName);
+ setProperty(componentName + ".streamingEnabled",
Boolean.toString(streamingEnabled));
+ setProperty(componentName + ".maxConnectionsPerHost",
Integer.toString(maxConnectionsPerHost));
+ setProperty(componentName + ".maxTotalConnections",
Integer.toString(maxTotalConnections));
+ setProperty(componentName + ".keystoreManagerName",
keystoreManagerName);
+ setProperty(componentName + ".authenticationServiceName",
authenticationServiceName);
+ setProperty(componentName + ".jettyManagement",
Boolean.toString(jettyManagement));
+ setProperty(componentName + ".connectorMaxIdleTime",
Integer.toString(connectorMaxIdleTime));
+ setProperty(componentName + ".consumerProcessorSuspendTime",
Integer.toString(consumerProcessorSuspendTime));
+ setProperty(componentName + ".retryCount",
Integer.toString(retryCount));
+ setProperty(componentName + ".proxyHost", proxyHost);
+ setProperty(componentName + ".proxyPort", Integer.toString(proxyPort));
if (rootDir != null) {
File f = new File(rootDir, CONFIG_FILE);
try {
@@ -320,6 +386,14 @@
}
}
+ protected void setProperty(String name, String value) {
+ if (value == null) {
+ properties.remove(name);
+ } else {
+ properties.setProperty(name, value);
+ }
+ }
+
public boolean load() {
File f = null;
InputStream in = null;
@@ -376,6 +450,15 @@
}
if (properties.getProperty(componentName +
".consumerProcessorSuspendTime") != null) {
consumerProcessorSuspendTime =
Integer.parseInt(properties.getProperty(componentName +
".consumerProcessorSuspendTime"));
+ }
+ if (properties.getProperty(componentName + ".retryCount") != null) {
+ retryCount = Integer.parseInt(properties.getProperty(componentName
+ ".retryCount"));
+ }
+ if (properties.getProperty(componentName + ".proxyHost") != null) {
+ proxyHost = properties.getProperty(componentName + ".proxyHost");
+ }
+ if (properties.getProperty(componentName + ".proxyPort") != null) {
+ proxyPort = Integer.parseInt(properties.getProperty(componentName
+ ".proxyPort"));
}
return true;
}
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
Wed Dec 13 07:19:32 2006
@@ -57,5 +57,17 @@
public int getConsumerProcessorSuspendTime();
public void setConsumerProcessorSuspendTime(int
consumerProcessorSuspendTime);
-
+
+ public int getRetryCount();
+
+ public void setRetryCount(int retryCount);
+
+ public String getProxyHost();
+
+ public void setProxyHost(String name);
+
+ public int getProxyPort();
+
+ public void setProxyPort(int name);
+
}
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
Wed Dec 13 07:19:32 2006
@@ -58,6 +58,7 @@
protected String authMethod;
protected String soapAction;
protected BasicAuthCredentials basicAuthentication;
+ protected ProxyParameters proxy;
/**
* @return the soapAction
@@ -132,6 +133,20 @@
*/
public void setBasicAuthentication(BasicAuthCredentials
basicAuthCredentials) {
this.basicAuthentication = basicAuthCredentials;
+ }
+
+ /**
+ * @return Returns the proxy.
+ */
+ public ProxyParameters getProxy() {
+ return this.proxy;
+ }
+
+ /**
+ * @param proxy The proxy to set.
+ */
+ public void setProxy(ProxyParameters proxy) {
+ this.proxy = proxy;
}
/**
Added:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java?view=auto&rev=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
(added)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
Wed Dec 13 07:19:32 2006
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.http;
+
+
+/**
+ * This class contains all parameters needed to send http requests through a
proxy
+ *
+ * @author Fabrice Dewasmes
+ * @org.apache.xbean.XBean
+ */
+public class ProxyParameters {
+
+ protected String proxyHost;
+ protected int proxyPort;
+ protected BasicAuthCredentials proxyCredentials;
+
+ /**
+ * @return Returns the proxyCredentials.
+ */
+ public BasicAuthCredentials getProxyCredentials() {
+ return this.proxyCredentials;
+ }
+
+ /**
+ * @param proxyCredentials The proxyCredentials to set.
+ */
+ public void setProxyCredentials(BasicAuthCredentials proxyCredentials) {
+ this.proxyCredentials = proxyCredentials;
+ }
+
+ /**
+ * Proxy Host through which every http call are emitted
+ *
+ * @return Returns the proxyHost.
+ */
+ public String getProxyHost() {
+ return this.proxyHost;
+ }
+
+ /**
+ * @param proxyHost The proxy host name to set.
+ */
+ public void setProxyHost(String proxyHost) {
+ this.proxyHost = proxyHost;
+ }
+
+ /**
+ * Proxy Port for the proxy host specified
+ *
+ * @return Returns the proxyPort.
+ */
+ public int getProxyPort() {
+ return this.proxyPort;
+ }
+
+ /**
+ * @param proxyPort The ProxyPort to set.
+ */
+ public void setProxyPort(int proxyPort) {
+ this.proxyPort = proxyPort;
+ }
+}
Propchange:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/ProxyParameters.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?view=diff&rev=486681&r1=486680&r2=486681
==============================================================================
---
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
(original)
+++
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Wed Dec 13 07:19:32 2006
@@ -34,16 +34,19 @@
import javax.jbi.messaging.NormalizedMessage;
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpHost;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.logging.Log;
@@ -154,17 +157,14 @@
method.setRequestEntity(entity);
boolean close = true;
try {
- // Uncomment to avoid the http request being sent several times.
- // Can be useful when debugging
- //================================
- //method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new HttpMethodRetryHandler() {
- // public boolean retryMethod(HttpMethod method, IOException
exception, int executionCount) {
- // return false;
- // }
- //});
+ // Set the retry handler
+ int retries = getConfiguration().isStreamingEnabled() ? 0 :
getConfiguration().getRetryCount();
+ method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(retries, true));
+ // Set authentication
if (endpoint.getBasicAuthentication() != null) {
endpoint.getBasicAuthentication().applyCredentials(
getClient() );
}
+ // Execute the HTTP method
int response =
getClient().executeMethod(getHostConfiguration(locationURI), method);
if (response != HttpStatus.SC_OK && response !=
HttpStatus.SC_ACCEPTED) {
if (exchange instanceof InOnly == false) {
@@ -256,7 +256,16 @@
host = new HostConfiguration();
host.setHost(uri.getHost(), uri.getPort());
}
-
+ if (endpoint.getProxy() != null) {
+ if ((endpoint.getProxy().getProxyHost() != null) &&
(endpoint.getProxy().getProxyPort() != 0)) {
+ host.setProxy(endpoint.getProxy().getProxyHost(),
endpoint.getProxy().getProxyPort());
+ }
+ } else if ((getConfiguration().getProxyHost() != null) &&
(getConfiguration().getProxyPort() != 0)) {
+ host.setProxy(getConfiguration().getProxyHost(),
getConfiguration().getProxyPort());
+ }
+ if (endpoint.getProxy().getProxyCredentials() != null) {
+
endpoint.getProxy().getProxyCredentials().applyProxyCredentials(getClient());
+ }
return host;
}