001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2014-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.resource.examples; 018 019import static org.forgerock.json.resource.examples.DemoUtils.*; 020 021import org.forgerock.json.resource.Connection; 022import org.forgerock.json.resource.ConnectionFactory; 023import org.forgerock.json.resource.Requests; 024import org.forgerock.json.resource.ResourceException; 025import org.forgerock.json.resource.ResourceResponse; 026 027/** 028 * An example client application which performs an asynchronous read, modify, 029 * write update cycle for a resource in an in memory resource container. This 030 * example does not require any command line arguments. 031 */ 032public final class ReadModifyWriteDemo { 033 034 private ReadModifyWriteDemo() { 035 // No implementation. 036 } 037 038 /** 039 * Main method. 040 * 041 * @param args 042 * The command line arguments: this example does not have any. 043 * @throws ResourceException 044 * If an unexpected error occurred. 045 */ 046 public static void main(final String[] args) throws ResourceException { 047 try (final ConnectionFactory server = getConnectionFactory(); 048 final Connection connection = server.getConnection()) { 049 log("Reading resource"); 050 final ResourceResponse before = connection.read(ctx(), Requests.newReadRequest("users/1")); 051 log("Resource read and has revision " + before.getRevision()); 052 log("Updating resource"); 053 final ResourceResponse after = 054 connection.update(ctx(), Requests.newUpdateRequest("users/1", 055 userAliceWithIdAndRev(1, 1))); 056 log("Updated resource now has revision " + after.getRevision()); 057 } 058 } 059 060}