Search in sources :

Example 96 with GET

use of javax.ws.rs.GET in project jersey by jersey.

the class UsersResource method getUsersAsJsonArray.

@GET
@Produces("application/json")
public JSONArray getUsersAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (UserEntity userEntity : getUsers()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI userUri = ub.path(userEntity.getUserid()).build();
        uriArray.put(userUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UserEntity(org.glassfish.jersey.examples.bookmark_em.entity.UserEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 97 with GET

use of javax.ws.rs.GET in project jersey by jersey.

the class BookmarksResource method getBookmarksAsJsonArray.

@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONArray getBookmarksAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (BookmarkEntity bookmarkEntity : getBookmarks()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI bookmarkUri = ub.path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
        uriArray.put(bookmarkUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) BookmarkEntity(org.glassfish.jersey.examples.bookmark.entity.BookmarkEntity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 98 with GET

use of javax.ws.rs.GET in project jersey by jersey.

the class UsersResource method getUsersAsJsonArray.

@GET
@Produces("application/json")
public JSONArray getUsersAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (UserEntity userEntity : getUsers()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI userUri = ub.path(userEntity.getUserid()).build();
        uriArray.put(userUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UserEntity(org.glassfish.jersey.examples.bookmark.entity.UserEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 99 with GET

use of javax.ws.rs.GET in project jersey by jersey.

the class PersonResource method getPerson.

@GET
@Path("{id}")
public Person getPerson() {
    final Person person = new Person();
    person.setGivenName("Andrew");
    person.setFamilyName("Dowd");
    person.setHonorificPrefix("Mr.");
    person.setHonorificSuffix("PhD");
    person.setRegion("1st Level Region");
    final ArrayList<Address> addresses = new ArrayList<>();
    person.setAddresses(addresses);
    final Address address = new Address();
    addresses.add(address);
    address.setRegion("2nd Level Region");
    address.setStreetAddress("1234 fake st.");
    address.setPhoneNumber(new PhoneNumber());
    address.getPhoneNumber().setNumber("867-5309");
    address.getPhoneNumber().setAreaCode("540");
    person.setPhoneNumbers(new HashMap<String, PhoneNumber>());
    final PhoneNumber number = new PhoneNumber();
    number.setAreaCode("804");
    number.setNumber("867-5309");
    person.getPhoneNumbers().put("HOME", number);
    return person;
}
Also used : Address(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Address) ArrayList(java.util.ArrayList) PhoneNumber(org.glassfish.jersey.examples.entityfiltering.selectable.domain.PhoneNumber) Person(org.glassfish.jersey.examples.entityfiltering.selectable.domain.Person) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 100 with GET

use of javax.ws.rs.GET in project jersey by jersey.

the class AsyncAgentResource method async.

@GET
@ManagedAsync
public void async(@Suspended final AsyncResponse async) {
    final long time = System.nanoTime();
    final AgentResponse response = new AgentResponse();
    final CountDownLatch outerLatch = new CountDownLatch(2);
    final Queue<String> errors = new ConcurrentLinkedQueue<>();
    // Obtain visited destinations.
    destination.path("visited").request().header("Rx-User", "Async").async().get(new InvocationCallback<List<Destination>>() {

        @Override
        public void completed(final List<Destination> destinations) {
            response.setVisited(destinations);
            outerLatch.countDown();
        }

        @Override
        public void failed(final Throwable throwable) {
            errors.offer("Visited: " + throwable.getMessage());
            outerLatch.countDown();
        }
    });
    // Obtain recommended destinations. (does not depend on visited ones)
    destination.path("recommended").request().header("Rx-User", "Async").async().get(new InvocationCallback<List<Destination>>() {

        @Override
        public void completed(final List<Destination> recommended) {
            final CountDownLatch innerLatch = new CountDownLatch(recommended.size() * 2);
            // Forecasts. (depend on recommended destinations)
            final Map<String, Forecast> forecasts = Collections.synchronizedMap(new HashMap<>());
            for (final Destination dest : recommended) {
                forecast.resolveTemplate("destination", dest.getDestination()).request().async().get(new InvocationCallback<Forecast>() {

                    @Override
                    public void completed(final Forecast forecast) {
                        forecasts.put(dest.getDestination(), forecast);
                        innerLatch.countDown();
                    }

                    @Override
                    public void failed(final Throwable throwable) {
                        errors.offer("Forecast: " + throwable.getMessage());
                        innerLatch.countDown();
                    }
                });
            }
            // Calculations. (depend on recommended destinations)
            final List<Future<Calculation>> futures = recommended.stream().map(dest -> calculation.resolveTemplate("from", "Moon").resolveTemplate("to", dest.getDestination()).request().async().get(Calculation.class)).collect(Collectors.toList());
            final Map<String, Calculation> calculations = new HashMap<>();
            while (!futures.isEmpty()) {
                final Iterator<Future<Calculation>> iterator = futures.iterator();
                while (iterator.hasNext()) {
                    final Future<Calculation> f = iterator.next();
                    if (f.isDone()) {
                        try {
                            final Calculation calculation = f.get();
                            calculations.put(calculation.getTo(), calculation);
                            innerLatch.countDown();
                        } catch (final Throwable t) {
                            errors.offer("Calculation: " + t.getMessage());
                            innerLatch.countDown();
                        } finally {
                            iterator.remove();
                        }
                    }
                }
            }
            // Have to wait here for dependent requests ...
            try {
                if (!innerLatch.await(10, TimeUnit.SECONDS)) {
                    errors.offer("Inner: Waiting for requests to complete has timed out.");
                }
            } catch (final InterruptedException e) {
                errors.offer("Inner: Waiting for requests to complete has been interrupted.");
            }
            // Recommendations.
            final List<Recommendation> recommendations = new ArrayList<>(recommended.size());
            for (final Destination dest : recommended) {
                final Forecast fore = forecasts.get(dest.getDestination());
                final Calculation calc = calculations.get(dest.getDestination());
                recommendations.add(new Recommendation(dest.getDestination(), fore != null ? fore.getForecast() : "N/A", calc != null ? calc.getPrice() : -1));
            }
            response.setRecommended(recommendations);
            outerLatch.countDown();
        }

        @Override
        public void failed(final Throwable throwable) {
            errors.offer("Recommended: " + throwable.getMessage());
            outerLatch.countDown();
        }
    });
    // ... and have to wait also here for independent requests.
    try {
        if (!outerLatch.await(10, TimeUnit.SECONDS)) {
            errors.offer("Outer: Waiting for requests to complete has timed out.");
        }
    } catch (final InterruptedException e) {
        errors.offer("Outer: Waiting for requests to complete has been interrupted.");
    }
    // Do something with errors.
    // ...
    response.setProcessingTime((System.nanoTime() - time) / 1000000);
    async.resume(response);
}
Also used : Destination(org.glassfish.jersey.examples.rx.domain.Destination) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) Recommendation(org.glassfish.jersey.examples.rx.domain.Recommendation) InvocationCallback(javax.ws.rs.client.InvocationCallback) Forecast(org.glassfish.jersey.examples.rx.domain.Forecast) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) Calculation(org.glassfish.jersey.examples.rx.domain.Calculation) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) HashMap(java.util.HashMap) Map(java.util.Map) GET(javax.ws.rs.GET) ManagedAsync(org.glassfish.jersey.server.ManagedAsync)

Aggregations

GET (javax.ws.rs.GET)947 Path (javax.ws.rs.Path)757 Produces (javax.ws.rs.Produces)606 ApiOperation (io.swagger.annotations.ApiOperation)227 ApiResponses (io.swagger.annotations.ApiResponses)161 IOException (java.io.IOException)109 Response (javax.ws.rs.core.Response)100 WebApplicationException (javax.ws.rs.WebApplicationException)99 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)84 Timed (com.codahale.metrics.annotation.Timed)80 ArrayList (java.util.ArrayList)79 List (java.util.List)72 HashMap (java.util.HashMap)68 Map (java.util.Map)65 URI (java.net.URI)60 TimedResource (org.killbill.commons.metrics.TimedResource)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)57 ApiResponse (io.swagger.annotations.ApiResponse)52 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)39 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31