org.glassfish.jersey.internal.util.collection.Refs Java Examples

The following examples show how to use org.glassfish.jersey.internal.util.collection.Refs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsynchronousResources.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@Produces(SERVER_SENT_EVENTS)
@Path("/sse/stream")
@GET
public void getSseStream(@Context final SseEventSink eventSink,
                         @Context final Sse sse) {
    scheduleSseEventSend(new SseEmitter() {
        @Override
        public CompletionStage<?> emit(final OutboundSseEvent event) {
            return eventSink.send(event);
        }

        @Override
        public void close() {
            eventSink.close();
        }
    }, sse, Refs.of(0), ctx.executionContext().executor());
}
 
Example #2
Source File: AsynchronousResources.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@Produces(SERVER_SENT_EVENTS)
@Path("/sse/broadcast")
@GET
public void getSseBroadcast(@Context final SseEventSink eventSink,
                            @Context final Sse sse) {
    eventSink.send(sse.newEvent("bar"));
    final SseBroadcaster sseBroadcaster = sse.newBroadcaster();
    sseBroadcaster.register(eventSink);

    scheduleSseEventSend(new SseEmitter() {
        @Override
        public CompletionStage<?> emit(final OutboundSseEvent event) {
            return sseBroadcaster.broadcast(event);
        }

        @Override
        public void close() {
            sseBroadcaster.close();
        }
    }, sse, Refs.of(0), ctx.executionContext().executor());
}
 
Example #3
Source File: AbstractRestClient.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
@Override
public RestResult get(String path, Map<String, Object> params) {
    Ref<WebTarget> target = Refs.of(this.target);
    for (String key : params.keySet()) {
        Object value = params.get(key);
        if (value instanceof Collection) {
            for (Object i : (Collection<?>) value) {
                target.set(target.get().queryParam(key, i));
            }
        } else {
            target.set(target.get().queryParam(key, value));
        }
    }
    Response response = this.request(() -> {
        return target.get().path(path).request().get();
    });
    checkStatus(response, Response.Status.OK);
    return new RestResult(response);
}
 
Example #4
Source File: ModelResourceStructure.java    From ameba with MIT License 6 votes vote down vote up
/**
 * <p>fetchHistory.</p>
 *
 * @param id a URI_ID object.
 * @return a {@link javax.ws.rs.core.Response} object.
 * @throws java.lang.Exception if any.
 */
public Response fetchHistory(@PathParam("id") URI_ID id) throws Exception {
    final MODEL_ID mId = tryConvertId(id);
    matchedFetchHistory(mId);
    final Query<MODEL> query = server.find(modelType);

    defaultFindOrderBy(query);

    final Ref<FutureRowCount> rowCount = Refs.emptyRef();
    Object entity = executeTx(t -> {
        configDefaultQuery(query);
        configFetchHistoryQuery(query, mId);
        applyUriQuery(query, false);
        applyPageConfig(query);
        List<Version<MODEL>> list = query.findVersions();
        rowCount.set(fetchRowCount(query));
        return processFetchedHistoryModelList(list, mId);
    });

    if (isEmptyEntity(entity)) {
        return Response.noContent().build();
    }
    Response response = Response.ok(entity).build();
    applyRowCountHeader(response.getHeaders(), query, rowCount.get());
    return response;
}
 
Example #5
Source File: EndpointEnhancingRequestFilterTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotFilterNonStRequests() throws Exception {
    EndpointEnhancingRequestFilter filter = new EndpointEnhancingRequestFilter();
    Provider<Ref<ConnectionContext>> ctxRefProvider = () -> Refs.of(null);
    Provider<RouteStrategiesConfig> routeStrategiesConfigProvider = () -> mock(RouteStrategiesConfig.class);
    RequestScope requestScope = mock(RequestScope.class);
    setField(filter, filter.getClass().getDeclaredField("ctxRefProvider"), ctxRefProvider);
    setField(filter, filter.getClass().getDeclaredField("routeStrategiesConfigProvider"),
            routeStrategiesConfigProvider);
    setField(filter, filter.getClass().getDeclaredField("requestScope"), requestScope);

    ContainerRequestContext context = mock(ContainerRequestContext.class);
    filter.filter(mock(ContainerRequestContext.class));
    verifyZeroInteractions(context);
}
 
