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 2009/09/03 08:42:22 UTC
svn commit: r810785 - in /camel/trunk/components/camel-mina/src:
main/java/org/apache/camel/component/mina/
test/java/org/apache/camel/component/mina/
Author: davsclaus
Date: Thu Sep 3 06:42:22 2009
New Revision: 810785
URL: http://svn.apache.org/viewvc?rev=810785&view=rev
Log:
CAMEL-1939: Applied patch with thanks to Stan Lewis. Camel Mina now supports setting encoder/decoder textline max lengths for the textline protocol.
Added:
camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java (with props)
Modified:
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/TextLineCodecFactory.java
Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?rev=810785&r1=810784&r2=810785&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java (original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java Thu Sep 3 06:42:22 2009
@@ -210,12 +210,21 @@
if (configuration.isTextline()) {
Charset charset = getEncodingParameter(type, configuration);
LineDelimiter delimiter = getLineDelimiterParameter(configuration.getTextlineDelimiter());
- codecFactory = new TextLineCodecFactory(charset, delimiter);
+ TextLineCodecFactory tmpCodecFactory = new TextLineCodecFactory(charset, delimiter);
+ if (configuration.getEncoderMaxLineLength() > 0) {
+ tmpCodecFactory.setEncoderMaxLineLength(configuration.getEncoderMaxLineLength());
+ }
+ if (configuration.getDecoderMaxLineLength() > 0) {
+ tmpCodecFactory.setDecoderMaxLineLength(configuration.getDecoderMaxLineLength());
+ }
if (LOG.isDebugEnabled()) {
LOG.debug(type + ": Using TextLineCodecFactory: " + codecFactory + " using encoding: "
- + charset + " and line delimiter: " + configuration.getTextlineDelimiter()
+ + charset + " line delimiter: " + configuration.getTextlineDelimiter()
+ "(" + delimiter + ")");
+ LOG.debug("Encoder maximum line length: " + tmpCodecFactory.getEncoderMaxLineLength()
+ + "Decoder maximum line length: " + tmpCodecFactory.getDecoderMaxLineLength());
}
+ codecFactory = tmpCodecFactory;
} else {
codecFactory = new ObjectSerializationCodecFactory();
if (LOG.isDebugEnabled()) {
Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java?rev=810785&r1=810784&r2=810785&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java (original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java Thu Sep 3 06:42:22 2009
@@ -39,6 +39,8 @@
private boolean lazySessionCreation = true;
private boolean transferExchange;
private boolean minaLogger;
+ private int encoderMaxLineLength = -1;
+ private int decoderMaxLineLength = -1;
private List<IoFilter> filters;
/**
@@ -152,6 +154,22 @@
this.transferExchange = transferExchange;
}
+ public void setEncoderMaxLineLength(int encoderMaxLineLength) {
+ this.encoderMaxLineLength = encoderMaxLineLength;
+ }
+
+ public int getEncoderMaxLineLength() {
+ return encoderMaxLineLength;
+ }
+
+ public void setDecoderMaxLineLength(int decoderMaxLineLength) {
+ this.decoderMaxLineLength = decoderMaxLineLength;
+ }
+
+ public int getDecoderMaxLineLength() {
+ return decoderMaxLineLength;
+ }
+
public boolean isMinaLogger() {
return minaLogger;
}
Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/TextLineCodecFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/TextLineCodecFactory.java?rev=810785&r1=810784&r2=810785&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/TextLineCodecFactory.java (original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/TextLineCodecFactory.java Thu Sep 3 06:42:22 2009
@@ -32,8 +32,8 @@
*/
public class TextLineCodecFactory implements ProtocolCodecFactory {
- private ProtocolEncoder encoder;
- private ProtocolDecoder decoder;
+ private TextLineEncoder encoder;
+ private TextLineDecoder decoder;
public TextLineCodecFactory(Charset charset, LineDelimiter delimiter) {
if (delimiter.equals(LineDelimiter.AUTO)) {
@@ -53,4 +53,20 @@
return decoder;
}
+ public void setEncoderMaxLineLength(int encoderMaxLineLength) {
+ encoder.setMaxLineLength(encoderMaxLineLength);
+ }
+
+ public int getEncoderMaxLineLength() {
+ return encoder.getMaxLineLength();
+ }
+
+ public void setDecoderMaxLineLength(int decoderMaxLineLength) {
+ decoder.setMaxLineLength(decoderMaxLineLength);
+ }
+
+ public int getDecoderMaxLineLength() {
+ return decoder.getMaxLineLength();
+ }
+
}
Added: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java?rev=810785&view=auto
==============================================================================
--- camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java (added)
+++ camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java Thu Sep 3 06:42:22 2009
@@ -0,0 +1,67 @@
+/**
+ * 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.mina;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MinaMaxLineLengthTest extends ContextTestSupport {
+
+ public void testSendToServer() {
+ String request = "";
+ for (int c = 0; c < 4000; c++) {
+ request += "A";
+ }
+
+ // START SNIPPET: e3
+ String out = (String) template.requestBody("mina:tcp://localhost:5555?sync=true&textline=true&encoderMaxLineLength=5000&decoderMaxLineLength=5000", request);
+ assertEquals(request, out);
+ // END SNIPPET: e3
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ // lets setup a server on port 5555
+ // we set the sync option so we will send a reply
+ // and we let the request-reply be processed in the MyServerProcessor
+ from("mina:tcp://localhost:5555?sync=true&textline=true&encoderMaxLineLength=5000&decoderMaxLineLength=5000").process(new MyServerProcessor());
+ // END SNIPPET: e1
+ }
+ };
+ }
+
+ // START SNIPPET: e2
+ private class MyServerProcessor implements Processor {
+ public void process(Exchange exchange) throws Exception {
+ // get the input from the IN body
+ String request = exchange.getIn().getBody(String.class);
+ // echo back the response on the OUT body
+ exchange.getOut().setBody(request);
+ }
+ }
+ // END SNIPPET: e2
+
+}
Propchange: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMaxLineLengthTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date