You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/06/24 14:41:19 UTC
[2/2] git commit: CAMEL-5842: Added responseBufferSize option to
camel-jetty/http.
CAMEL-5842: Added responseBufferSize option to camel-jetty/http.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/42b564ea
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/42b564ea
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/42b564ea
Branch: refs/heads/camel-2.11.x
Commit: 42b564ea6a64d687505230e6c53355d563c9ed26
Parents: a758fd2
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 24 14:40:42 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 24 14:41:00 2013 +0200
----------------------------------------------------------------------
.../camel/component/http/CamelServlet.java | 14 +++++--
.../camel/component/http/HttpEndpoint.java | 8 ++++
.../jetty/CamelContinuationServlet.java | 25 +++++++++---
.../component/jetty/JettyHttpComponent.java | 13 +++++++
.../component/jetty/JettyHttpEndpoint.java | 1 -
.../jetty/JettyResponseBufferSizeTest.java | 40 ++++++++++++++++++++
.../camel/component/jetty/SimpleJettyTest.java | 40 ++++++++++++++++++++
7 files changed, 131 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
index 1957873..7da5f30 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
@@ -111,7 +111,9 @@ public class CamelServlet extends HttpServlet {
}
try {
- log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
+ if (log.isTraceEnabled()) {
+ log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
+ }
// process the exchange
consumer.getProcessor().process(exchange);
} catch (Exception e) {
@@ -119,9 +121,15 @@ public class CamelServlet extends HttpServlet {
}
try {
- log.trace("Writing response for exchangeId: {}", exchange.getExchangeId());
-
// now lets output to the response
+ if (log.isTraceEnabled()) {
+ log.trace("Writing response for exchangeId: {}", exchange.getExchangeId());
+ }
+ Integer bs = consumer.getEndpoint().getResponseBufferSize();
+ if (bs != null) {
+ log.trace("Using response buffer size: {}", bs);
+ response.setBufferSize(bs);
+ }
consumer.getBinding().writeResponse(exchange, response);
} catch (IOException e) {
log.error("Error processing request", e);
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
index 05bd274..7263ab7 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
@@ -62,6 +62,7 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter
private boolean traceEnabled;
private String httpMethodRestrict;
private UrlRewrite urlRewrite;
+ private Integer responseBufferSize;
public HttpEndpoint() {
}
@@ -350,4 +351,11 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter
this.urlRewrite = urlRewrite;
}
+ public Integer getResponseBufferSize() {
+ return responseBufferSize;
+ }
+
+ public void setResponseBufferSize(Integer responseBufferSize) {
+ this.responseBufferSize = responseBufferSize;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
index 280a5c1..056e135 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
@@ -121,15 +121,19 @@ public class CamelContinuationServlet extends CamelServlet {
exchange.getIn().setHeader(Exchange.HTTP_PATH,
httpPath.substring(contextPath.length()));
}
-
- log.trace("Suspending continuation of exchangeId: {}", exchange.getExchangeId());
+
+ if (log.isTraceEnabled()) {
+ log.trace("Suspending continuation of exchangeId: {}", exchange.getExchangeId());
+ }
continuation.setAttribute(EXCHANGE_ATTRIBUTE_ID, exchange.getExchangeId());
// must suspend before we process the exchange
continuation.suspend();
ClassLoader oldTccl = overrideTccl(exchange);
-
- log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
+
+ if (log.isTraceEnabled()) {
+ log.trace("Processing request for exchangeId: {}", exchange.getExchangeId());
+ }
// use the asynchronous API to process the exchange
consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
@@ -137,7 +141,9 @@ public class CamelContinuationServlet extends CamelServlet {
// check if the exchange id is already expired
boolean expired = expiredExchanges.remove(exchange.getExchangeId()) != null;
if (!expired) {
- log.trace("Resuming continuation of exchangeId: {}", exchange.getExchangeId());
+ if (log.isTraceEnabled()) {
+ log.trace("Resuming continuation of exchangeId: {}", exchange.getExchangeId());
+ }
// resume processing after both, sync and async callbacks
continuation.setAttribute(EXCHANGE_ATTRIBUTE_NAME, exchange);
continuation.resume();
@@ -157,8 +163,15 @@ public class CamelContinuationServlet extends CamelServlet {
}
try {
- log.trace("Resumed continuation and writing response for exchangeId: {}", result.getExchangeId());
// now lets output to the response
+ if (log.isTraceEnabled()) {
+ log.trace("Resumed continuation and writing response for exchangeId: {}", result.getExchangeId());
+ }
+ Integer bs = consumer.getEndpoint().getResponseBufferSize();
+ if (bs != null) {
+ log.trace("Using response buffer size: {}", bs);
+ response.setBufferSize(bs);
+ }
consumer.getBinding().writeResponse(result, response);
} catch (IOException e) {
log.error("Error processing request", e);
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index a091904..e679485 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -100,6 +100,7 @@ public class JettyHttpComponent extends HttpComponent {
protected Long continuationTimeout;
protected boolean useContinuation = true;
protected SSLContextParameters sslContextParameters;
+ protected Integer responseBufferSize;
class ConnectorRef {
Server server;
@@ -152,6 +153,7 @@ public class JettyHttpComponent extends HttpComponent {
SSLContextParameters ssl = sslContextParameters != null ? sslContextParameters : this.sslContextParameters;
String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class);
Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class);
+ Integer responseBufferSize = getAndRemoveParameter(parameters, "responseBufferSize", Integer.class, getResponseBufferSize());
// extract httpClient. parameters
Map<String, Object> httpClientParameters = IntrospectionSupport.extractProperties(parameters, "httpClient.");
@@ -245,6 +247,9 @@ public class JettyHttpComponent extends HttpComponent {
if (ssl != null) {
endpoint.setSslContextParameters(ssl);
}
+ if (responseBufferSize != null) {
+ endpoint.setResponseBufferSize(responseBufferSize);
+ }
setProperties(endpoint, parameters);
return endpoint;
@@ -825,6 +830,14 @@ public class JettyHttpComponent extends HttpComponent {
this.sslContextParameters = sslContextParameters;
}
+ public Integer getResponseBufferSize() {
+ return responseBufferSize;
+ }
+
+ public void setResponseBufferSize(Integer responseBufferSize) {
+ this.responseBufferSize = responseBufferSize;
+ }
+
// Implementation methods
// -------------------------------------------------------------------------
protected CamelServlet createServletForConnector(Server server, Connector connector,
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
index 09b484c..0116e7a 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
@@ -54,7 +54,6 @@ public class JettyHttpEndpoint extends HttpEndpoint {
private Boolean useContinuation;
private SSLContextParameters sslContextParameters;
private Map<String, Object> httpClientParameters;
-
public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL) throws URISyntaxException {
super(uri, component, httpURL);
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBufferSizeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBufferSizeTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBufferSizeTest.java
new file mode 100644
index 0000000..84baa2c
--- /dev/null
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyResponseBufferSizeTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.component.jetty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class JettyResponseBufferSizeTest extends BaseJettyTest {
+
+ @Test
+ public void testSimple() throws Exception {
+ String result = template.requestBody("http://localhost:{{port}}/myapp", "Camel", String.class);
+ assertEquals("Hello Camel", result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("jetty:http://localhost:{{port}}/myapp?responseBufferSize=65536")
+ .transform(body().prepend("Hello "));
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/42b564ea/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java
new file mode 100644
index 0000000..aa06352
--- /dev/null
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SimpleJettyTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.component.jetty;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class SimpleJettyTest extends BaseJettyTest {
+
+ @Test
+ public void testSimple() throws Exception {
+ String result = template.requestBody("http://localhost:{{port}}/myapp", "Camel", String.class);
+ assertEquals("Hello Camel", result);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("jetty:http://localhost:{{port}}/myapp")
+ .transform(body().prepend("Hello "));
+ }
+ };
+ }
+
+}