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/02/19 20:46:40 UTC
svn commit: r1447882 - in /camel/trunk/components/camel-netty/src:
main/java/org/apache/camel/component/netty/NettyEndpoint.java
test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java
Author: davsclaus
Date: Tue Feb 19 19:46:40 2013
New Revision: 1447882
URL: http://svn.apache.org/r1447882
Log:
Added test based on user forum issue
Added:
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java?rev=1447882&r1=1447881&r2=1447882&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java Tue Feb 19 19:46:40 2013
@@ -85,6 +85,12 @@ public class NettyEndpoint extends Defau
}
@Override
+ protected String createEndpointUri() {
+ ObjectHelper.notNull(configuration, "configuration");
+ return "netty:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort();
+ }
+
+ @Override
protected void doStart() throws Exception {
ObjectHelper.notNull(timer, "timer");
}
Added: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java?rev=1447882&view=auto
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java (added)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyManualEndpointTest.java Tue Feb 19 19:46:40 2013
@@ -0,0 +1,79 @@
+/**
+ * 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.netty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.handler.codec.frame.Delimiters;
+import org.jboss.netty.util.CharsetUtil;
+import org.junit.Test;
+
+public class NettyManualEndpointTest extends BaseNettyTest {
+
+ private NettyEndpoint endpoint;
+
+ @Test
+ public void testNettyManaul() throws Exception {
+ assertNotNull(endpoint);
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody(endpoint, "Hello World\n");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals("netty:tcp://localhost:" + getPort(), endpoint.getEndpointUri());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ NettyConfiguration nettyConfig = new NettyConfiguration();
+ nettyConfig.setProtocol("tcp");
+ nettyConfig.setHost("localhost");
+ nettyConfig.setPort(getPort());
+ nettyConfig.setSync(false);
+
+ // need to add encoders and decoders manually
+ nettyConfig.setEncoder(ChannelHandlerFactories.newStringEncoder(CharsetUtil.UTF_8));
+ List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
+ decoders.add(ChannelHandlerFactories.newDelimiterBasedFrameDecoder(1000, Delimiters.lineDelimiter()));
+ decoders.add(ChannelHandlerFactories.newStringDecoder(CharsetUtil.UTF_8));
+ nettyConfig.setDecoders(decoders);
+
+ // create and start component
+ NettyComponent component = new NettyComponent(getContext());
+ component.setConfiguration(nettyConfig);
+ getContext().addComponent("netty", component);
+ component.start();
+
+ // create and start endpoint, pass in null as endpoint uri
+ // as we create this endpoint manually
+ endpoint = new NettyEndpoint(null, component, nettyConfig);
+ endpoint.setTimer(NettyComponent.getTimer());
+ endpoint.start();
+
+ from(endpoint).to("mock:result");
+ }
+ };
+ }
+}