You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Justin Bertram (Jira)" <ji...@apache.org> on 2023/01/24 04:07:00 UTC

[jira] [Comment Edited] (ARTEMIS-4140) HTTP Transport - Wrong authority compoment in HTTP request causes 400 Bad Request

    [ https://issues.apache.org/jira/browse/ARTEMIS-4140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17680080#comment-17680080 ] 

Justin Bertram edited comment on ARTEMIS-4140 at 1/24/23 4:06 AM:
------------------------------------------------------------------

I think the safest thing would be to always include the port in the {{host}} header since the specification requires it when its a non-standard value (i.e. not {{80}} or {{443}}). This should be a relatively straight-forward change [here|https://github.com/apache/activemq-artemis/blob/main/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java#L1172], e.g.:
{code:java}
httpRequest.headers().add(HttpHeaderNames.HOST, String.format("%s:%d", host, port));{code}
The only difficulty I see is with providing a proper test to verify the fix and mitigate any future regressions.

Would you care to submit a PR?


was (Author: jbertram):
I think the safest thing would be to always include the port in the {{host}} header since the specification requires it when its a non-standard value (i.e. not {{80}} or {{443}}). This should be a relatively straight-forward change [here|https://github.com/apache/activemq-artemis/blob/main/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector.java#L1172]. The only difficulty I see is with providing a proper test to verify the fix and mitigate any future regressions.

Would you care to submit a PR?

> 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
>            Priority: Minor
>
> 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)