Example #6
Source File: AbstractRestClient.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Override
public RestResult delete(String path, Map<String, Object> params) {
    Ref<WebTarget> target = Refs.of(this.target);
    for (String key : params.keySet()) {
        target.set(target.get().queryParam(key, params.get(key)));
    }
    Response response = this.request(() -> {
        return target.get().path(path).request().delete();
    });
    checkStatus(response, Response.Status.NO_CONTENT,
                Response.Status.ACCEPTED);
    return new RestResult(response);
}
 
Example #7
Source File: TemplateHelper.java    From ameba with MIT License 5 votes vote down vote up
/**
 * Get media types for which the {@link org.glassfish.jersey.server.mvc.spi.ResolvedViewable resolved viewable} could be
 * produced.
 *
 * @param containerRequest request to obtain acceptable media types.
 * @param extendedUriInfo  uri info to obtain resource method from and its producible media types.
 * @param varyHeaderValue  Vary header reference.
 * @return list of producible media types.
 */
public static List<MediaType> getProducibleMediaTypes(final ContainerRequest containerRequest,
                                                      final ExtendedUriInfo extendedUriInfo,
                                                      final Ref<String> varyHeaderValue) {
    final List<MediaType> producedTypes = getResourceMethodProducibleTypes(extendedUriInfo);
    final MediaType[] mediaTypes = producedTypes.toArray(new MediaType[producedTypes.size()]);

    final List<Variant> variants = VariantSelector.selectVariants(containerRequest, Variant.mediaTypes(mediaTypes)
            .build(), varyHeaderValue == null ? Refs.emptyRef() : varyHeaderValue);

    return Lists.transform(variants, variant -> MediaTypes.stripQualityParams(variant.getMediaType()));
}
 
Example #8
Source File: ModelResourceStructure.java    From ameba with MIT License 5 votes vote down vote up
/**
 * Find the beans for this beanType.
 * <p>
 * This can use URL query parameters such as order and maxrows to configure
 * the query.
 * </p>
 *
 * @param includeDeleted a boolean.
 * @return a {@link javax.ws.rs.core.Response} object.
 * @throws java.lang.Exception if any.
 * @see javax.ws.rs.GET
 * @see AbstractModelResource#find
 */
public Response find(@QueryParam("include_deleted") final boolean includeDeleted) throws Exception {
    matchedFind(includeDeleted);
    final Query<MODEL> query = server.find(modelType);

    if (includeDeleted) {
        query.setIncludeSoftDeletes();
    }

    defaultFindOrderBy(query);

    final Ref<FutureRowCount> rowCount = Refs.emptyRef();

    Object entity = executeTx(t -> {
        configDefaultQuery(query);
        configFindQuery(query, includeDeleted);
        rowCount.set(applyUriQuery(query));
        List<MODEL> list = query.findList();
        return processFoundModelList(list, includeDeleted);
    });

    if (isEmptyEntity(entity)) {
        return Response.noContent().build();
    }
    Response response = Response.ok(entity).build();
    applyRowCountHeader(response.getHeaders(), query, rowCount.get());
    return response;
}
 
Example #9
Source File: ModelResourceStructure.java    From ameba with MIT License 5 votes vote down vote up
/**
 * find model history between start to end timestamp versions
 * <p>
 * need model mark {@code @History}
 *
 * @param id    model id
 * @param start start timestamp
 * @param end   end timestamp
 * @return history versions
 * @throws java.lang.Exception any error
 */
public Response fetchHistory(@PathParam("id") URI_ID id,
                             @PathParam("start") final Timestamp start,
                             @PathParam("end") final Timestamp end) throws Exception {
    final MODEL_ID mId = tryConvertId(id);
    matchedFetchHistory(mId, start, end);
    final Query<MODEL> query = server.find(modelType);

    defaultFindOrderBy(query);

    final Ref<FutureRowCount> rowCount = Refs.emptyRef();
    Object entity = executeTx(t -> {
        configDefaultQuery(query);
        configFetchHistoryQuery(query, mId, start, end);
        applyUriQuery(query, false);
        applyPageConfig(query);
        List<Version<MODEL>> list = query.findVersionsBetween(start, end);
        rowCount.set(fetchRowCount(query));
        return processFetchedHistoryModelList(list, mId, start, end);
    });

    if (isEmptyEntity(entity)) {
        return Response.noContent().build();
    }
    Response response = Response.ok(entity).build();
    applyRowCountHeader(response.getHeaders(), query, rowCount.get());
    return response;
}