JMeter : How to set a Cookie using Beanshell

Here is a Beanshell script that will add a cookie to the cookies sent in every HTTP request.

import org.apache.jmeter.protocol.http.control.Cookie;

// Retrieve the cookie value from a JMeter variable called "myCookieValue"
String cookieValue = vars.get("myCookieValue");

// Create a new Cookie and add it to the cookie manager
Cookie cookie = new Cookie("cookieName", cookieValue , "localhost", "/", false, -1);
ctx.getCurrentSampler().getCookieManager().add(cookie); 

log.info("Cookie added: "+cookie);

NB: Please remind to add a ´HTTP Cookie Manager´ to your thread group.

How to configure Log4j 2 with a properties file

You may want to migrate from Log4j 1.x to Log4j 2, for example because of performance improvements.

But, you don’t want to rewrite all your Log4j 1.x properties file, to use them for Log4j2, you have to slightly change them.

Here is an example of Log4j 2 configuration using properties. It defines two appenders: a console appender and a rolling file appender. (You can find a full working example in my Github repo)

# Declare loggers
name=LoggingConfig
appenders=a_console, a_rolling
rootLogger.level=info
rootLogger.appenderRefs=ar_console,ar_rolling
rootLogger.appenderRef.ar_console.ref=StdoutAppender
rootLogger.appenderRef.ar_rolling.ref=DailyRollingAppender

# Console logger
appender.a_console.type=Console
appender.a_console.name=StdoutAppender
appender.a_console.layout.type=PatternLayout
appender.a_console.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

# File logger
appender.a_rolling.type=RollingFile
appender.a_rolling.name=DailyRollingAppender
appender.a_rolling.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

appender.a_rolling.fileName=log4j2-sample.log
appender.a_rolling.filePattern=log4j2-sample-%d{yyyy-MM-dd}.log

appender.a_rolling.layout.type=PatternLayout
appender.a_rolling.policies.type=Policies
appender.a_rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.a_rolling.policies.time.interval=1

Don’t hesitate to send me a message if you have any issue/question.

Eclipse does not lookup to the right code version while debugging

If you debug some code on a project where you have multiple versions in your workspace, eclipse may lookup for the wrong class.

To tell eclipse which project to search for, go to:

  • Run > Debug Configurations...
  • Click on your debug configuration
  • Go to Source tab
  • In Source Lookup Path panel:
    • remove Workspace entry
    • add the version of your project you want eclipse to search for

How to use Google Slides as a OneNote alternative

OneNote is my favorite software for taking notes, I use it everyday for taking & organizing notes, sometimes sharing them to friends/colleagues.

Unfortunately https://www.onenote.com/ is blocked at my office. I can still use the desktop version but I can’t synchronize my notebooks and I’m not able to share them.

Continue reading