Ruben Rodrigues created ARTEMIS-4140:
----------------------------------------
Summary: HTTP Transport - Wrong authority-name 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
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 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)