Package common.intro

Examples of common.intro.Person


    Map<Integer, Person> members = new ConcurrentHashMap<Integer, Person>();
    AtomicInteger currentId = new AtomicInteger();

    public MembershipServiceImpl() {
        // seed HashMap with first member
        Person p = new Person();
        p.setName("Bob");
        p.setAge(20);
        p.setId(currentId.incrementAndGet());
        members.put(p.getId(), p);
    }
View Full Code Here


    }

    @Override
    public Person getMemberSubresource(int id) {
        System.out.println("getMemberSubresource called - id = " + id);
        Person p = members.get(id);
        if (p == null) {
            // will return HTTP 404 "not found" code
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        System.out.println("person ID/Name/Age = " + p.getId() + " / " + p.getName() + " / " + p.getAge());
        return p;
    }
View Full Code Here

    }

    @Override
    public Response deleteMember(int id) {
        System.out.println("----invoking deleteMember for id = " + id);
        Person p = members.get(id);
        if (p == null) {
            // alternative to throwing WebApplicationException()
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        members.remove(id);
View Full Code Here

    public RESTClient(int port) {
        urlStem = "http://localhost:" + port + "/services/membership/members/";
    }
   
    public void run() throws Exception {
        Person p = getMember(1);

        System.out.println("Updating person name using PUT and .../members/1/name URL:");
        WebClient wc = WebClient.create(urlStem);
        wc.path("1");
        wc.path("name").type("text/plain");
        Response resp = wc.put("George".equals(p.getName()) ? "Sam" : "George");
        // for PUTS, resp.getStatus() returns 204 if success, 404 if ID couldn't
        // be found
        p = getMember(1);

        System.out.println("Updating multiple fields of the person using PUT and .../members/1 URL:");
        p.setName("Bob");
        p.setAge(p.getAge() == 40 ? 30 : 40);
        resp = wc.reset().path("1").put(p);
        p = getMember(1);

        System.out.println("Creating a new member using POST and .../members/1 URL:");
        Person newMember = new Person();
        newMember.setName("Harry");
        newMember.setAge(30);
        resp = wc.reset().post(newMember);

        if (resp.getStatus() != Response.Status.CREATED.getStatusCode()) {
            throw new RuntimeException("Could not add new member.");
        }
View Full Code Here

    }

    private Person getMember(int memberNo) throws Exception {
        WebClient wc = WebClient.create(urlStem);
        wc.path(memberNo);
        Person p = wc.get(Person.class);
        System.out.println("person ID/Name/Age = " + p.getId() + " / " + p.getName() + " / " + p.getAge());
        return p;
    }
View Full Code Here

        return p;
    }

    private Person getMember(String locationURL) throws Exception {
        WebClient wc = WebClient.create(locationURL);
        Person p = wc.get(Person.class);
        System.out.println("person ID/Name/Age = " + p.getId() + " / " + p.getName() + " / " + p.getAge());
        return p;
    }
View Full Code Here

TOP

Related Classes of common.intro.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.