Java Code Examples for javax.ws.rs.core.PathSegment#getMatrixParameters()

The following examples show how to use javax.ws.rs.core.PathSegment#getMatrixParameters() . 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: SynchronousResources.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Produces(TEXT_PLAIN)
@Path("/matrix/{pathSegment:ps}/params")
@GET
public String objectsByCategory(@PathParam("pathSegment") final PathSegment pathSegment,
                                @MatrixParam("mp") final List<String> matrixParams) {
    final MultivaluedMap<String, String> matrixParameters = pathSegment.getMatrixParameters();
    final String categorySegmentPath = pathSegment.getPath();
    return "GOT: "
            + matrixParameters.keySet().stream().map(k -> k + "="
            + matrixParameters.get(k).stream().collect(joining(","))).collect(joining(","))
            + " & " + categorySegmentPath
            + " & " + matrixParams.stream().collect(joining(","));
}
 
Example 2
Source File: WorkflowVariablesTransformer.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public Map<String, String> getWorkflowVariablesFromPathSegment(PathSegment pathSegment) {
    Map<String, String> variables = null;
    MultivaluedMap<String, String> matrixParams = pathSegment.getMatrixParameters();
    if (matrixParams != null && !matrixParams.isEmpty()) {
        // Remove any empty keys that might be mistakenly sent to the scheduler to prevent bad behaviour
        matrixParams.remove("");
        variables = Maps.newHashMap();
        for (String key : matrixParams.keySet()) {
            String value = matrixParams.getFirst(key) == null ? "" : matrixParams.getFirst(key);
            variables.put(key, value);
        }
    }
    return variables;
}
 
Example 3
Source File: BookStore.java    From cxf with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/segment/{pathsegment}/")
public Book getBookBySegment(@PathParam("pathsegment") PathSegment segment) throws Exception {
    if (!"matrix2".equals(segment.getPath())) {
        throw new RuntimeException();
    }
    MultivaluedMap<String, String> map = segment.getMatrixParameters();
    String s1 = map.getFirst("first").toString();
    String s2 = map.getFirst("second").toString();
    return doGetBook(s1 + s2);
}
 
Example 4
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Object processMatrixParam(Message m, String key,
                                         Class<?> pClass, Type genericType,
                                         Annotation[] paramAnns,
                                         String defaultValue,
                                         boolean decode) {
    List<PathSegment> segments = JAXRSUtils.getPathSegments(
                                  (String)m.get(Message.REQUEST_URI), decode);
    if (!segments.isEmpty()) {
        MultivaluedMap<String, String> params = new MetadataMap<>();
        for (PathSegment ps : segments) {
            MultivaluedMap<String, String> matrix = ps.getMatrixParameters();
            for (Map.Entry<String, List<String>> entry : matrix.entrySet()) {
                for (String value : entry.getValue()) {
                    params.add(entry.getKey(), value);
                }
            }
        }

        if ("".equals(key)) {
            return InjectionUtils.handleBean(pClass, paramAnns, params, ParameterType.MATRIX, m, false);
        }
        List<String> values = params.get(key);
        return InjectionUtils.createParameterObject(values,
                                                    pClass,
                                                    genericType,
                                                    paramAnns,
                                                    defaultValue,
                                                    false,
                                                    ParameterType.MATRIX,
                                                    m);
    }

    return null;
}
 
Example 5
Source File: PathSegmentImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testPathSegmentWithMatrixParams() {
    PathSegment ps = new PathSegmentImpl("bar;a=1;a=2;b=3%202", false);
    assertEquals("bar", ps.getPath());
    MultivaluedMap<String, String> params = ps.getMatrixParameters();
    assertEquals(2, params.size());
    assertEquals(2, params.get("a").size());
    assertEquals("1", params.get("a").get(0));
    assertEquals("2", params.get("a").get(1));
    assertEquals("3%202", params.getFirst("b"));
}
 
Example 6
Source File: PathSegmentImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testPathSegmentWithDecodedMatrixParams() {
    PathSegment ps = new PathSegmentImpl("bar%20foo;a=1%202");
    assertEquals("bar foo", ps.getPath());
    MultivaluedMap<String, String> params = ps.getMatrixParameters();
    assertEquals(1, params.size());
    assertEquals(1, params.get("a").size());
    assertEquals("1 2", params.get("a").get(0));
}
 
Example 7
Source File: PathSegmentImplTest.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void parsesPathSegmentsFromString() {
    PathSegment pathSegment = PathSegmentImpl.fromString(pathSegmentString, decode);
    MultivaluedMap<String, String> matrixParameters = pathSegment.getMatrixParameters();

    assertEquals(expectedPath, pathSegment.getPath());
    assertEquals(expectedMatrixParameters.size() / 2, matrixParameters.size());

    for (int i = 0; i < expectedMatrixParameters.size(); i += 2) {
        String expectedMatrixParameterName = expectedMatrixParameters.get(i);
        String expectedMatrixParameterValue = expectedMatrixParameters.get(i + 1);
        assertEquals(expectedMatrixParameterValue, matrixParameters.getFirst(expectedMatrixParameterName));
    }
}