[ https://issues.apache.org/jira/browse/ARTEMIS-4140?focusedWorklogId=971168&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-971168 ]
ASF GitHub Bot logged work on ARTEMIS-4140: ------------------------------------------- Author: ASF GitHub Bot Created on: 29/May/25 17:49 Start Date: 29/May/25 17:49 Worklog Time Spent: 10m Work Description: tabish121 commented on code in PR #5707: URL: https://github.com/apache/activemq-artemis/pull/5707#discussion_r2114461357 ########## tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/http/HttpAuthorityTest.java: ########## @@ -0,0 +1,97 @@ +/* + * 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.activemq.artemis.tests.integration.http; + +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpServerCodec; +import org.apache.activemq.artemis.api.core.client.ActiveMQClient; +import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; +import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class HttpAuthorityTest extends ActiveMQTestBase { + + @Test + public void testHttpAuthority() throws Exception { + int port = 61616; + CountDownLatch requestTested = new CountDownLatch(1); + AtomicBoolean failed = new AtomicBoolean(false); + EventLoopGroup bossGroup = new NioEventLoopGroup(); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + try { + ServerBootstrap bootstrap = new ServerBootstrap(); + bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { + @Override + public void initChannel(SocketChannel ch) { + ch.pipeline().addLast(new HttpServerCodec()); + ch.pipeline().addLast(new HttpObjectAggregator(1024 * 1024)); + ch.pipeline().addLast(new SimpleChannelInboundHandler<FullHttpRequest>() { + @Override + protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) { + if (failed.get()) { + return; + } + + try { + failed.set(!new URI(req.uri()).getAuthority().equals(req.headers().get("host"))); + } catch (Exception e) { + failed.set(true); + } + requestTested.countDown(); + + ctx.writeAndFlush(new DefaultFullHttpResponse(req.protocolVersion(), HttpResponseStatus.OK)); + } + }); + } + }); + ChannelFuture future = bootstrap.bind(port).sync(); + + try { + ServerLocator locator = ActiveMQClient.createServerLocator("tcp://127.0.0.1:61616?httpEnabled=true;callTimeout=250"); Review Comment: Should this be using a try with resources to ensure the locator is closed cleanly ? Issue Time Tracking ------------------- Worklog Id: (was: 971168) Time Spent: 40m (was: 0.5h) > HTTP Transport - Wrong authority compoment in HTTP request causes 400 Bad > Request > --------------------------------------------------------------------------------- > > Key: ARTEMIS-4140 > URL: https://issues.apache.org/jira/browse/ARTEMIS-4140 > Project: ActiveMQ Artemis > Issue Type: Bug > Components: JMS > Affects Versions: 2.21.0 > Environment: ActiveMQ Artemis 2.21 > JMS Client 2.21.0.redhat-00041 from maven.repository.redhat.com. I don't know > which upstream version it matches. > Consumer/Producer is on a VM, HAProxy is the ingress controller of an > OpenShift (Kubernetes) cluster and the broker is hosted as a container on the > OpenShift platform. > Reporter: Ruben Rodrigues > Assignee: Justin Bertram > Priority: Minor > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > Hello everyone, > I was trying to connect to an AMQ Artemis Broker using the following java > code example given in the github repository : > [https://github.com/apache/activemq-artemis/tree/main/examples/features/standard/http-transport] > Here, the broker is exposed over HTTP behind an HAProxy. When I try to make > the client connect to the broker, I keep having a timeout error, stating that > the client can't actually connect to the broker. > {code:java} > Exception in thread "main" javax.jms.JMSException: Failed to create session > factory > at > org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:867) > at > org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:284) > at > org.apache.activemq.artemis.jms.example.HttpTransportExample.main(HttpTransportExample.java:47) > Caused by: ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT > message=AMQ219013: Timed out waiting to receive cluster topology. Group:null] > at > org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:743) > at > org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:865) > ... 2 more {code} > So I digged an little and found that when the client tries to connect to the > broker, it sends the following HTTP request : > {code:java} > POST > http://broker-2-http-0-svc-rte-dc2.company.com:80/messaging/ActiveMQServlet > HTTP/1.1 > host: broker-2-http-0-svc-rte-dc2.company.com > content-length: 21 {code} > The HAProxy answers with a 400 Bad Request error because this request does > not comply with the RFC 7230 section 5.4, which states that : > {code:java} > If the target URI includes an authority component, then a client MUST send a > field-value for Host that is identical to that authority component {code} > The authority component being the "<hostname>:<port>" string. RFC 7230 > section 2.7.1 : > {code:java} > http-URI = "http:" "//" authority path-abempty [ "?" query ] > [ "#" fragment ] {code} > There is 3 solutions to resolve this : > - Remove the "<hostname>:<port>" part of the request and keep it in the Host > header > {code:java} > POST /messaging/ActiveMQServlet HTTP/1.1 > host: broker-2-http-0-svc-rte-dc2.company.com > content-length: 21 {code} > - Remove the port in the request to match the host header > {code:java} > POST http://broker-2-http-0-svc-rte-dc2.company.com/messaging/ActiveMQServlet > HTTP/1.1 > host: broker-2-http-0-svc-rte-dc2.company.com > content-length: 21 {code} > - Add the port in the Host header > {code:java} > POST > http://broker-2-http-0-svc-rte-dc2.company.com:80/messaging/ActiveMQServlet > HTTP/1.1 > host: broker-2-http-0-svc-rte-dc2.company.com:80 > content-length: 21 {code} > > I honestly don't know which solution is the best. > Hope this will be fixed soon, > Thanks everyone -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@activemq.apache.org For additional commands, e-mail: issues-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact