How do I set up a Proxy with the Java version of Gatling

I am new to Gatling. Cannot figure out how to set up the HttpProtocolBuilder in Java to use a proxy. Can someone point me at an example?

**Gatling version 3.14.3 **:
Gatling flavor: [ X] java kotlin scala javascript typescript
Gatling build tool: [X ] maven gradle sbt bundle npm

Please explain exactly what you’re doing and the problem you’re facing.

I am trying to run the demo, however the work machine I am using requires a proxy to reach the internet. When I run the demo script I get j.n.c.ClosedChannelException

OK, so now we have the problem you’re facing but we’re still lacking what you’re doing exactly :grinning_face:

Please share your protocol configuration.

Thanks for looking into this!

I’d also be OK with using the scala version to get started. All of the documentation I found online for Gatling regarding proxy seems to be for the Scala DSL.

However, I don’t see any samples for Scala in the gatling-charts-highcharts-bundle-3.14.3 zip. Is there a different scala bundle I need to download to try that out?

Also, I started looking at a tutorial on Gatling Scala that used version 3.8. Is there a download location to obtain older versions, if I want to use the exact version used in the training material?

My configuration is the generic one that comes within the zip file BasicSimulation.java. Based on my research I tried to add a proxy but was unable to get it to compile.

// Define HTTP configuration
private static final HttpProtocolBuilder httpProtocol = http.baseUrl(“https://api-ecomm.gatling.io”)
.acceptHeader(“application/json”)
.userAgentHeader( “Mozilla/5.0 …”)
// .proxy(httpProxy(“10.1.32.228”, 8080)); // httpProxy symbol not found
.proxy(new Proxy(“10.1.32.228”, 8080, 8080, null)); // also does not compile

Hi,

All of the documentation I found online for Gatling regarding proxy seems to be for the Scala DSL.

Which documentation are you searching?
Our official documentation has samples for Java, JavaScript, Kotlin and Scala.
cf Gatling HTTP protocol reference - protocol configuration

However, I don’t see any samples for Scala in the gatling-charts-highcharts-bundle-3.14.3 zip. Is there a different scala bundle I need to download to try that out?

No, there isn’t. We now only provide a beginner-friendly standalone bundle for Java. Scala is not beginner friendly. If you really want to go with Scala (which we don’t recommend unless you are a Scala developper), you can check our different demo projects for the different build tools, eg Maven Plugin for Gatling and Gatling Enterprise.

Also, I started looking at a tutorial on Gatling Scala

You seem to be trying to use outdated material from a third-party source.
I recommend you check our official tutorials: How to get started with Gatling

that used version 3.8.

Sorry, but we can’t help with outdated versions. 3.8 was from 3 years ago.
Please use the latest Gatling 3.14.3.

Based on my research I tried to add a proxy but was unable to get it to compile.

You have the correct syntax on our documentation page I linked above (for Gatling 3.13.4).

Regards

Thanks for your support and the additional context and guidance. This code worked :slight_smile:

private static final HttpProtocolBuilder httpProtocol = http.baseUrl(“https://api-ecomm.gatling.io”)
.acceptHeader(“application/json”)
.userAgentHeader(
“Mozilla…”)
.proxy( Proxy(“10.1.32.228”, 8080));

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.