Search in sources :

Example 16 with MultivaluedMap

use of jakarta.ws.rs.core.MultivaluedMap in project incubator-hugegraph by apache.

the class CustomizedCrosspointsTraverser method crosspointsPaths.

public CrosspointsPaths crosspointsPaths(Iterator<Vertex> vertices, List<PathPattern> pathPatterns, long capacity, long limit) {
    E.checkArgument(vertices.hasNext(), "The source vertices can't be empty");
    E.checkArgument(!pathPatterns.isEmpty(), "The steps pattern can't be empty");
    checkCapacity(capacity);
    checkLimit(limit);
    MultivaluedMap<Id, Node> initialSources = newMultivalueMap();
    List<HugeVertex> verticesList = newList();
    while (vertices.hasNext()) {
        HugeVertex vertex = (HugeVertex) vertices.next();
        verticesList.add(vertex);
        Node node = new Node(vertex.id(), null);
        initialSources.add(vertex.id(), node);
    }
    List<Path> paths = newList();
    for (PathPattern pathPattern : pathPatterns) {
        MultivaluedMap<Id, Node> sources = initialSources;
        int stepNum = pathPattern.size();
        long access = 0;
        MultivaluedMap<Id, Node> newVertices = null;
        for (Step step : pathPattern.steps()) {
            stepNum--;
            newVertices = newMultivalueMap();
            Iterator<Edge> edges;
            // Traversal vertices of previous level
            for (Map.Entry<Id, List<Node>> entry : sources.entrySet()) {
                List<Node> adjacency = newList();
                edges = this.edgesOfVertex(entry.getKey(), step.edgeStep);
                while (edges.hasNext()) {
                    HugeEdge edge = (HugeEdge) edges.next();
                    Id target = edge.id().otherVertexId();
                    for (Node n : entry.getValue()) {
                        // If have loop, skip target
                        if (n.contains(target)) {
                            continue;
                        }
                        Node newNode = new Node(target, n);
                        adjacency.add(newNode);
                        checkCapacity(capacity, ++access, "customized crosspoints");
                    }
                }
                // Add current node's adjacent nodes
                for (Node node : adjacency) {
                    newVertices.add(node.id(), node);
                }
            }
            // Re-init sources
            sources = newVertices;
        }
        assert stepNum == 0;
        for (List<Node> nodes : newVertices.values()) {
            for (Node n : nodes) {
                paths.add(new Path(n.path()));
            }
        }
    }
    return intersectionPaths(verticesList, paths, limit);
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeStep(com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Example 17 with MultivaluedMap

use of jakarta.ws.rs.core.MultivaluedMap in project helidon by oracle.

the class ClientTracingFilter method filter.

@Override
public void filter(ClientRequestContext requestContext) {
    // if we run within Jersey server, the tracing context will be filled in by TracingHelperFilter
    // if not, it will be empty
    Optional<TracingContext> tracingContext = Contexts.context().flatMap(ctx -> ctx.get(TracingContext.class));
    // maybe we are disabled
    if (tracingDisabled(requestContext, tracingContext)) {
        return;
    }
    // also we may configure tracing through other means
    SpanTracingConfig spanConfig = TracingConfigUtil.spanConfig(JAX_RS_TRACING_COMPONENT, SPAN_OPERATION_NAME);
    if (!spanConfig.enabled()) {
        return;
    }
    Tracer tracer = findTracer(requestContext, tracingContext);
    Optional<SpanContext> parentSpan = findParentSpan(tracer, requestContext, tracingContext);
    Map<String, List<String>> inboundHeaders = findInboundHeaders(tracingContext);
    String spanName = findSpanName(requestContext, spanConfig);
    // create a new span for this jersey client request
    Span currentSpan = createSpan(requestContext, tracer, parentSpan, spanName);
    // register it so we can close the span on response
    requestContext.setProperty(SPAN_PROPERTY_NAME, currentSpan);
    // and also register it with Context, so we can close the span in case of an exception that does not hit the
    // response filter
    Contexts.context().ifPresent(ctx -> ctx.register(SPAN_PROPERTY_NAME, currentSpan));
    Contexts.context().ifPresent(ctx -> ctx.register(TracingConfigUtil.OUTBOUND_SPAN_QUALIFIER, currentSpan.context()));
    // propagate tracing headers, so remote service can use currentSpan as its parent
    Map<String, List<String>> tracingHeaders = tracingHeaders(tracer, currentSpan);
    Map<String, List<String>> outboundHeaders = tracerProvider.map(provider -> provider.updateOutboundHeaders(currentSpan, tracer, parentSpan.orElse(null), tracingHeaders, inboundHeaders)).orElse(tracingHeaders);
    // add headers from inbound request that were not added by tracing provider and are needed
    // by supported proxies or routing services
    outboundHeaders = updateOutboundHeaders(outboundHeaders, inboundHeaders);
    // update the headers to be correctly propagated to remote service
    MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    outboundHeaders.forEach((key, value) -> headers.put(key, new ArrayList<>(value)));
}
Also used : TracingContext(io.helidon.tracing.jersey.client.internal.TracingContext) HashMap(java.util.HashMap) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Tags(io.opentracing.tag.Tags) ArrayList(java.util.ArrayList) ClientResponseFilter(jakarta.ws.rs.client.ClientResponseFilter) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map) URI(java.net.URI) Priority(jakarta.annotation.Priority) Iterator(java.util.Iterator) Tracer(io.opentracing.Tracer) TracingConfigUtil(io.helidon.tracing.config.TracingConfigUtil) ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ServiceLoader(java.util.ServiceLoader) GlobalTracer(io.opentracing.util.GlobalTracer) HelidonServiceLoader(io.helidon.common.serviceloader.HelidonServiceLoader) Collectors(java.util.stream.Collectors) Contexts(io.helidon.common.context.Contexts) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) SpanContext(io.opentracing.SpanContext) Priorities(jakarta.ws.rs.Priorities) List(java.util.List) Format(io.opentracing.propagation.Format) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) Optional(java.util.Optional) TracerProvider(io.helidon.tracing.spi.TracerProvider) Span(io.opentracing.Span) SpanTracingConfig(io.helidon.tracing.config.SpanTracingConfig) TracingContext(io.helidon.tracing.jersey.client.internal.TracingContext) SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) GlobalTracer(io.opentracing.util.GlobalTracer) ArrayList(java.util.ArrayList) Span(io.opentracing.Span) SpanTracingConfig(io.helidon.tracing.config.SpanTracingConfig) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with MultivaluedMap

use of jakarta.ws.rs.core.MultivaluedMap in project minijax by minijax.

the class HttpHeadersTest method testMultiple.

@Test
void testMultiple() throws Exception {
    final Map<String, List<String>> headerMap = new HashMap<>();
    headerMap.computeIfAbsent("X-Foo", k -> new ArrayList<>()).add("bar");
    headerMap.computeIfAbsent("X-Foo", k -> new ArrayList<>()).add("baz");
    final WebSocketHttpExchange exchange = mock(WebSocketHttpExchange.class);
    when(exchange.getRequestHeaders()).thenReturn(headerMap);
    final MinijaxUndertowWebSocketHttpHeaders httpHeaders = new MinijaxUndertowWebSocketHttpHeaders(exchange);
    assertEquals(Arrays.asList("bar", "baz"), httpHeaders.getRequestHeader("X-Foo"));
    final MultivaluedMap<String, String> multiMap = httpHeaders.getRequestHeaders();
    assertNotNull(multiMap);
    assertEquals(multiMap, httpHeaders.getRequestHeaders());
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) java.util(java.util) Cookie(jakarta.ws.rs.core.Cookie) MediaType(jakarta.ws.rs.core.MediaType) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) HttpHeaders(jakarta.ws.rs.core.HttpHeaders) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) Assertions(org.junit.jupiter.api.Assertions) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) Test(org.junit.jupiter.api.Test)

