Asynchronous Requests (Java)
Last update: July 17, 2023
- Topics:
- APIs/SDKs
CREATED FOR:
- Developer
Description
One benefit of server-side integration is that you can leverage the huge bandwidth and computing resources available on the server-side by using parallelism. Target Java SDK supports asynchronous requests, which can reduce the effective target time to zero.
Supported Methods
Methods
CompletableFuture<TargetDeliveryResponse> getOffersAsync(TargetDeliveryRequest request);
CompletableFuture<ResponseStatus> sendNotificationsAsync(TargetDeliveryRequest request);
CompletableFuture<Attributes> getAttributesAsync(TargetDeliveryRequest targetRequest, String ...mboxes);
Example
A sample Spring
application Controller could look like this:
Sample Controller
@RestController
public class TargetRestController {
@Autowired
private TargetClient targetJavaClient;
@GetMapping("/mboxTargetOnlyAsync")
public TargetDeliveryResponse mboxTargetOnlyAsync(
@RequestParam(name = "mbox", defaultValue = "server-side-mbox") String mbox,
HttpServletRequest request, HttpServletResponse response) {
ExecuteRequest executeRequest = new ExecuteRequest()
.mboxes(getMboxRequests(mbox));
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
.context(getContext(request))
.execute(executeRequest)
.cookies(getTargetCookies(request.getCookies()))
.build();
CompletableFuture<TargetDeliveryResponse> targetResponseAsync =
targetJavaClient.getOffersAsync(targetDeliveryRequest);
targetResponseAsync.thenAccept(tr -> setCookies(tr.getCookies(), response));
simulateIO();
TargetDeliveryResponse targetResponse = targetResponseAsync.join();
return targetResponse;
}
/**
* Function for simulating network calls like other microservices and database calls
*/
private void simulateIO() {
try {
Thread.sleep(200L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
This example assumes you have initialized the SDK as a spring bean and that you have utility methods available.
The Target request is fired before simulateIO
and by the time it is executed target result should also be ready. Even if it is not, you will have significant savings in most cases.
Previous pageLogger (Java)
Next pageProxy Configuration (Java)
Target
- Adobe Target Developer Guide
- Getting started
- Before you implement
- Privacy and security
- Privacy overview
- Privacy and data protection regulations
- Target cookies
- Delete the Target cookie
- The impact of third-party cookie deprecation on Target (at.js)
- Google Chrome SameSite cookie policies
- Apple Intelligent Tracking Prevention (ITP) 2.x
- Content Security Policy (CSP) directives
- Allowlist Target edge nodes
- Methods to get data into Target
- Target security overview
- Supported browsers
- TLS (Transport Layer Security) encryption changes
- CNAME and Adobe Target
- Client-side implementation
- Overview: implement Target for client-side web
- Adobe Experience Platform Web SDK implementation overview
- at.js implementation
- at.js overview
- How at.js works
- How to deploy at.js
- On-device decisioning
- at.js functions
- at.js functions overview
- adobe.target.getOffer()
- adobe.target.getOffers() - at.js 2.x
- adobe.target.applyOffer()
- adobe.target.applyOffers() - at.js 2.x
- adobe.target.triggerView() - at.js 2.x
- adobe.target.trackEvent()
- mboxCreate() - at.js 1.x
- targetGlobalSettings()
- mboxDefine() and mboxUpdate() - at.js 1.x
- targetPageParams()
- targetPageParamsAll()
- registerExtension() - at.js 1.x
- sendNotifications() - at.js 2.1
- at.js custom events
- Debug at.js using the Adobe Experience Cloud Debugger
- Use cloud-based instances with Target
- at.js FAQs
- at.js version details
- Upgrading from at.js 1.x to at.js 2.x
- at.js cookies
- User-agent and client hints
- Understand the Global mbox
- Server Side implementation
- Server Side: implement Target overview
- Getting started with Target SDKs
- Sample apps
- Transition from Target legacy APIs to Adobe I/O
- Core principles
- Integration
- On-Device Decisioning
- Node.js SDK Reference
- Java SDK Reference
- .NET SDK Reference
- Python SDK Reference
- Hybrid implementation
- Recommendations implementation
- Mobile app implementation
- Email implementation
- API guides
- Implementation patterns