Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 64962 invoked from network); 3 Sep 2009 06:42:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Sep 2009 06:42:45 -0000 Received: (qmail 98282 invoked by uid 500); 3 Sep 2009 06:42:45 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 98230 invoked by uid 500); 3 Sep 2009 06:42:45 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 98221 invoked by uid 99); 3 Sep 2009 06:42:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 06:42:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 06:42:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 21F0E23888D6; Thu, 3 Sep 2009 06:42:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810785 - in /camel/trunk/components/camel-mina/src: main/java/org/apache/camel/component/mina/ test/java/org/apache/camel/component/mina/ Date: Thu, 03 Sep 2009 06:42:22 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090903064223.21F0E23888D6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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