Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static Server createServer(AvroConfiguration configuration, CamelContext
if (AVRO_HTTP_TRANSPORT.equalsIgnoreCase(configuration.getTransport().name())) {
AvroRpcHttpServerFactory factory = ResolverHelper.resolveMandatoryService(camelContext,
"avro-rpc-http-server-factory", AvroRpcHttpServerFactory.class, "camel-avro-rpc");
return factory.create(responder, configuration.getPort());
return factory.create(responder, configuration.getHost(), configuration.getPort());
} else if (AVRO_NETTY_TRANSPORT.equalsIgnoreCase(configuration.getTransport().name())) {
return new NettyServer(responder, new InetSocketAddress(configuration.getHost(), configuration.getPort()));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.avro;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* The http consumer listens on the host of the endpoint, as the netty consumer does.
*/
public class AvroHttpConsumerHostTest extends AvroTestSupport {

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
from("avro:http:127.0.0.1:" + avroPort
+ "/getName?protocolClassName=org.apache.camel.avro.test.TestReflection")
.setBody(constant("Camel"));
}
};
}

@Test
public void testListensOnConfiguredHostOnly() {
assertDoesNotThrow(() -> connect("127.0.0.1"));
assertThrows(IOException.class, () -> connect("127.0.0.2"));
}

private void connect(String host) throws IOException {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(host, avroPort), 2000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ public class JettyHttpServerFactory implements AvroRpcHttpServerFactory {
public Server create(SpecificResponder responder, int port) throws IOException {
return new HttpServer(responder, port);
}

@Override
public Server create(SpecificResponder responder, String host, int port) throws IOException {
return new HttpServer(responder, host, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,24 @@
*/
public interface AvroRpcHttpServerFactory {

/**
* Creates a server that listens on the given port on all interfaces.
*/
Server create(SpecificResponder responder, int port) throws Exception;

/**
* Creates a server that listens on the given host and port.
*
* The default implementation ignores the host and calls {@link #create(SpecificResponder, int)}, so an
* implementation should override it to listen on the host the endpoint is configured with.
*
* @param responder the responder
* @param host the host or address to listen on
* @param port the port to listen on
* @return the server
* @since 4.24
*/
default Server create(SpecificResponder responder, String host, int port) throws Exception {
return create(responder, port);
}
}
Loading