Example 19 with MultivaluedMap

use of jakarta.ws.rs.core.MultivaluedMap in project tomee by apache.

the class XSLTJaxbProvider method createTemplates.

protected Templates createTemplates(Templates templates, Map<String, Object> configuredParams, Map<String, String> outProps) {
    if (templates == null) {
        if (supportJaxbOnly) {
            return null;
        }
        LOG.severe("No template is available");
        throw ExceptionUtils.toInternalServerErrorException(null, null);
    }
    TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
    MessageContext mc = getContext();
    if (mc != null) {
        UriInfo ui = mc.getUriInfo();
        MultivaluedMap<String, String> params = ui.getPathParameters();
        for (Map.Entry<String, List<String>> entry : params.entrySet()) {
            String value = entry.getValue().get(0);
            int ind = value.indexOf(';');
            if (ind > 0) {
                value = value.substring(0, ind);
            }
            templ.setTransformerParameter(entry.getKey(), value);
        }
        List<PathSegment> segments = ui.getPathSegments();
        if (!segments.isEmpty()) {
            setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
        }
        setTransformParameters(templ, ui.getQueryParameters());
        templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
        templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
        templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
        if (configuredParams != null) {
            for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
                templ.setTransformerParameter(entry.getKey(), entry.getValue());
            }
        }
    }
    if (outProps != null) {
        templ.setOutProperties(outProps);
    }
    return templ;
}
Also used : PathSegment(jakarta.ws.rs.core.PathSegment) List(java.util.List) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UriInfo(jakarta.ws.rs.core.UriInfo)

Example 20 with MultivaluedMap

use of jakarta.ws.rs.core.MultivaluedMap in project tomee by apache.

the class InjectionUtils method injectIntoMap.

private static Object injectIntoMap(Type genericType, Annotation[] paramAnns, MultivaluedMap<String, String> processedValues, boolean decoded, ParameterType pathParam, Message message) {
    ParameterizedType paramType = (ParameterizedType) genericType;
    Class<?> keyType = (Class<?>) paramType.getActualTypeArguments()[0];
    Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
    if (secondType instanceof ParameterizedType) {
        MultivaluedMap<Object, Object> theValues = new MetadataMap<>();
        ParameterizedType valueParamType = (ParameterizedType) secondType;
        Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType.getActualTypeArguments(), 0);
        for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
            List<String> valuesList = processedValuesEntry.getValue();
            for (String value : valuesList) {
                Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
                theValues.add(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
            }
        }
        return theValues;
    }
    Map<Object, Object> theValues = new HashMap<>();
    Class<?> valueType = (Class<?>) InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
    for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
        List<String> valuesList = processedValuesEntry.getValue();
        for (String value : valuesList) {
            Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
            theValues.put(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
        }
    }
    return theValues;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParameterizedType(java.lang.reflect.ParameterizedType) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) MediaType(jakarta.ws.rs.core.MediaType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) List(java.util.List) ArrayList(java.util.ArrayList) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MultivaluedMap (jakarta.ws.rs.core.MultivaluedMap)51 Map (java.util.Map)32 List (java.util.List)26 MediaType (jakarta.ws.rs.core.MediaType)20 Response (jakarta.ws.rs.core.Response)13 IOException (java.io.IOException)12 Type (java.lang.reflect.Type)11 ArrayList (java.util.ArrayList)11 WebTarget (jakarta.ws.rs.client.WebTarget)10 OutputStream (java.io.OutputStream)10 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 WebApplicationException (jakarta.ws.rs.WebApplicationException)9 LinkedHashMap (java.util.LinkedHashMap)9 MessageBodyWriter (jakarta.ws.rs.ext.MessageBodyWriter)8 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)8 Client (jakarta.ws.rs.client.Client)7 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)7 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)6 InputStream (java.io.InputStream)6