You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2010/07/30 08:42:32 UTC
svn commit: r980660 - in
/servicemix/components/bindings/servicemix-http/trunk/src:
main/java/org/apache/servicemix/http/
main/java/org/apache/servicemix/http/endpoints/
main/resources/OSGI-INF/blueprint/ test/java/org/apache/servicemix/http/
test/java...
Author: ffang
Date: Fri Jul 30 06:42:31 2010
New Revision: 980660
URL: http://svn.apache.org/viewvc?rev=980660&view=rev
Log:
[SMXCOMP-722]Http Component & Http Provider Endpoint do not offer a way to change the Jetty expiration time
Added:
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java
Modified:
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpComponent.java
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
servicemix/components/bindings/servicemix-http/trunk/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml
servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpTxTest.java
Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpComponent.java?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpComponent.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpComponent.java Fri Jul 30 06:42:31 2010
@@ -178,6 +178,7 @@ public class HttpComponent extends Defau
btp.setMaxThreads(getConfiguration().getJettyClientThreadPoolSize());
tempClient.setThreadPool(btp);
tempClient.setConnectorType(org.mortbay.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL);
+ tempClient.setTimeout(getConfiguration().getProviderExpirationTime());
tempClient.start();
return tempClient;
}
Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfiguration.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfiguration.java Fri Jul 30 06:42:31 2010
@@ -113,6 +113,11 @@ public class HttpConfiguration implement
* servicemix is 60000msec)
*/
private int consumerProcessorSuspendTime = 60000;
+
+ /***
+ * HttpProvider endpoint expiration time.
+ */
+ private int providerExpirationTime = 60000;
/**
* Number of times a given HTTP request will be tried until successful. If
@@ -525,6 +530,28 @@ public class HttpConfiguration implement
save();
}
+
+ /***
+ * Gets the number of milliseconds that the provider will wait for a response before expiring.
+ * @return an int representing the ammout of time the provider will wait for a response before expiring.
+ */
+ public int getProviderExpirationTime() {
+ return providerExpirationTime;
+ }
+
+ /**
+ * Sets the number of milliseconds the provider will wait for a response (read timeout).
+ * The default default value for Jetty is 300000.
+ *
+ * @param providerExpirationTime an int representing the number of milliseconds the Jetty will wait for a response.
+ * @org.apache.xbean.Property description="the number of miliseconds Jetty will susspend the processing of a request. The default is 60000."
+ */
+ public void setProviderExpirationTime(int providerExpirationTime) {
+ this.providerExpirationTime = providerExpirationTime;
+ }
+
+
+
/**
* Gets the number of times a request will be tried before an error is
* created.
@@ -621,6 +648,7 @@ public class HttpConfiguration implement
setProperty(componentName + ".connectorMaxIdleTime", Integer.toString(connectorMaxIdleTime));
setProperty(componentName + ".consumerProcessorSuspendTime", Integer
.toString(consumerProcessorSuspendTime));
+ setProperty(componentName + ".providerExpirationTime", Integer.toString(providerExpirationTime));
setProperty(componentName + ".retryCount", Integer.toString(retryCount));
setProperty(componentName + ".proxyHost", proxyHost);
setProperty(componentName + ".proxyPort", Integer.toString(proxyPort));
@@ -719,6 +747,10 @@ public class HttpConfiguration implement
consumerProcessorSuspendTime = Integer.parseInt(properties
.getProperty(componentName + ".consumerProcessorSuspendTime"));
}
+ if (properties.getProperty(componentName + ".providerExpirationTime") != null) {
+ providerExpirationTime = Integer.parseInt(properties
+ .getProperty(componentName + ".providerExpirationTime"));
+ }
if (properties.getProperty(componentName + ".retryCount") != null) {
retryCount = Integer.parseInt(properties.getProperty(componentName + ".retryCount"));
}
Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/HttpConfigurationMBean.java Fri Jul 30 06:42:31 2010
@@ -65,6 +65,10 @@ public interface HttpConfigurationMBean
int getConsumerProcessorSuspendTime();
void setConsumerProcessorSuspendTime(int consumerProcessorSuspendTime);
+
+ int getProviderExpirationTime();
+
+ void setProviderExpirationTime(int providerExpirationTime);
int getRetryCount();
Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java Fri Jul 30 06:42:31 2010
@@ -64,6 +64,7 @@ public class HttpProviderEndpoint extend
private HttpProviderMarshaler marshaler;
private String locationURI;
private int clientSoTimeout = 60000;
+ private int providerExpirationTime = 300000;
private HttpClient jettyClient;
private boolean ownClient = false;
private String principal;
@@ -329,6 +330,7 @@ public class HttpProviderEndpoint extend
}
}
jettyClient.setSoTimeout(getClientSoTimeout());
+ jettyClient.setTimeout(getProviderExpirationTime());
if (principal != null && credentials != null) {
jettyClient.setRealmResolver(new SimpleRealmResolver(new Realm() {
public String getPrincipal() {
@@ -371,6 +373,20 @@ public class HttpProviderEndpoint extend
this.clientSoTimeout = clientTimeout;
}
+ public int getProviderExpirationTime() {
+ return providerExpirationTime;
+ }
+
+ /***
+ * Sets the number of milliseconds the endpoint will wait to read the response. The default value is 300000.
+ *
+ * @param providerExpirationTime an int specifying the number of milliseconds to wait for a response before expiring.
+ * @org.apache.xbean.Property description="the number of milliseconds to wait for a response before expiring."
+ */
+ public void setProviderExpirationTime(int providerExpirationTime) {
+ this.providerExpirationTime = providerExpirationTime;
+ }
+
public void validate() throws DeploymentException {
super.validate();
if (marshaler == null) {
Modified: servicemix/components/bindings/servicemix-http/trunk/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/main/resources/OSGI-INF/blueprint/servicemix-http.xml Fri Jul 30 06:42:31 2010
@@ -31,6 +31,7 @@
<bean id="servicemix-http-configuration" class="org.apache.servicemix.http.HttpConfiguration">
<property name="connectorMaxIdleTime" value="${connectorMaxIdleTime}" />
<property name="consumerProcessorSuspendTime" value="${consumerProcessorSuspendTime}" />
+ <property name="providerExpirationTime" value="${providerExpirationTime}" />
<property name="jettyClientThreadPoolSize" value="${jettyClientThreadPoolSize}" />
<property name="jettyConnectorClassName" value="${jettyConnectorClassName}" />
<property name="jettyThreadPoolSize" value="${jettyThreadPoolSize}" />
@@ -91,6 +92,7 @@
<cm:default-properties>
<cm:property name="connectorMaxIdleTime" value="30000"/>
<cm:property name="consumerProcessorSuspendTime" value="60000"/>
+ <cm:property name="providerExpirationTime" value="300000"/>
<cm:property name="jettyClientThreadPoolSize" value="16"/>
<cm:property name="jettyConnectorClassName" value="org.mortbay.jetty.nio.SelectChannelConnector"/>
<cm:property name="jettyThreadPoolSize" value="255"/>
Modified: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpTxTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpTxTest.java?rev=980660&r1=980659&r2=980660&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpTxTest.java (original)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/HttpTxTest.java Fri Jul 30 06:42:31 2010
@@ -36,6 +36,7 @@ import org.apache.servicemix.jbi.nmr.flo
import org.apache.servicemix.tck.ExchangeCompletedListener;
import org.jencks.GeronimoPlatformTransactionManager;
+
public class HttpTxTest extends TestCase {
private ExchangeCompletedListener listener;
Added: servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java?rev=980660&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java (added)
+++ servicemix/components/bindings/servicemix-http/trunk/src/test/java/org/apache/servicemix/http/endpoints/HttpProviderExpirationTest.java Fri Jul 30 06:42:31 2010
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2010 iocanel.
+ *
+ * Licensed 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.
+ * under the License.
+ */
+package org.apache.servicemix.http.endpoints;
+
+import java.net.URI;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.Destination;
+import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.http.HttpComponent;
+import org.apache.servicemix.http.HttpEndpointType;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.nmr.flow.Flow;
+import org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow;
+
+/**
+ *
+ * @author ioannis canellos
+ */
+public class HttpProviderExpirationTest extends TestCase {
+
+ private JBIContainer jbi;
+ private BrokerService broker;
+
+ protected void setUp() throws Exception {
+ broker = new BrokerService();
+ broker.setUseJmx(false);
+ broker.setPersistent(false);
+ broker.addConnector("tcp://localhost:61616");
+ broker.start();
+
+
+ jbi = new JBIContainer();
+ jbi.setFlows(new Flow[]{new SedaFlow()});
+ jbi.setEmbedded(true);
+ jbi.setUseMBeanServer(false);
+ jbi.setCreateMBeanServer(false);
+ jbi.setAutoEnlistInTransaction(true);
+ jbi.init();
+ jbi.start();
+ }
+
+ protected void tearDown() throws Exception {
+ jbi.shutDown();
+ broker.stop();
+ }
+
+ public void testExpirationOnComponent() throws Exception {
+ EchoComponent echo = new EchoComponent();
+ echo.setService(new QName("urn:test", "echo"));
+ echo.setEndpoint("echo");
+ jbi.activateComponent(echo, "echo");
+
+ HttpProviderEndpoint provider = new HttpProviderEndpoint();
+ provider.setService(new QName("urn:test", "provider"));
+ provider.setEndpoint("provider");
+ provider.setLocationURI("http://localhost:8192/expiration/");
+ provider.setProviderExpirationTime(100000);
+
+ HttpConsumerEndpoint consumer = new HttpConsumerEndpoint();
+ consumer.setService(new QName("urn:test", "consumer"));
+ consumer.setEndpoint("consumer");
+ consumer.setTargetService(new QName("urn:test", "echo"));
+ consumer.setLocationURI("http://localhost:8192/expiration/");
+ consumer.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out"));
+ consumer.setMarshaler(new DefaultHttpConsumerMarshaler() {
+
+ @Override
+ public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ Thread.sleep(10000);
+ super.sendOut(exchange, outMsg, request, response);
+ }
+ });
+
+
+ HttpComponent http = new HttpComponent();
+ http.getConfiguration().setProviderExpirationTime(10);
+ http.setEndpoints(new HttpEndpointType[]{provider, consumer});
+ jbi.activateComponent(http, "http");
+
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ Destination d = client.createDestination("service:urn:test:provider");
+ InOut me = d.createInOutExchange();
+ me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+
+ boolean ok = client.sendSync(me);
+ Exception exception = me.getError();
+ assertTrue(exception != null);
+ }
+
+ public void testExpirationOnProvider() throws Exception {
+ EchoComponent echo = new EchoComponent();
+ echo.setService(new QName("urn:test", "echo"));
+ echo.setEndpoint("echo");
+ jbi.activateComponent(echo, "echo");
+
+ HttpProviderEndpoint provider = new HttpProviderEndpoint();
+ provider.setService(new QName("urn:test", "provider"));
+ provider.setEndpoint("provider");
+ provider.setLocationURI("http://localhost:8192/expiration/");
+ provider.setProviderExpirationTime(10);
+
+ HttpConsumerEndpoint consumer = new HttpConsumerEndpoint();
+ consumer.setService(new QName("urn:test", "consumer"));
+ consumer.setEndpoint("consumer");
+ consumer.setTargetService(new QName("urn:test", "echo"));
+ consumer.setLocationURI("http://localhost:8192/expiration/");
+ consumer.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out"));
+ consumer.setMarshaler(new DefaultHttpConsumerMarshaler() {
+
+ @Override
+ public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ Thread.sleep(10000);
+ super.sendOut(exchange, outMsg, request, response);
+ }
+ });
+
+
+ HttpComponent http = new HttpComponent();
+ //To avoid adding delaying mechanisms we are using an extremly low expiration time.
+ http.getConfiguration().setProviderExpirationTime(300000);
+ http.getConfiguration().setJettyClientPerProvider(true);
+ http.setEndpoints(new HttpEndpointType[]{provider, consumer});
+ jbi.activateComponent(http, "http");
+
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ Destination d = client.createDestination("service:urn:test:provider");
+ InOut me = d.createInOutExchange();
+ me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+
+ boolean ok = client.sendSync(me);
+ Exception exception = me.getError();
+ assertTrue(exception != null);
+ }
+
+ public void testNoExpiration() throws Exception {
+ EchoComponent echo = new EchoComponent();
+ echo.setService(new QName("urn:test", "echo"));
+ echo.setEndpoint("echo");
+ jbi.activateComponent(echo, "echo");
+
+ HttpProviderEndpoint provider = new HttpProviderEndpoint();
+ provider.setService(new QName("urn:test", "provider"));
+ provider.setEndpoint("provider");
+ provider.setLocationURI("http://localhost:8192/expiration/");
+ provider.setProviderExpirationTime(300000);
+
+ HttpConsumerEndpoint consumer = new HttpConsumerEndpoint();
+ consumer.setService(new QName("urn:test", "consumer"));
+ consumer.setEndpoint("consumer");
+ consumer.setTargetService(new QName("urn:test", "echo"));
+ consumer.setLocationURI("http://localhost:8192/expiration/");
+ consumer.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out"));
+ consumer.setMarshaler(new DefaultHttpConsumerMarshaler() {
+
+ @Override
+ public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ Thread.sleep(10000);
+ super.sendOut(exchange, outMsg, request, response);
+ }
+ });
+
+
+ HttpComponent http = new HttpComponent();
+ //To avoid adding delaying mechanisms we are using an extremly low expiration time.
+ http.getConfiguration().setProviderExpirationTime(300000);
+ http.getConfiguration().setJettyClientPerProvider(true);
+ http.setEndpoints(new HttpEndpointType[]{provider, consumer});
+ jbi.activateComponent(http, "http");
+
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ Destination d = client.createDestination("service:urn:test:provider");
+ InOut me = d.createInOutExchange();
+ me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+
+ boolean ok = client.sendSync(me);
+ Exception exception = me.getError();
+ assertTrue(exception == null);
+ client.done(me);
+ }
+}