Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – LambdaTest – NPI EA (cat=Testing)
announcement - icon

Browser testing is essential if you have a website or web applications that users interact with. Manual testing can be very helpful to an extent, but given the multiple browsers available, not to mention versions and operating system, testing everything manually becomes time-consuming and repetitive.

To help automate this process, Selenium is a popular choice for developers, as an open-source tool with a large and active community. What's more, we can further scale our automation testing by running on theLambdaTest cloud-based testing platform.

Read more through our step-by-step tutorial on how to set up Selenium tests with Java and run them on LambdaTest:

>> Automated Browser Testing With Selenium

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Partner – LambdaTest – NPI (cat= Testing)
announcement - icon

Browser testing is essential if you have a website or web applications that users interact with. Manual testing can be very helpful to an extent, but given the multiple browsers available, not to mention versions and operating system, testing everything manually becomes time-consuming and repetitive.

To help automate this process, Selenium is a popular choice for developers, as an open-source tool with a large and active community. What's more, we can further scale our automation testing by running on the LambdaTest cloud-based testing platform.

Read more through our step-by-step tutorial on how to set up Selenium tests with Java and run them on LambdaTest:

>> Automated Browser Testing With Selenium

1. Introduction

In this tutorial, we’ll learn how JMeter manages sessions and cookies, set up a test plan that logs in to an application, accesses protected resources, and logs out. Along the way, we’ll use HTTP Cookie Manager, CSV Data Set Config, and response assertions to ensure our tests simulate real-world user behavior.

2. Session Management in Web Applications

In web applications, session and cookie management come in many forms and are critical in authentication and user experience.

Let’s consider an application using form login. This type of authentication allows us to send a single authentication request that returns a cookie with the JSESSIONID when successful, which we can include in future requests. This eliminates the need to include credentials in every request.

2.1. How JMeter Handles Sessions and Cookies

Unlike browsers, JMeter requires explicit configuration to maintain state across requests. The specific components we’ll need are the HTTP Cookie Manager and the HTTP Header Manager.

3. Configure the JMeter Test Plan

We’ll use these components to create a test plan to log in to an application, access a protected resource, and log out.

In the end, we’ll have this structure:

test plan

3.1. Create a Thread Group

To start, we’ll need a Thread Group, which controls how many users and iterations we’ll use in our test.

Let’s right-click on Test Plan, then Add > Threads (Users) > Thread Group and modify a few properties:

thread group
  • Stop Thread: Since we need to log in to access the application, we also want the test to stop on the first error. This option helps generate fewer requests if the login fails for any reason.
  • Number of Threads: 3. This parameter helps test whether the application handles more than a couple of sessions simultaneously. Since we need valid credentials for each user, we can’t exceed the number of users in our database, which we’ll configure later.
  • Loop Count: 2. Using any number greater than one helps verify that our application handles returning users
  • Same user on each iteration: This option controls whether each user maintains its identity across multiple iterations of the test plan. If unchecked, cookies aren’t retained at the start of the next iteration. Since our plan starts with a login and ends with a logout, the value of this option isn’t relevant.

We can leave the other options with default values since they’re unrelated to session management.

3.2. Use a CSV File to Load Users

Since we’re running tests with multiple users, the most effective and secure way to load them is by including them in a CSV file.

Let’s create a file named users.csv and include three users, using the first line as the header:

username,password
alex_foo,password123
jane_bar,password213
john_baz,password321

Then, we’ll right-click our Thread Group, select Add > Config Element > CSV Data Set Config:

csv db

In this component, the only property we won’t leave with default values is Filename, which we’ll use to select our CSV file. Other notable options are:

  • Variable Names: This overrides the default behavior of using the column names in the first line of the file as variable names. In conjunction with “Ignore first line“, this is useful if we want different variable names.
  • Recycle on EOF: Each new thread picks the next line in the file. If this option is false, the values will return “EOF” for the next user, when the lines are exhausted. Otherwise, it loops back to the beginning of the file.

The variables defined here become usable almost anywhere we can input a value for the request and assertion elements we’ll use later.

Finally, we’ll add another Config Element, and then choose the HTTP Cookie Manager. This component enables session management in JMeter:

cookie manager
  • Clear cookies each iteration: This has the same effect as the “Same user on each iteration” option and is thus unavailable when we check the next option.
  • Use Thread Group configuration to control cookie clearing: As the name suggests, this considers the “Same user on each iteration” we defined earlier.

4. Create the Login Request

Our first request is for the login form. Let’s right-click our Thread Group, then select Add > Sampler > HTTP Request:

login request

Let’s check out the most relevant configuration bits for our scenario:

  • Protocol: We only need to change it if our application uses HTTPS
  • Server Name or IP: Should point to our server address
  • Method: Our application uses the HTTP POST method for the login page
  • Path: /login. This path is our login endpoint
  • Follow Redirects: We should only check this when the login redirects to a page where we want to make test assertions. Otherwise, we should leave it unchecked to boost performance

Finally, Body Data is a query string where we define the user credentials. Since we’re using the CSV file component, we can reference the variables for the current cursor here. Also, we’re using the default parameter names for a Spring Security login form:

username=${username}&password=${password}

4.1. Include an HTTP Header Manager

We need to define the Content-Type header as application/x-www-form-urlencoded for our login request. To do this, we’ll right-click our login request, then select Add > Config Element > HTTP Header Manager and include it as a name/value pair:

header manager

If we don’t include it, our login will fail, as the server won’t know how to handle the request.

4.2. Assert Request Redirected After Login

When a login request is successful, it returns a 302 code, redirecting to the landing page in the application. To assert this, we can right-click our login request, then select Add > Assertions > Response Assertion:

assert redirected

Here, we’re using a combination of the “Response Code” and “Equals” options, inputting the 302 code in the “Patterns to Test” field. We’ll leave other options with default values.

4.3. Assert There’s No Login Error

If login fails, the response contains a Location header pointing to the error page. Let’s add another Response Assertion:

test login error
  • Response Headers: This defines that we want to check the value in one of the response headers. We don’t need to set the header name.
  • Contains + Not: The header value shouldn’t contain the string specified in the Patterns to Test field.
  • Patterns to Test: The Location header contains the word “error” and is matched here.
  • Custom failure message: We can also reference the current username variable here, generating a more descriptive JMeter error message.

5. Accessing Protected Resources

With the cookie manager in place, all subsequent requests automatically include session cookies, granting access to protected resources:

protected request

Then, we’ll check if the response matches the expected value. In our case, the secured endpoint Path we specified returns the currently logged-in user’s name. We’ll leave other options with default values.

So, let’s include the username variable in a new Response Assertion, in the Patterns to Test field:

assert user resource
  • Text Response: We’ll check the response as plain text
  • Matches: We want an exact match

6. Create the Logout Request

At the end of the iteration, we’ll add a logout request pointing to the logout endpoint:

logout

And an assertion to check that we logged out successfully, using a similar logic to the login assertion, where we check if one of the headers contains “logout“:

logout assert

Now we have a complete test cycle of authenticated users interacting with the application concurrently.

7. Explore the Requests

To visualize what’s happening under the hood, we’ll right-click our Thread Group, then Add > Listener > View Results Tree. After running our tests and inspecting a login request, we can see the JSESSIONID when clicking Response data > Response headers:

results

We can also see that the cookie is sent back in our request to a protected resource when clicking Request > Request Body:

request result

Lastly, we can verify the expected response under Response Data > Response Body:

results response

8. Conclusion

In this article, we explored how JMeter handles session and cookie management, enabling us to simulate real-world authentication scenarios. We configured a test plan that logs in, accesses protected resources, and logs out, ensuring our application correctly maintains and invalidates user sessions.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)