---
title: Sample code
description: In an account linking event, the user's browser is redirected to the configured Account Linking Service in the SP OpenToken Adapter instance. The application should capture the resumePath upon a GET request made to this URL with something similar to the following:
component: java
page_id: java:setup:pf_java_ik_sample_code
canonical_url: https://docs.pingidentity.com/integrations/java/setup/pf_java_ik_sample_code.html
revdate: June 21, 2024
---

# Sample code

In an account linking event, the user's browser is redirected to the configured Account Linking Service in the SP OpenToken Adapter instance. The application should capture the resumePath upon a `GET` request made to this URL with something similar to the following:

```
String username = (String)request.getSession().getAttribute("username");
Map<String, String> userInfo = new HashMap<String, String>();
userInfo.put(Agent.TOKEN_SUBJECT, username);
String returnUrl = "https://<{pingfed} DNS>:9031" + request.getParameter("resume");
. . . .
try {
   UrlHelper urlHelper = new UrlHelper(returnUrl);
   //see "Using the Agent API" section for sample code
   //that instantiates and configures an Agent instance
   agent.writeToken(userInfo,response,urlHelper,false);
   returnUrl = (String)urlHelper.toString();
}
catch(TokenException e) {
   // Handle exception
}
response.sendRedirect(returnUrl);
```
