Search code examples
javaapache-camelnettyhttp-proxy

Making "external" calls through proxy using Apache Camel's Netty4 HTTP component


We use the Apache Camel's Netty4 HTTP Component for almost everything on the artifact I have a problem with right now.

The issue is that, a proxy is now required to make external/outbound calls to the Internet...and eventually this is not working. All the calls are getting blocked/rejected — and just for the record, we had the same issue in a different artifact and we were able to circumvent it by using the JVM proxy settings, but this one is using the Async Http Client.

I've tried setting the proxy at the JVM level by using http.proxyHost, http.proxyPort, etc., but it didn't work this time.

Question(s): Is there a way to configure any proxy settings within this component? I've been digging inside org.apache.camel.component.netty4.http.NettyHttpConfiguration to see if there are any relevant settings I can change/use — I'm not completely sure what HTTP client it's used behind scenes and I'm guessing it might be Netty O:)


If relevant, (one of) our routes looks like:

@Component
public final class Route extends AbstractRouteBuilder {
  @Override
  public void configure() throws Exception {
    super.configure();

    from("{{route.inbound.reports}}") // netty4-http:https://hostname.tld/api/v1/reports
      .choice()
      .when(header(Exchange.HTTP_METHOD).isEqualToIgnoreCase(HttpMethod.GET))
        .toD("seda:get")
        .choice()
        .when(AbstractHelper::isOk)
          .setProperty("source", constant("user"))
          .to("seda:retrieve?timeout={{async.timeout:4500}}")
          .setBody(simple("${property.results}"))
          .marshal().json(JsonLibrary.Jackson)
          .end()
        .endChoice()
      .otherwise()
        .toD("{{route.artifact.reports}}");

    from("seda:get")
      .toD("{{route.artifact.reports}}")
      .unmarshal().json(JsonLibrary.Jackson)
      .to(exec("analyze"));

    from("seda:retrieve")
      .filter(PredicateBuilder.and(header(Key.ACCOUNT_ID).isNotNull()))
      .setHeader(Exchange.HTTP_METHOD, constant(HttpMethod.GET))
      .setHeader(Header.API_KEY, simple("{{vendor.api-key}}"))
      .toD("{{route.outbound.reports}}") // netty4-http:https://external-hostname.tld/api/client/reports
      .unmarshal().json(JsonLibrary.Jackson)
      .choice()
      .when(AbstractHelper::isOk)
        .to(exec("aggregate"))
      .otherwise()
        .to(exec("handleFailure"))
      .end();
  }

  // ...
}

Solution

  • I guess there is no way around this one...or at least, not something I could find within the allowed timeframe.

    We ended-up using a different component for all external/outbound calls (that obey the proxy rules); specifically: